summaryrefslogtreecommitdiffstats
path: root/acid
diff options
context:
space:
mode:
authorMalfurious <m@lfurio.us>2023-08-09 01:43:40 -0400
committerMalfurious <m@lfurio.us>2023-08-09 01:43:40 -0400
commite35da6fc7bf4c3ca554c534e2b72922c7bfe1bed (patch)
treee12147dde806f9bc8a5feb26b2e3052224ca3084 /acid
parent2c3e2e404c87d01166471ec9f27912d654dec9bb (diff)
downloadcychedelic-e35da6fc7bf4c3ca554c534e2b72922c7bfe1bed.tar.gz
cychedelic-e35da6fc7bf4c3ca554c534e2b72922c7bfe1bed.zip
acid: Add service build helper script
This is a merged version of a normal service builder and a cychedelic self-builder. Signed-off-by: Malfurious <m@lfurio.us>
Diffstat (limited to 'acid')
-rwxr-xr-xacid/cyche-build48
1 files changed, 48 insertions, 0 deletions
diff --git a/acid/cyche-build b/acid/cyche-build
new file mode 100755
index 0000000..586e230
--- /dev/null
+++ b/acid/cyche-build
@@ -0,0 +1,48 @@
+#!/bin/bash -e
+
+# cyche-build <name> <hash> [--self]
+#
+# (Re)build and deploy docker services using the files associated with <name>.
+#
+# In the typical case, this is a straightforward process and `docker compose up`
+# can properly recreate/start containers for the guest service. However, when
+# rebuilding cychedelic itself, --self must be given, to instruct this file to
+# modify its behavior to support self-upgrade of the running compose service.
+#
+# In `--self` mode, we prepare and start the cychedelic service under an
+# alternate project name each time, before taking down the existing (old)
+# services. This is necessary because running `docker compose up` terminates
+# old containers before starting new one. Termination of the ACID service
+# interrupts the `compose up` process before it can start the replacements.
+# Normally, `docker compose down` is then not needed.
+#
+# We take <hash> (from cyche-source) so we may commit it to the cache iff the
+# deployment is successful.
+#
+# This file exits early on any failure (non-zero). On a successful run in
+# `--self` mode, this file does not exit (we are killed by `compose down`).
+
+cd "/services/$1"
+
+if [ "$3" == "--self" ]; then
+ slug=$(echo -n "$1-"; tr -dc a-z </dev/urandom | head -c 12)
+ prev="--project-name '$(cat '.git/previous_slug')'"
+ next="--project-name '$slug'"
+fi
+
+docker compose $next pull
+docker compose $next build \
+ --force-rm \
+ --no-cache \
+ --pull
+docker compose $next up \
+ --detach \
+ --remove-orphans \
+ --force-recreate
+
+echo "$2" >.git/previous_hash
+
+if [ "$3" == "--self" ]; then
+ echo "$slug" >.git/previous_slug
+ docker compose $prev down
+fi