Using Git with Docker

Hi Brian,

Are you using 8.1 or 8.3?

For 8.1, there are some significant steps I had to take to be able to version ignition reliably. I would recommend using a docker compose with volume mounts to point your data/projects to a directory in the git repo like your-repo/ignition. That will get you 80% there. It will version all of your views, scripts and other plain text files related to your projects. The last 20% is the hard part. I personally use the tag cicd module to store the UDTs in data/projects/.tags. For the gateway specific configurations, I have a directory inside data/projects/.config where I store my application configuration and the gateway backup artifact. To generate a gateway artifact that doesn't have the projects or UDTs (since we are already versioning those items), you have to build a custom dockerfile that has sqlite and zip installed. Note that I remove everything from TAGCONFIG because I build my tags from an application configuration. This script has to be triggered from inside the container and obviously gateway scoped. As noted in the script I query the audit table to get what changed and generate a commit message and a script that just pushes the artifact with the generated commit message. You would need to adapt this to your needs.

Example below:

script example
environmentType = "dev"
gatewayName = "some-gateway"
commitMessage = "I usually build a commit message from ignitions audit table. to get some idea of the changes."
system.util.execute(["/usr/local/bin/ignition/data/projects/.config/scripts/make-backup.sh", environmentType, gatewayName, commitMessage])
ignition/.config/scripts/make-backup.sh
#!/bin/bash

# Allows us to see output even when called from ignition
exec > /usr/local/bin/ignition/data/projects/.config/scripts/backup.log 2>&1
set -euox 
ENVIRONMENT_TYPE="$1"
GATEWAY_NAME="$2"
COMMIT_MSG="$3"

BACKUP_DIR="/usr/local/bin/ignition/data/projects/.config/${ENVIRONMENT_TYPE}/${GATEWAY_NAME}"

echo $(date)

/usr/local/bin/ignition/gwcmd.sh -b /usr/local/bin/ignition/data/projects/.config/scripts/backup.gwbk -y

cd /usr/local/bin/ignition/data/projects/.config/scripts

mv backup.gwbk backup.zip

zip --delete backup.zip projects/* modules/com.inductiveautomation.perspective/*

unzip backup.zip db_backup_sqlite.idb

sqlite3 db_backup_sqlite.idb < remove-tags.sql

zip backup.zip db_backup_sqlite.idb

rm db_backup_sqlite.idb

# Create the destination directory if it doesn't exist
mkdir -p "$BACKUP_DIR"

# Move and rename the final backup
mv backup.zip "${BACKUP_DIR}/backup.gwbk"

printf '%s\n' "$COMMIT_MSG" > "${BACKUP_DIR}/commit.txt"
ignition/.config/scripts/remove-tags.sql
delete from TAGCONFIG;
dockerfile
FROM inductiveautomation/ignition:8.1.42

USER root

RUN apt-get update && apt-get install sqlite3 -y && apt-get install unzip -y && apt-get install zip -y

COPY modules/*.modl /usr/local/bin/ignition/user-lib/modules/

COPY jars/*.jar /usr/local/bin/ignition/lib/core/common/

More than happy to go into detail about this if you are curious.

For 8.3, this guide will help. I put the plain text config in data/projects/.config/ignition but you could make a separate volume mount for this. Be sure to follow the guide's .gitignore. I dont have to generate backup artifacts in a hacky way or use external modules. It actually works pretty nice now.

Hope this helps!