commit 2c9eacc21a49bbddd83d674e1932af93594a44fa Author: Aravindan Sathyanarayanan Date: Sun Nov 26 22:54:52 2023 +0000 first commit diff --git a/DckrFile/Dockerfile.txt b/DckrFile/Dockerfile.txt new file mode 100644 index 0000000..a5fce7d --- /dev/null +++ b/DckrFile/Dockerfile.txt @@ -0,0 +1,6 @@ +FROM inductiveautomation/ignition:latest + +RUN apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + git && \ + rm -rf /var/lib/apt/lists/* \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..bb49353 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM inductiveautomation/ignition:latest +USER 0 +RUN apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + git && \ + rm -rf /var/lib/apt/lists/* +CMD ["test 0"] \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/commit_and_push.py b/commit_and_push.py new file mode 100644 index 0000000..8d4d088 --- /dev/null +++ b/commit_and_push.py @@ -0,0 +1,24 @@ +def handleMessage(payload): + import time + + script_path = '/usr/local/bin/ignition/data/factorystack/scripts/ignition-save.sh' + + project = payload['project'] + + logger = system.util.getLogger("FactoryStack") + logger.info("'Commit and Push' request received from project '{}'.".format(project)) + + try: + actor = payload['actor'] + resources = payload['resources'] + + added = ['/'.join([project, resource['path']]) for resource in resources['added']] + modified = ['/'.join([project, resource['path']]) for resource in resources['modified']] + removed = ['/'.join([project, resource['path']]) for resource in resources['removed']] + + time.sleep(5) # following best practices guide from Inductive Automation + system.util.execute([script_path] + [actor] + added + modified + removed) + + logger.info("'Commit and Push' operation completed.") + except: + logger.error("Error occurred during 'Commit and Push' operation. Please contact 4IR Support.") \ No newline at end of file diff --git a/docker-Compose.yml b/docker-Compose.yml new file mode 100644 index 0000000..a87d759 --- /dev/null +++ b/docker-Compose.yml @@ -0,0 +1,37 @@ +services: + # Ignition Gateway + gateway1: + image: ignitiongit + ports: + - 9088:8088 + volumes: + - gw1-data:/usr/local/bin/ignition/data + command: > + -n dev-env + -m 1024 + -- + wrapper.java.initmemory=512 + -Dignition.allowunsignedmodules=true + gateway2: + image: ignitiongit + ports: + - 9089:8088 + volumes: + - gw2-data:/usr/local/bin/ignition/data + command: > + -n prod-env + -m 1024 + -- + wrapper.java.initmemory=512 + -Dignition.allowunsignedmodules=true + +volumes: + gw1-data: + gw2-data: + +version: "3" + +networks: + gitea: + external: false + \ No newline at end of file diff --git a/ignition-save.sh b/ignition-save.sh new file mode 100644 index 0000000..6db2855 --- /dev/null +++ b/ignition-save.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +set -euo pipefail + +cd /usr/local/bin/ignition/data/projects || exit + +NOW=$(date +"%m-%d-%Y %H:%M:%S") +actor="${1}" +git add "${@:2}" +git commit -m "Designer save by $actor @ $NOW" +git push origin \ No newline at end of file diff --git a/ignition-startup.sh b/ignition-startup.sh new file mode 100644 index 0000000..d13b57c --- /dev/null +++ b/ignition-startup.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +set -euo pipefail + +# For the workshop, expect the password to match the username +GIT_PASSWORD=${GIT_USER} + +# Consume parameters from Environment Variables +if [[ -z "${BRANCH}" ]]; then + REMOTE_BRANCH="origin/main" +else + REMOTE_BRANCH="origin/${BRANCH}" +fi + +# Set global git parameters +git config --global user.name "$GIT_USER" +git config --global user.email "$GIT_EMAIL" +git config --global init.defaultBranch 'main' + +cd /usr/local/bin/ignition/data/projects || exit + +if [ ! -d '.git' ]; then + git init + git remote add origin "https://$GIT_USER:$GIT_PASSWORD@$GIT_HOSTNAME:$GIT_PORT/$GIT_ORG/$GIT_REPO.git" + git fetch + #git reset origin/main # Required when the versioned files existed in path before "git init" of this repo. + git checkout -t "${REMOTE_BRANCH}" +fi diff --git a/startup.py b/startup.py new file mode 100644 index 0000000..1130676 --- /dev/null +++ b/startup.py @@ -0,0 +1 @@ +system.util.execute(["/usr/local/bin/ignition/data/factorystack/scripts/ignition-startup.sh"]) \ No newline at end of file diff --git a/update.py b/update.py new file mode 100644 index 0000000..6d65578 --- /dev/null +++ b/update.py @@ -0,0 +1,8 @@ +# Copy the code below into projects that should be version controlled +system.util.sendMessage('FactoryStack', 'Commit and Push', + payload = { + 'project': system.project.getProjectName(), + 'actor': actor, + 'resources': resources + } +) \ No newline at end of file diff --git a/uploadToGIT.sh b/uploadToGIT.sh new file mode 100644 index 0000000..65a5317 --- /dev/null +++ b/uploadToGIT.sh @@ -0,0 +1,6 @@ +git init +git checkout -b main +git add README.md +git commit -m "first commit" +git remote add origin https://gittea.dev/Aravindan/Scripts.git +git push -u origin main