summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMalfurious <m@lfurio.us>2023-10-30 14:11:00 -0400
committerMalfurious <m@lfurio.us>2023-11-02 06:11:59 -0400
commit0da2ed7bd1cd7be76b6803a0c638036614a8f7b9 (patch)
treee96eaf8fc9a4630b7635a3c03382d810585d9c36
parent47dbaf2c1d6329fdc814a107e0020b5b23e2d237 (diff)
downloadcychedelic-0da2ed7bd1cd7be76b6803a0c638036614a8f7b9.tar.gz
cychedelic-0da2ed7bd1cd7be76b6803a0c638036614a8f7b9.zip
Merge data volumes
I need something more complicated than just 1 new directory for logs, so let's go to the trouble now of merging the persistent volumes together and use subdirectories/files. The default location is now '/data'. To aid similar changes in the future, the locations of these persistent files are no longer hard-coded in the source, but defined by global shell variables. Additionally, a bug is fixed which impacted our ability to accurately clean old logs and calculate the next job number. Signed-off-by: Malfurious <m@lfurio.us>
-rwxr-xr-xacid/acid29
-rwxr-xr-xacid/acid-build2
-rwxr-xr-xacid/acid-remove4
-rwxr-xr-xacid/acid-source2
-rw-r--r--docker-compose.yml9
5 files changed, 27 insertions, 19 deletions
diff --git a/acid/acid b/acid/acid
index 49e8e72..4f4da5a 100755
--- a/acid/acid
+++ b/acid/acid
@@ -1,9 +1,12 @@
-#!/bin/bash
+#!/bin/bash -a
# cychedelic ACID daemon
# cychedelic is an automated Continuous Deployment solution. See the README for
# more information.
+CYCHE_SERVICE_DIR="/data/services"
+CYCHE_LOG_DIR="/data/logs"
+CYCHE_STATUS_FILE="/data/status"
source config.sh
now() {
@@ -16,10 +19,17 @@ should_restart() {
[ $runtime -gt $CYCHE_MAINT_TIME ]
}
+prune_logs() {
+ ls -A "$CYCHE_LOG_DIR" \
+ | sort -n | head -n "$((CYCHE_LOG_SIZE*-1))" \
+ | sed "s?^?$CYCHE_LOG_DIR/?" \
+ | xargs rm -f
+}
+
log_filename() {
- latest=$(find /logs -type f | sort -rn | sed 's/^\/logs\/0*//;s/_.*$//;1q')
- [ -z "$latest" ] && number="1" || number=$((latest+1))
- printf '/logs/%010i_%s_%s.log\n' "$number" "$(now)" "$1"
+ latest=$(ls -A "$CYCHE_LOG_DIR" | sort -rn | sed 's/_.*$//;1q')
+ [ -z "$latest" ] && number="0" || number=$((latest+1))
+ printf '%s/%s_%s_%s.log' "$CYCHE_LOG_DIR" "$number" "$(now)" "$1"
}
do_job() {
@@ -51,10 +61,10 @@ update() {
log=$(log_filename "${arr[0]}")
[ "$1" == "$forceopt" ] && f="--force" || f=""
- touch /logs/active
+ echo "$log" >"$CYCHE_STATUS_FILE"
do_job $line "$f" "$selfopt" >"$log" 2>&1
res=$?
- rm -f /logs/active
+ truncate -s 0 "$CYCHE_STATUS_FILE"
if [ $res -ne 0 ]; then
echo "Updated ${arr[0]}"
@@ -70,7 +80,7 @@ update() {
remove() {
next=$(printf '%s\n' "${CYCHE_SERVICES[@]}" | awk '{print $1}')
- prev=$(ls -A '/services')
+ prev=$(ls -A "$CYCHE_SERVICE_DIR")
removed=$(printf '%s\n' "$next" "$next" "$prev" | sort | uniq -u)
for name in $removed; do
@@ -85,14 +95,15 @@ remove() {
# sleep briefly at the beginning to allow the previous cychedelic instance time
# to die.
echo "cychedelic ACID kicking in ..."
-rm -f /logs/active
+mkdir -p "$CYCHE_SERVICE_DIR" "$CYCHE_LOG_DIR"
+truncate -s 0 "$CYCHE_STATUS_FILE"
sleep "$CYCHE_STARTUP_TIME"
remove
update --force
docker system prune --force --all
-find /logs -type f | sort -n | head -n "$((CYCHE_LOG_SIZE*-1))" | xargs rm -f
+prune_logs
starttime=$(now)
# monitor source changes
diff --git a/acid/acid-build b/acid/acid-build
index fd5b69d..87c281e 100755
--- a/acid/acid-build
+++ b/acid/acid-build
@@ -23,7 +23,7 @@
# 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"
+cd "$CYCHE_SERVICE_DIR/$1"
# For <file>, no absolute paths and no '../'
if ! echo "$2" | grep -Evq '\.\.|^/'; then
diff --git a/acid/acid-remove b/acid/acid-remove
index 6094a23..2c96669 100755
--- a/acid/acid-remove
+++ b/acid/acid-remove
@@ -5,11 +5,11 @@
# Stop the service <name>, which was previously managed by cychedelic, and
# remove associated files.
-name=$(cat "/services/$1/.git/previous_slug")
+name=$(cat "$CYCHE_SERVICE_DIR/$1/.git/previous_slug")
[ -z "$name" ] && name="$1"
docker compose --project-name "$name" down
echo "Removing files..."
-rm -rf "/services/$1"
+rm -rf "$CYCHE_SERVICE_DIR/$1"
echo "Done."
diff --git a/acid/acid-source b/acid/acid-source
index 2d507d6..29b1516 100755
--- a/acid/acid-source
+++ b/acid/acid-source
@@ -23,7 +23,7 @@ gethash() {
"$1" # pattern
}
-cd '/services'
+cd "$CYCHE_SERVICE_DIR"
# For <name>, limit to a-z, 0-9, -, _
if ! echo "$1" | grep -Eq '^[-_a-z0-9]*$'; then
diff --git a/docker-compose.yml b/docker-compose.yml
index 111535f..ea05646 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -5,12 +5,9 @@ services:
build: "acid"
restart: "always"
volumes:
- - "logs:/logs"
- - "services:/services"
+ - "data:/data"
- "/var/run/docker.sock:/var/run/docker.sock:ro"
volumes:
- logs:
- name: "cychedelic-logs"
- services:
- name: "cychedelic-services"
+ data:
+ name: "cychedelic_data"