From d4aa8ff4107c80b9b3b7458c0d8ab829e4088e7a Mon Sep 17 00:00:00 2001
From: MrMeeb <charles.macdonald@me.com>
Date: Sat, 27 May 2023 13:40:44 +0000
Subject: [PATCH 1/7] update drone behaviour [CI SKIP]

---
 .drone.yml | 83 +++++++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 70 insertions(+), 13 deletions(-)

diff --git a/.drone.yml b/.drone.yml
index 6baedd0..665721d 100644
--- a/.drone.yml
+++ b/.drone.yml
@@ -1,22 +1,86 @@
-
 kind: pipeline
 type: docker
-name: build-multiarch-images
+name: build-release-images
+trigger:
+  event:
+    exclude:
+    - pull_request
+  ref:
+    - refs/tags/**
 
 platform:
   os: linux
   arch: amd64
 
 steps:
-- name: make-tags
+  # Set tags for main branch - release tag and 'latest'
+- name: make-tags-main
   image: node
   commands:
-    - echo -n "${DRONE_COMMIT_SHA:0:10}, latest" > .tags
+    - echo -n "${DRONE_TAG}, latest" > .tags
 
-- name: build  
+  # Build containers from main branch when released
+- name: build-main
   image: thegeeklab/drone-docker-buildx
   privileged: true
   settings:
+    provenance: false
+    registry: git.mrmeeb.stream
+    username: 
+      from_secret: docker_username
+    password: 
+      from_secret: docker_password
+    repo: git.mrmeeb.stream/mrmeeb/cronicle
+    platforms:
+      - linux/arm64
+      - linux/amd64
+
+- name: release
+  image: goreleaser/goreleaser
+  environment:
+    GITEA_TOKEN:
+      from_secret: gitea_token
+  commands:
+    - goreleaser release
+
+- name: notify
+  image: plugins/slack
+  when:
+    status:
+    - success
+    - failure
+  settings:
+    webhook: 
+      from_secret: slack_webhook
+
+---
+kind: pipeline
+type: docker
+name: build-develop-images
+trigger:
+  event:
+    exclude:
+    - pull_request
+  branch:
+    - develop
+
+platform:
+  os: linux
+  arch: amd64
+
+steps:
+  # Set tags for develop branch - git commit SHA and 'develop'
+- name: make-tags-develop
+  image: node
+  commands:
+    - echo -n "${DRONE_COMMIT_SHA:0:8}, develop" > .tags
+   
+  # Build containers from develop branch
+- name: build-develop
+  image: thegeeklab/drone-docker-buildx
+  privileged: true
+  settings:
+    provenance: false
     registry: git.mrmeeb.stream
     username: 
       from_secret: docker_username
@@ -35,11 +99,4 @@ steps:
     - failure
   settings:
     webhook: 
-      from_secret: slack_webhook
-
-trigger:
-  branch:
-    - main
-  event:
-    exclude:
-    - pull_request
\ No newline at end of file
+      from_secret: slack_webhook
\ No newline at end of file

From 580845afe08071acaac9592f2538e9491cec009b Mon Sep 17 00:00:00 2001
From: MrMeeb <charles.macdonald@me.com>
Date: Sat, 27 May 2023 13:40:53 +0000
Subject: [PATCH 2/7] add goreleaser [CI SKIP]

---
 .goreleaser.yaml | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
 create mode 100644 .goreleaser.yaml

diff --git a/.goreleaser.yaml b/.goreleaser.yaml
new file mode 100644
index 0000000..4adcd4c
--- /dev/null
+++ b/.goreleaser.yaml
@@ -0,0 +1,25 @@
+build:
+  skip: true
+
+archives:
+- format: binary
+
+release:
+  draft: true
+  gitea:
+    owner: MrMeeb
+    name: cronicle-docker
+
+changelog:
+  sort: asc
+  filters:
+    exclude:
+      - '^docs:'
+      - '^test:'
+
+# .goreleaser.yaml
+gitea_urls:
+  api: https://git.mrmeeb.stream/api/v1
+  download: https://git.mrmeeb.stream
+  # set to true if you use a self-signed certificate
+  skip_tls_verify: false
\ No newline at end of file

From 30026b4e177e8e1c87bba629c14c5f99930d83fa Mon Sep 17 00:00:00 2001
From: MrMeeb <charles.macdonald@me.com>
Date: Sat, 27 May 2023 13:42:38 +0000
Subject: [PATCH 3/7] update readme [CI SKIP]

---
 README.md | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/README.md b/README.md
index c31579d..6f56c32 100644
--- a/README.md
+++ b/README.md
@@ -1,19 +1,16 @@
 # Cronicle Docker
 
-[![Build Status](https://drone.mrmeeb.stream/api/badges/MrMeeb/cronicle-docker/status.svg)](https://drone.mrmeeb.stream/MrMeeb/cronicle-docker) - _Every new commit triggers a build. I'm lazy._
-
-
 Dockerised Cronicle, based on the [Cronicle-Edge](https://github.com/cronicle-edge/cronicle-edge) fork.
 
 Can function in both the **manager** and **worker** role.
 
 ## Running 
 
-`config.json`, located in `/config/config.json`, is automatically generated on the first run of Cronicle in 'manager' mode. This file must be kept identical between the manager and any workers it controls.
+`config.json`, located in `/config/cronicle/conf/config.json`, is automatically generated on the first run of Cronicle in 'manager' mode. This file must be kept identical between the manager and any workers it controls.
 
-If you want to configure Cronicle before first run, download `config_sample.json` and adjust accordingly before placing in `/config/config.json`.
+If you want to configure Cronicle before first run (e.g to use a different storage engine), download `config_sample.json` and adjust accordingly before placing in `/config/cronicle/conf/config.json`.
 
-NOTE: You must define the hostname of the container. Cronicle expects the hostname to remain the same, so the randomly-generated container hostname can cause problems if it changes.
+:exclamation: NOTE: You must define the hostname of the container. Cronicle expects the hostname to remain the same, so the randomly-generated container hostname can cause problems if it changes. :exclamation:
 
 ### Docker CLI
 ```
@@ -21,6 +18,9 @@ docker run -d --name cronicle \
     --hostname cronicle-manager \
     -p 3012:3012 \
     -e MODE=manager \
+    -e PUID=1000 \
+    -e PGID=1000 \
+    -e TZ=Europe/London \
     -v {path on host}:/config
     git.mrmeeb.stream/mrmeeb/cronicle:latest 
 ```
@@ -41,11 +41,14 @@ services:
       - {path on host}:/config
     environment:
       - MODE=manager
+      - PUID=1000
+      - PGID=1000
+      - TZ=Europe/London
 ```
 
 ## Custom Scripts
 
-This container automatically checks for scripts in `/config/init` and runs them at startup of the container. This could be useful if you need to install additional applications into a worker container so it can execute any jobs.
+This container automatically checks for scripts in `/config/init` and runs them at startup. This could be useful if you need to install additional applications into a worker container so it can execute jobs.
 
 ## Ports
 
@@ -62,4 +65,7 @@ This container automatically checks for scripts in `/config/init` and runs them
 ## Environment Variables
 |Variable|Options|Default|Description|
 |--------|-------|-------|-------|
-|MODE    |manager, worker|manager|Determines what mode Cronicle runs in
\ No newline at end of file
+|MODE    |manager, worker|manager|Determines what mode Cronicle runs in
+|PUID    |int    |1000   |Sets the UID of the user Cronicle runs under
+|PGID    |int    |1000   |Sets the GID of the user Cronicle runs under
+|TZ      |[List of valid TZs](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List)    |UTC    |Sets the timezone of the container and by extension Cronicle
\ No newline at end of file

From 613393f328c0fc2714e8445ad25e602711fb4c03 Mon Sep 17 00:00:00 2001
From: MrMeeb <charles.macdonald@me.com>
Date: Sat, 27 May 2023 13:43:46 +0000
Subject: [PATCH 4/7] redesign around s6-overlay

---
 Dockerfile                                    |  48 +++++---
 root/container-init.sh                        |  53 +++++++++
 root/cronicle-prepare.sh                      | 107 ++++++++++++++++++
 .../container-init/dependencies.d/base        |   0
 .../s6-overlay/s6-rc.d/container-init/type    |   1 +
 root/etc/s6-overlay/s6-rc.d/container-init/up |   1 +
 .../cronicle-prepare/dependencies.d/base      |   0
 .../dependencies.d/container-init             |   0
 .../s6-overlay/s6-rc.d/cronicle-prepare/type  |   1 +
 .../s6-overlay/s6-rc.d/cronicle-prepare/up    |   1 +
 .../s6-rc.d/cronicle/dependencies.d/base      |   0
 .../cronicle/dependencies.d/cronicle-prepare  |   0
 root/etc/s6-overlay/s6-rc.d/cronicle/finish   |   1 +
 root/etc/s6-overlay/s6-rc.d/cronicle/run      |   3 +
 root/etc/s6-overlay/s6-rc.d/cronicle/type     |   1 +
 .../s6-rc.d/user/contents.d/cronicle          |   0
 .../s6-rc.d/user/contents.d/cronicle-prepare  |   0
 run.sh                                        |  86 --------------
 18 files changed, 199 insertions(+), 104 deletions(-)
 create mode 100644 root/container-init.sh
 create mode 100644 root/cronicle-prepare.sh
 create mode 100644 root/etc/s6-overlay/s6-rc.d/container-init/dependencies.d/base
 create mode 100644 root/etc/s6-overlay/s6-rc.d/container-init/type
 create mode 100644 root/etc/s6-overlay/s6-rc.d/container-init/up
 create mode 100644 root/etc/s6-overlay/s6-rc.d/cronicle-prepare/dependencies.d/base
 create mode 100644 root/etc/s6-overlay/s6-rc.d/cronicle-prepare/dependencies.d/container-init
 create mode 100644 root/etc/s6-overlay/s6-rc.d/cronicle-prepare/type
 create mode 100644 root/etc/s6-overlay/s6-rc.d/cronicle-prepare/up
 create mode 100644 root/etc/s6-overlay/s6-rc.d/cronicle/dependencies.d/base
 create mode 100644 root/etc/s6-overlay/s6-rc.d/cronicle/dependencies.d/cronicle-prepare
 create mode 100644 root/etc/s6-overlay/s6-rc.d/cronicle/finish
 create mode 100644 root/etc/s6-overlay/s6-rc.d/cronicle/run
 create mode 100644 root/etc/s6-overlay/s6-rc.d/cronicle/type
 create mode 100644 root/etc/s6-overlay/s6-rc.d/user/contents.d/cronicle
 create mode 100644 root/etc/s6-overlay/s6-rc.d/user/contents.d/cronicle-prepare
 delete mode 100644 run.sh

diff --git a/Dockerfile b/Dockerfile
index 7bbeac2..a0be22a 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,35 +1,47 @@
 FROM alpine:latest
 
+ARG S6_OVERLAY_VERSION=3.1.5.0
+
 ENV CRONICLE_foreground=1
 ENV CRONICLE_echo=1
 ENV CRONICLE_color=1
 ENV EDITOR=vi
 ENV MODE=manager
+ENV PUID=1000
+ENV PGID=1000
+ENV TZ=UTC
 
-#RUN apt update && apt install -y tini curl git procps
+#Get required packages
+RUN apk update && apk add tzdata curl shadow bash xz git procps nodejs npm
 
-RUN apk update && apk add bash tini git procps nodejs npm
+#Make folders
+RUN mkdir /config && \
+    mkdir /app && \
+#Create default user
+    useradd -u 1000 -U -d /config -s /bin/false mrmeeb && \
+    usermod -G users mrmeeb
 
-RUN git clone https://github.com/cronicle-edge/cronicle-edge.git /opt/cronicle
+#Install s6-overlay
+RUN curl -fsSL "https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-noarch.tar.xz" | tar Jpxf - -C / && \
+    curl -fsSL "https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-x86_64.tar.xz" | tar Jpxf - -C / && \
+    curl -fsSL "https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-symlinks-noarch.tar.xz" | tar Jpxf - -C / && \
+    curl -fsSL "https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-symlinks-arch.tar.xz" | tar Jpxf - -C /
+ENV S6_BEHAVIOUR_IF_STAGE2_FAILS=2 S6_CMD_WAIT_FOR_SERVICES_MAXTIME=0 S6_VERBOSITY=1
 
-WORKDIR /opt/cronicle
-
-RUN npm install
-
-RUN node bin/build dist
-
-COPY run.sh /
-
-RUN chmod +x /run.sh
-
-RUN mkdir /config
+#Install Cronicle
+RUN git clone https://github.com/cronicle-edge/cronicle-edge.git /app/cronicle
+WORKDIR /app/cronicle
+RUN npm install && \
+    node bin/build dist
+RUN rm -rf /app/cronicle/Docker* .vscode
 
+#Create Cronicle user, necessary for SSH plugin with default settings
 RUN adduser --disabled-password --no-create-home cronicle
 
-#RUN ln -sf /dev/stdout /opt/cronicle/logs/Cronicle.log
+COPY root/ /
+RUN chmod +x /cronicle-prepare.sh && \
+    chmod +x /container-init.sh
 
 EXPOSE 3012
 
-ENTRYPOINT ["/sbin/tini", "--"]
-
-CMD [ "/run.sh" ]
\ No newline at end of file
+ENTRYPOINT [ "/init" ]
\ No newline at end of file
diff --git a/root/container-init.sh b/root/container-init.sh
new file mode 100644
index 0000000..c6e6821
--- /dev/null
+++ b/root/container-init.sh
@@ -0,0 +1,53 @@
+#!/command/with-contenv bash
+# shellcheck shell=bash
+
+echo ""
+echo ""
+echo "================================================"
+echo "|      __  _______  __  ___________________    |" 
+echo "|     /  |/  / __ \/  |/  / ____/ ____/ __ )   |"
+echo "|    / /|_/ / /_/ / /|_/ / __/ / __/ / __  |   |"
+echo "|   / /  / / _, _/ /  / / /___/ /___/ /_/ /    |"
+echo "|  /_/  /_/_/ |_/_/  /_/_____/_____/_____/     |"
+echo "|                                              |"
+echo "================================================"
+echo ""
+echo "Initialising container"
+echo "
+----------------------------------------------------------------------
+ENVIRONMENT
+----------------------------------------------------------------------
+PUID=${PUID}
+PGID=${PGID}
+TZ=${TZ}
+MODE=${MODE}
+----------------------------------------------------------------------
+"
+
+#Setting UID and GID as configured
+if [[ ! "${PUID}" -eq 0 ]] && [[ ! "${PGID}" -eq 0 ]]; then
+    echo "Executing usermod..."
+    mkdir "/tmp/temphome"
+    usermod -d "/tmp/temphome" mrmeeb
+    usermod -o -u "${PUID}" mrmeeb
+    usermod -d /config mrmeeb
+    rm -rf "/tmp/temphome"
+    groupmod -o -g "${PGID}" mrmeeb
+else
+    echo "Running as root is not supported, please fix your PUID and PGID!"
+    exit 1
+fi
+
+echo "Checking permissions in /config and /app (this can take some time)."
+
+if [ ! "$(stat -c %u /app)" -eq "${PUID}" ] || [ ! "$(stat -c %g /app)" -eq "${PGID}" ]
+then
+    echo "Fixing permissions for /app."
+    chown -R mrmeeb:mrmeeb /app
+fi
+
+if [ ! "$(stat -c %u /config)" -eq "${PUID}" ] || [ ! "$(stat -c %g /config)" -eq "${PGID}" ]
+then
+    echo "Fixing permissions for /config."
+    chown -R mrmeeb:mrmeeb /config
+fi
\ No newline at end of file
diff --git a/root/cronicle-prepare.sh b/root/cronicle-prepare.sh
new file mode 100644
index 0000000..a0bd1a2
--- /dev/null
+++ b/root/cronicle-prepare.sh
@@ -0,0 +1,107 @@
+#!/command/with-contenv bash
+# shellcheck shell=bash
+
+echo "Preparing Cronicle"
+
+#Importing and running additional scripts placed in /config/init
+if [ -d /config/init ]
+then
+	if [ "$(ls -A /config/init)" ]
+    then
+
+        echo "Running additional startup scripts."
+
+        bash /config/init/*
+	
+    else
+        
+        echo "/config/init is empty - no additional startup scripts detected."
+	
+    fi
+else
+
+	echo "Directory /config/init not found. Creating."
+
+    mkdir /config/init
+
+fi
+
+if [ ! -d /config/cronicle ]
+then
+    echo "Directory /config/cronicle not found. Creating."
+
+    mkdir /config/cronicle
+fi
+
+#Detecting what mode Cronicle should be started in
+if [ $MODE == "manager" ] 
+then
+
+    echo "Cronicle is running in 'manager' mode."
+
+    #Copying config directory to /config/cronicle/conf if not already there, then linking back into Cronicle
+    if [ ! -d /config/cronicle/conf ]
+    then
+        cp -r /app/cronicle/conf /config/cronicle/conf
+        rm -rf /app/cronicle/conf
+        ln -s /config/cronicle/conf /app/cronicle/conf
+    fi
+
+    if [ ! -f /config/cronicle/data/.setup_done ]
+    then
+
+        echo "Setup needed - running now."
+
+        /app/cronicle/bin/control.sh setup
+        touch /app/cronicle/data/.setup_done
+
+        #Moving data dir to /config, then linking it back into Cronicle
+        mv -n /app/cronicle/data /config/cronicle/data
+        rm -rf /app/cronicle/data
+        ln -s /config/cronicle/data /app/cronicle/data
+
+        #exec node /app/cronicle/lib/main.js --color 1
+
+    else
+
+        echo "Setup already completed."
+
+        rm -rf /app/cronicle/data
+        ln -s /config/cronicle/data /app/cronicle/data
+
+        #exec node /app/cronicle/lib/main.js --color 1
+
+    fi
+
+elif [ $MODE == "worker" ] 
+then
+
+    echo "Cronicle is running in 'worker' mode."
+
+    if [ ! -f /config/cronicle/conf/config.json ]
+    then
+
+        echo "No config found. Copy config.json from the manager server and place it in /config/cronicle/conf dir."
+        mkdir -p /config/cronicle/conf
+        exit 0
+
+    else
+
+        #Removing default config.json and linking provided one back into Cronicle
+        rm -rf /app/cronicle/conf/config.json
+        ln -s /config/config.json /app/cronicle/conf/config.json
+
+        #exec node /app/cronicle/lib/main.js --color 1
+
+    fi
+
+else
+
+    echo "'$MODE' is not a recognised appion for the MODE environment variable. Accepted appions are 'manager' and 'worker'."
+
+fi
+
+#echo "Applying permissions to /config and /app (this can take a while on first run or after PUID/PGID changes)"
+#chmod "=rwx" /config
+#chown -R mrmeeb:mrmeeb /config
+#chown -R mrmeeb:mrmeeb /app
\ No newline at end of file
diff --git a/root/etc/s6-overlay/s6-rc.d/container-init/dependencies.d/base b/root/etc/s6-overlay/s6-rc.d/container-init/dependencies.d/base
new file mode 100644
index 0000000..e69de29
diff --git a/root/etc/s6-overlay/s6-rc.d/container-init/type b/root/etc/s6-overlay/s6-rc.d/container-init/type
new file mode 100644
index 0000000..3d92b15
--- /dev/null
+++ b/root/etc/s6-overlay/s6-rc.d/container-init/type
@@ -0,0 +1 @@
+oneshot
\ No newline at end of file
diff --git a/root/etc/s6-overlay/s6-rc.d/container-init/up b/root/etc/s6-overlay/s6-rc.d/container-init/up
new file mode 100644
index 0000000..7682227
--- /dev/null
+++ b/root/etc/s6-overlay/s6-rc.d/container-init/up
@@ -0,0 +1 @@
+/container-init.sh
\ No newline at end of file
diff --git a/root/etc/s6-overlay/s6-rc.d/cronicle-prepare/dependencies.d/base b/root/etc/s6-overlay/s6-rc.d/cronicle-prepare/dependencies.d/base
new file mode 100644
index 0000000..e69de29
diff --git a/root/etc/s6-overlay/s6-rc.d/cronicle-prepare/dependencies.d/container-init b/root/etc/s6-overlay/s6-rc.d/cronicle-prepare/dependencies.d/container-init
new file mode 100644
index 0000000..e69de29
diff --git a/root/etc/s6-overlay/s6-rc.d/cronicle-prepare/type b/root/etc/s6-overlay/s6-rc.d/cronicle-prepare/type
new file mode 100644
index 0000000..3d92b15
--- /dev/null
+++ b/root/etc/s6-overlay/s6-rc.d/cronicle-prepare/type
@@ -0,0 +1 @@
+oneshot
\ No newline at end of file
diff --git a/root/etc/s6-overlay/s6-rc.d/cronicle-prepare/up b/root/etc/s6-overlay/s6-rc.d/cronicle-prepare/up
new file mode 100644
index 0000000..5c021c4
--- /dev/null
+++ b/root/etc/s6-overlay/s6-rc.d/cronicle-prepare/up
@@ -0,0 +1 @@
+exec s6-setuidgid mrmeeb /cronicle-prepare.sh
\ No newline at end of file
diff --git a/root/etc/s6-overlay/s6-rc.d/cronicle/dependencies.d/base b/root/etc/s6-overlay/s6-rc.d/cronicle/dependencies.d/base
new file mode 100644
index 0000000..e69de29
diff --git a/root/etc/s6-overlay/s6-rc.d/cronicle/dependencies.d/cronicle-prepare b/root/etc/s6-overlay/s6-rc.d/cronicle/dependencies.d/cronicle-prepare
new file mode 100644
index 0000000..e69de29
diff --git a/root/etc/s6-overlay/s6-rc.d/cronicle/finish b/root/etc/s6-overlay/s6-rc.d/cronicle/finish
new file mode 100644
index 0000000..767f815
--- /dev/null
+++ b/root/etc/s6-overlay/s6-rc.d/cronicle/finish
@@ -0,0 +1 @@
+echo "$e" > /run/s6-linux-init-container-results/exitcode
\ No newline at end of file
diff --git a/root/etc/s6-overlay/s6-rc.d/cronicle/run b/root/etc/s6-overlay/s6-rc.d/cronicle/run
new file mode 100644
index 0000000..d41cf93
--- /dev/null
+++ b/root/etc/s6-overlay/s6-rc.d/cronicle/run
@@ -0,0 +1,3 @@
+#!/command/with-contenv bash
+# shellcheck shell=bash
+exec s6-setuidgid mrmeeb node /app/cronicle/lib/main.js --color 1
\ No newline at end of file
diff --git a/root/etc/s6-overlay/s6-rc.d/cronicle/type b/root/etc/s6-overlay/s6-rc.d/cronicle/type
new file mode 100644
index 0000000..1780f9f
--- /dev/null
+++ b/root/etc/s6-overlay/s6-rc.d/cronicle/type
@@ -0,0 +1 @@
+longrun
\ No newline at end of file
diff --git a/root/etc/s6-overlay/s6-rc.d/user/contents.d/cronicle b/root/etc/s6-overlay/s6-rc.d/user/contents.d/cronicle
new file mode 100644
index 0000000..e69de29
diff --git a/root/etc/s6-overlay/s6-rc.d/user/contents.d/cronicle-prepare b/root/etc/s6-overlay/s6-rc.d/user/contents.d/cronicle-prepare
new file mode 100644
index 0000000..e69de29
diff --git a/run.sh b/run.sh
deleted file mode 100644
index 4c983b7..0000000
--- a/run.sh
+++ /dev/null
@@ -1,86 +0,0 @@
-#!/bin/bash
-
-#Importing and running additional scripts placed in /config/init
-if [ -d /config/init ]
-then
-	if [ "$(ls -A /config/init)" ]
-    then
-
-        echo "Running additional startup scripts."
-
-        bash /config/init/*
-	
-    else
-        
-        echo "/config/init is empty - no additional startup scripts detected."
-	
-    fi
-else
-
-	echo "Directory /config/init not found. Creating."
-
-    mkdir /config/init
-
-fi
-
-#Detecting what mode Cronicle should be started in
-if [ $MODE == "manager" ] 
-then
-    echo "Cronicle is running in 'manager' mode."
-    
-    #Copying config.json to /config if it isn't there already, then linking it back into Cronicle
-    mv -n /opt/cronicle/conf/config.json /config/config.json
-    rm -rf /opt/cronicle/conf/config.json
-    ln -s /config/config.json /opt/cronicle/conf/config.json
-
-    if [ ! -f /config/data/.setup_done ]
-    then
-
-        echo "Setup needed - running now."
-
-        /opt/cronicle/bin/control.sh setup
-        touch /opt/cronicle/data/.setup_done
-
-        #Moving data dir to /config, then linking it back into Cronicle
-        mv -n /opt/cronicle/data /config/data
-        rm -rf /opt/cronicle/data
-        ln -s /config/data /opt/cronicle/data
-
-        exec node /opt/cronicle/lib/main.js --color 1
-
-    else
-
-        rm -rf /opt/cronicle/data
-        ln -s /config/data /opt/cronicle/data
-
-        exec node /opt/cronicle/lib/main.js --color 1
-
-    fi
-
-elif [ $MODE == "worker" ] 
-then
-
-    echo "Cronicle is running in 'worker' mode."
-
-    if [ ! -f /config/config.json ]
-    then
-
-        echo "No config found. Copy config.json from the manager server and place it in the /config dir."
-
-        exit 0
-
-    else
-
-        #Removing default config.json and linking provided one back into Cronicle
-        rm -rf /opt/cronicle/conf/config.json
-        ln -s /config/config.json /opt/cronicle/conf/config.json
-
-        exec node /opt/cronicle/lib/main.js --color 1
-
-    fi
-
-else
-
-    echo "'$MODE' is not a recognised option for the MODE environment variable. Accepted options are 'manager' and 'worker'."
-
-fi
\ No newline at end of file

From 2ecac5841463251858fae8559054a5d9561622e4 Mon Sep 17 00:00:00 2001
From: MrMeeb <charles.macdonald@me.com>
Date: Sat, 27 May 2023 15:37:58 +0000
Subject: [PATCH 5/7] add .gitignore [CI SKIP]

---
 .gitignore | 2 ++
 1 file changed, 2 insertions(+)
 create mode 100644 .gitignore

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..1479fe9
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+dist/
+.tags
\ No newline at end of file

From f990871798a4fdb870e05e8ff7e0350331fc5c84 Mon Sep 17 00:00:00 2001
From: MrMeeb <charles.macdonald@me.com>
Date: Sat, 27 May 2023 16:46:47 +0000
Subject: [PATCH 6/7] updated readme [CI SKIP]

---
 README.md | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 6f56c32..964360f 100644
--- a/README.md
+++ b/README.md
@@ -1,9 +1,20 @@
 # Cronicle Docker
 
+![Drone (self-hosted) with branch](https://img.shields.io/drone/build/MrMeeb/cronicle-docker/main?label=main&server=https%3A%2F%2Fdrone.mrmeeb.stream&style=for-the-badge) ![Drone (self-hosted) with branch](https://img.shields.io/drone/build/MrMeeb/cronicle-docker/develop?label=develop&server=https%3A%2F%2Fdrone.mrmeeb.stream&style=for-the-badge)
+
 Dockerised Cronicle, based on the [Cronicle-Edge](https://github.com/cronicle-edge/cronicle-edge) fork.
 
 Can function in both the **manager** and **worker** role.
 
+## Tags
+
+|Tag    |Description|
+|-------|-----------|
+|latest |Latest image built from the main branch. Usually coincides with a tagged release.|
+|develop|Latest image built from the develop branch. Commits are made to the develop branch before being merged to main. Old versions of `develop` are removed after 14 days.|
+
+Tags relating to releases are also available, for locking in on a specific version.
+
 ## Running 
 
 `config.json`, located in `/config/cronicle/conf/config.json`, is automatically generated on the first run of Cronicle in 'manager' mode. This file must be kept identical between the manager and any workers it controls.
@@ -68,4 +79,4 @@ This container automatically checks for scripts in `/config/init` and runs them
 |MODE    |manager, worker|manager|Determines what mode Cronicle runs in
 |PUID    |int    |1000   |Sets the UID of the user Cronicle runs under
 |PGID    |int    |1000   |Sets the GID of the user Cronicle runs under
-|TZ      |[List of valid TZs](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List)    |UTC    |Sets the timezone of the container and by extension Cronicle
\ No newline at end of file
+|TZ      |[List of valid TZs](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List)    |UTC    |Sets the timezone of the container and by extension Cronicle

From 1ac78908ad955a5b2a6d6a544f313c1c1d7594d6 Mon Sep 17 00:00:00 2001
From: MrMeeb <charles.macdonald@me.com>
Date: Sat, 27 May 2023 16:49:13 +0000
Subject: [PATCH 7/7] tweak build behaviour [CI SKIP]

---
 .drone.yml | 40 ++++++++++++++++++++++++++++++++--------
 1 file changed, 32 insertions(+), 8 deletions(-)

diff --git a/.drone.yml b/.drone.yml
index 665721d..0ac6ec2 100644
--- a/.drone.yml
+++ b/.drone.yml
@@ -1,11 +1,12 @@
 kind: pipeline
 type: docker
-name: build-release-images
+name: build-main-images
 trigger:
   event:
     exclude:
     - pull_request
   ref:
+    - refs/heads/main
     - refs/tags/**
 
 platform:
@@ -13,14 +14,34 @@ platform:
   arch: amd64
 
 steps:
-  # Set tags for main branch - release tag and 'latest'
-- name: make-tags-main
+
+- name: get-tags
+  image: docker:git
+  commands:
+    - git fetch --tags
+  when:
+    ref:
+      - refs/tags/**
+
+  # Set tags for main branch
+- name: make-tags
+  image: node
+  commands:
+    - echo -n "${DRONE_COMMIT_SHA:0:8}, latest" > .tags
+  when:
+    ref:
+      - refs/heads/main
+
+- name: make-tags-release
   image: node
   commands:
     - echo -n "${DRONE_TAG}, latest" > .tags
+  when:
+    ref:
+      - refs/tags/**
 
-  # Build containers from main branch when released
-- name: build-main
+  # Build containers from main branch
+- name: build
   image: thegeeklab/drone-docker-buildx
   privileged: true
   settings:
@@ -42,6 +63,9 @@ steps:
       from_secret: gitea_token
   commands:
     - goreleaser release
+  when:
+    ref:
+      - refs/tags/**
 
 - name: notify
   image: plugins/slack
@@ -70,13 +94,13 @@ platform:
 
 steps:
   # Set tags for develop branch - git commit SHA and 'develop'
-- name: make-tags-develop
+- name: make-tags
   image: node
   commands:
-    - echo -n "${DRONE_COMMIT_SHA:0:8}, develop" > .tags
+    - echo -n "develop-${DRONE_COMMIT_SHA:0:8}, develop" > .tags
    
   # Build containers from develop branch
-- name: build-develop
+- name: build
   image: thegeeklab/drone-docker-buildx
   privileged: true
   settings: