Skip to content

Commit

Permalink
tweak hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
SaswatPadhi committed Sep 30, 2024
1 parent 47c5d1c commit 61861cc
Show file tree
Hide file tree
Showing 28 changed files with 124 additions and 78 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Optional setup:
```
2. For each desired composition, override the:
- static and/or dynamic env generators in a similar manner
- additional prerequisite compositions: `pre.override.reqs`
- docker service configuration: `docker-compose.override.yml`
- docker service hooks: `docker-compose.up.pre_hook.override.01.sh` etc.

Expand Down Expand Up @@ -1129,6 +1130,9 @@ When deploying, all changes MUST appear in `.gitignore`d files:
- see [`dynamic.global.env.sh`](dynamic.global.env.sh) for the default

- within each composition:
- `pre.override.reqs` may name _additional_ compositions as prerequisites
- compositions listed in `pre.reqs` cannot be removed, however
- see [`tang/pre.reqs`](tang/pre.reqs) for an example
- `options.override.env` may contain overrides for default values of the `{devices|labels|logging|ports}`
options
- options provided on the command-line may still override `options.override.conf`
Expand All @@ -1142,8 +1146,11 @@ When deploying, all changes MUST appear in `.gitignore`d files:
- `docker-compose.override.{yml|yaml}` may contain overrides for docker compose
- modular overrides may also be specified for individual YAML fragment files:
`docker-compose.{devices|labels|logging|ports}.override.{yml|yaml}`
- `docker-compose.{pre,post}_hook.override.*.sh`
may define additional hooks to be run before `docker compose`
- see [`nextcloud/docker-compose.pre_hook.sh`](nextcloud/docker-compose.pre_hook.sh) for an example
- `docker-compose.{up,down,clean}.{pre,post}_hook.override.*.sh`
may define additional hooks to be run
may define additional verb-specific hooks to be run
- see [`monitarr/docker-compose.up.pre_hook.sh`](monitarr/docker-compose.up.pre_hook.sh) for an example

#### Subdirectories
Expand Down
2 changes: 1 addition & 1 deletion _scripts/test_comp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function SETUP () {
echo "INPUT: $3"
fi

echo "$3" | ./comp $2 >"$COMP_OUT_PATH" 2>"$COMP_ERR_PATH"
./comp $2 >"$COMP_OUT_PATH" 2>"$COMP_ERR_PATH" <<<"$3"
COMP_EXIT_CODE=$?
if [ -n "$DEBUG" ]; then
echo "\$COMP_ERR_PATH contents:"
Expand Down
11 changes: 11 additions & 0 deletions airdcpp/docker-compose.pre_hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

set -Eumo pipefail

SELF_DIR="$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
DATA_DIR="$SELF_DIR/data"

mkdir -p "$DATA_DIR/airdcpp/config" \
"$DATA_DIR/airdcpp/downloads" \
"$DATA_DIR/airdcpp/shared" \
"$DATA_DIR/openvpn/config"
11 changes: 0 additions & 11 deletions airdcpp/docker-compose.up.pre_hook.sh

This file was deleted.

File renamed without changes.
25 changes: 17 additions & 8 deletions comp
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,11 @@ __read_option () {
}

__run_hooks () {
local stage="$1.$2"
local stage="$1"
[ -z "${2:-}" ] || stage="$1.$2"
ls docker-compose."$stage"_hook*.sh &> /dev/null || return 0
echo "[*] Running '$2' hooks for '$1' ..."
[ -n "${2:-}" ] && echo "[>] Running '$2' hooks for '$1' ..." \
|| echo "[>] Running '$1' hooks ..."

if ! ( set -a && source .env && ./docker-compose."$stage"_hook.sh ) ; then
__error "HOOK 'docker-compose.${stage}_hook.sh' FAILED!" ; return 1
Expand Down Expand Up @@ -257,14 +259,14 @@ do_overrides () {
any_override='YES'
printf '[G] ' ; realpath -s --relative-to="$(pwd)/.." "$ofile"
done < <(find .. -maxdepth 1 -type f -iname '*override*')
[ -n "$any_override" ] || echo '[>] No global override files.'
[ -n "$any_override" ] || echo '[-] No global override files.'

any_override=''
while IFS= read -r ofile ; do
any_override='YES'
printf '[L] ' ; realpath -s --relative-to="$(pwd)/.." "$ofile"
done < <(find . -maxdepth 1 -type f -iname '*override*')
[ -n "$any_override" ] || echo '[>] No local override files.'
[ -n "$any_override" ] || echo '[-] No local override files.'
}

do_pull () {
Expand All @@ -275,7 +277,7 @@ do_pull () {
do_status () {
__do_prereqs status || return 1

printf '[s] Querying service:'
printf '[?] Querying service:'
for svc in $( "$YQ_CMD" -M '.services | keys | .[]' docker-compose.yml ) ; do
echo -n " $svc"
if ! ( $DOCKER_COMPOSE_CMD ps "$svc" 2> /dev/null | grep -q healthy ) ; then
Expand Down Expand Up @@ -508,7 +510,9 @@ perform () {
__create_external_networks "${COMPOSE_FILES[@]}" \
|| __maybe_fail_fast $EXIT_CODE_SETUP_ERROR || continue
__gen_templates \
|| __maybe_fail_fast $EXIT_CODE_SETUP_ERROR || continue
|| __maybe_fail_fast $EXIT_CODE_SETUP_ERROR || continue
[ "$OPTION_HOOKS" != "yes" ] || __run_hooks pre \
|| __maybe_fail_fast $EXIT_CODE_PRE_HOOK_SCRIPT_ERROR || continue
fi

[ "$OPTION_HOOKS" != "yes" ] || __run_hooks "$SIMPLE_VERB" pre \
Expand All @@ -522,12 +526,17 @@ perform () {
local verb_exit=0
"do_${SIMPLE_VERB}" ; verb_exit=$?

[ "$SIMPLE_VERB" != "validate" ] || [ $verb_exit -ne 0 ] || echo "[>] '$comp' is valid!"
[ "$SIMPLE_VERB" != "status" ] || [ $verb_exit -ne 0 ] || echo "[>] '$comp' is healthy!"
[ "$SIMPLE_VERB" != "validate" ] || [ $verb_exit -ne 0 ] || echo "[=] '$comp' is valid!"
[ "$SIMPLE_VERB" != "status" ] || [ $verb_exit -ne 0 ] || echo "[=] '$comp' is healthy!"

[ $verb_exit -eq 0 ] \
|| __maybe_fail_fast $EXIT_CODE_SIMPLE_VERB_FAILURE || continue

if __will_invoke_compose "$SIMPLE_VERB" ; then
[ "$OPTION_HOOKS" != "yes" ] || __run_hooks post \
|| __maybe_fail_fast $EXIT_CODE_POST_HOOK_SCRIPT_ERROR || continue
fi

[ "$OPTION_HOOKS" != "yes" ] || __run_hooks "$SIMPLE_VERB" post \
|| __maybe_fail_fast $EXIT_CODE_POST_HOOK_SCRIPT_ERROR
done
Expand Down
6 changes: 0 additions & 6 deletions docker.sock/docker-compose.up.pre_hook.sh

This file was deleted.

9 changes: 9 additions & 0 deletions gitea/docker-compose.pre_hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

set -Eumo pipefail

SELF_DIR="$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
DATA_DIR="$SELF_DIR/data"

mkdir -p "$DATA_DIR/gitea/var/lib/gitea" \
"$DATA_DIR/gitea/etc/gitea"
3 changes: 0 additions & 3 deletions gitea/docker-compose.up.pre_hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ set -Eumo pipefail
SELF_DIR="$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
DATA_DIR="$SELF_DIR/data"

mkdir -p $DATA_DIR/gitea/var/lib/gitea \
$DATA_DIR/gitea/etc/gitea

if ! [ -f "$DATA_DIR/gitea/etc/gitea/app.ini" ]; then
mkdir -p "$DATA_DIR/gitea/etc/gitea/"
cp "$SELF_DIR/generated/gitea/etc/gitea/app.ini" \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ set -Eumo pipefail
SELF_DIR="$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
DATA_DIR="$SELF_DIR/data"

mkdir -p $DATA_DIR/hass/config \
$DATA_DIR/hass/media
mkdir -p "$DATA_DIR/hass/config" \
"$DATA_DIR/hass/media"
10 changes: 10 additions & 0 deletions indexarr/docker-compose.pre_hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

set -Eumo pipefail

SELF_DIR="$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
DATA_DIR="$SELF_DIR/data"

mkdir -p "$DATA_DIR/jackett/config" \
"$DATA_DIR/jackett/downloads" \
"$DATA_DIR/openvpn/config"
4 changes: 0 additions & 4 deletions indexarr/docker-compose.up.pre_hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ set -Eumo pipefail
SELF_DIR="$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
DATA_DIR="$SELF_DIR/data"

mkdir -p $DATA_DIR/jackett/config \
$DATA_DIR/jackett/downloads \
$DATA_DIR/openvpn/config

if ! [ -f "$DATA_DIR/jackett/config/ServerConfig.json" ]; then
cp "$SELF_DIR/generated/jackett/config/ServerConfig.json" \
"$DATA_DIR/jackett/config/ServerConfig.json"
Expand Down
10 changes: 10 additions & 0 deletions influxdb/docker-compose.pre_hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

set -Eumo pipefail

SELF_DIR="$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
DATA_DIR="$SELF_DIR/data"

mkdir -p "$DATA_DIR/influxdb/cert" \
"$DATA_DIR/influxdb/etc/influxdb2" \
"$DATA_DIR/influxdb/var/lib/influxdb2"
4 changes: 0 additions & 4 deletions influxdb/docker-compose.up.pre_hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ set -Eumo pipefail
SELF_DIR="$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
DATA_DIR="$SELF_DIR/data"

mkdir -p "$DATA_DIR/influxdb/cert" \
"$DATA_DIR/influxdb/etc/influxdb2" \
"$DATA_DIR/influxdb/var/lib/influxdb2"

echo -n "[~] Checking for default certificates: "
cd "$DATA_DIR/influxdb/cert"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ set -Eumo pipefail
SELF_DIR="$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
DATA_DIR="$SELF_DIR/data"

mkdir -p $DATA_DIR/mariadb/var/lib/mysql
mkdir -p "$DATA_DIR/mariadb/var/lib/mysql"
16 changes: 16 additions & 0 deletions monitarr/docker-compose.pre_hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

set -Eumo pipefail

SELF_DIR="$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
DATA_DIR="$SELF_DIR/data"

mkdir -p "$DATA_DIR/lidarr/config" \
"$DATA_DIR/lidarr/downloads" \
"$DATA_DIR/lidarr/music" \
"$DATA_DIR/radarr/config" \
"$DATA_DIR/radarr/downloads" \
"$DATA_DIR/radarr/movies" \
"$DATA_DIR/sonarr/config" \
"$DATA_DIR/sonarr/downloads" \
"$DATA_DIR/sonarr/tv"
10 changes: 0 additions & 10 deletions monitarr/docker-compose.up.pre_hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,6 @@ set -Eumo pipefail
SELF_DIR="$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
DATA_DIR="$SELF_DIR/data"

mkdir -p $DATA_DIR/lidarr/config \
$DATA_DIR/lidarr/downloads \
$DATA_DIR/lidarr/music \
$DATA_DIR/radarr/config \
$DATA_DIR/radarr/downloads \
$DATA_DIR/radarr/movies \
$DATA_DIR/sonarr/config \
$DATA_DIR/sonarr/downloads \
$DATA_DIR/sonarr/tv

if ! [ -f "$DATA_DIR/radarr/config/config.xml" ]; then
cp "$SELF_DIR/generated/radarr/config/config.xml" \
"$DATA_DIR/radarr/config/config.xml"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ set -Eumo pipefail
SELF_DIR="$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
DATA_DIR="$SELF_DIR/data"

mkdir -p $DATA_DIR/navidrome/data \
$DATA_DIR/navidrome/music
mkdir -p "$DATA_DIR/navidrome/data" \
"$DATA_DIR/navidrome/music"
13 changes: 13 additions & 0 deletions nextcloud/docker-compose.pre_hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

set -Eumo pipefail

SELF_DIR="$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
DATA_DIR="$SELF_DIR/data"

mkdir -p "$DATA_DIR/mariadb/var/lib/mysql" \
"$DATA_DIR/redis/data" \
"$DATA_DIR/nextcloud/crontabs" \
"$DATA_DIR/nextcloud/data" \
"$DATA_DIR/nextcloud/var/www/html" \
"$DATA_DIR/nextcloud/usr/local/etc/php/conf.d"
13 changes: 3 additions & 10 deletions nextcloud/docker-compose.up.pre_hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,9 @@ set -Eumo pipefail
SELF_DIR="$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
DATA_DIR="$SELF_DIR/data"

mkdir -p $DATA_DIR/mariadb/var/lib/mysql \
$DATA_DIR/redis/data \
$DATA_DIR/nextcloud/crontabs \
$DATA_DIR/nextcloud/data \
$DATA_DIR/nextcloud/var/www/html \
$DATA_DIR/nextcloud/usr/local/etc/php/conf.d

# FIXME: Workaround from https://github.com/nextcloud/docker/issues/763#issuecomment-1007447212
touch $DATA_DIR/nextcloud/usr/local/etc/php/conf.d/redis-session.ini
touch "$DATA_DIR/nextcloud/usr/local/etc/php/conf.d/redis-session.ini"

# FIXME: Workaround from https://github.com/nextcloud/docker/issues/1494#issuecomment-1213540687
mkdir -p $DATA_DIR/nextcloud/etc/apache2/conf-enabled
touch $DATA_DIR/nextcloud/etc/apache2/conf-enabled/remoteip.conf
mkdir -p "$DATA_DIR/nextcloud/etc/apache2/conf-enabled"
touch "$DATA_DIR/nextcloud/etc/apache2/conf-enabled/remoteip.conf"
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ set -Eumo pipefail
SELF_DIR="$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
DATA_DIR="$SELF_DIR/data"

mkdir -p $DATA_DIR/tang/db
mkdir -p "$DATA_DIR/tang/db"
11 changes: 11 additions & 0 deletions teslamate/docker-compose.pre_hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

set -Eumo pipefail

SELF_DIR="$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
DATA_DIR="$SELF_DIR/data"

mkdir -p "$DATA_DIR/teslamate/opt/app/import" \
"$DATA_DIR/db/var/lib/postgresql/data" \
"$DATA_DIR/mqtt/mosquitto/config" \
"$DATA_DIR/mqtt/mosquitto/data"
11 changes: 0 additions & 11 deletions teslamate/docker-compose.up.pre_hook.sh

This file was deleted.

9 changes: 9 additions & 0 deletions traefik/docker-compose.pre_hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

set -Eumo pipefail

SELF_DIR="$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
DATA_DIR="$SELF_DIR/data"

mkdir -p "$DATA_DIR/traefik/cert" \
"$DATA_DIR/traefik/etc/traefik/lets-encrypt"
3 changes: 0 additions & 3 deletions traefik/docker-compose.up.pre_hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ set -Eumo pipefail
SELF_DIR="$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
DATA_DIR="$SELF_DIR/data"

mkdir -p "$DATA_DIR/traefik/cert" \
"$DATA_DIR/traefik/etc/traefik/lets-encrypt"

echo -n "[~] Checking for default certificates: "
cd "$DATA_DIR/traefik/cert"

Expand Down
File renamed without changes.

0 comments on commit 61861cc

Please sign in to comment.