Skip to content

Commit

Permalink
move post_hook msgs and pre.reqs into meta.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
SaswatPadhi committed Dec 12, 2024
1 parent 1d59f08 commit d7e34c8
Show file tree
Hide file tree
Showing 45 changed files with 162 additions and 169 deletions.
10 changes: 0 additions & 10 deletions airdcpp/docker-compose.up.post_hook.sh

This file was deleted.

9 changes: 9 additions & 0 deletions airdcpp/meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
messages:
up:
post:
- >-
${_bold_}${_CUR_COMP_}${_normal_} may now be accessed on
${_fg_magenta_}${_uline_}https://${SERVER_WAN_FQDN}:${SERVER_WAN_HTTPS_PORT}/${AIRDCPP_BASE_PATH}/${_normal_}
pre_reqs:
- traefik
1 change: 0 additions & 1 deletion airdcpp/pre.reqs

This file was deleted.

34 changes: 25 additions & 9 deletions comp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ source "$SCRIPTS_DIR/colors.sh"

COMP_SELF_CALL_DEPTH="${COMP_SELF_CALL_DEPTH:-0}"

PREREQS_FILENAME="pre.reqs"
PREREQS_OVERRIDE_FILENAME="pre.override.reqs"

DOCKER_CMD="docker"
DOCKER_COMPOSE_CMD="$LIB_DIR/compose"
YQ_CMD="$LIB_DIR/yq"
Expand Down Expand Up @@ -47,7 +44,7 @@ __append_env_from () {
if [ -f "$1" ] ; then
local script_file="${1/#./$_CUR_COMP_}"
echo -n " ${script_file#"$SELF_DIR"/}"
if set -a && source .env && "$1" > .env.add ; then
if bash -c "set -a ; source .env ; $1" > .env.add ; then
cat .env.add >> .env ; rm .env.add
else
echo " ${_fg_red_}${_bold_}FAILED!${_normal_}" ; return 1
Expand All @@ -65,9 +62,10 @@ __CALL_SELF__ () {
}

__create_external_networks () {
local query='.networks | with_entries(select(.value.external == true)) | keys | .[]'
local EXTERNAL_NETWORKS=( )
for yml in "${_CUR_COMPOSE_FILES_[@]}" "${_CUR_COMPOSE_OVERRIDE_FILES_[@]}" ; do
for ext_net in $($YQ_CMD -M '.networks | with_entries(select(.value.external == true)) | keys | .[]' "$yml") ; do
for ext_net in $( "$YQ_CMD" -M "$query" "$yml" ) ; do
# NOTE: `echo ... | xargs` to get rid of quotes around network name during extraction via `yq`.
EXTERNAL_NETWORKS+=( $(echo "$ext_net" | xargs) )
done
Expand All @@ -80,7 +78,6 @@ __create_external_networks () {

__do_prereqs () {
[ "$FLAG_SKIP_PREREQS" != "yes" ] || return 0
[ -f "$PREREQS_FILENAME" ] || return 0

local verb="$1"
local ensure_running="${2:-no}"
Expand All @@ -93,7 +90,7 @@ __do_prereqs () {
else
__CALL_SELF__ "$verb" -F "$prereq_comp_dir" || return 1
fi
done < <( cat "$PREREQS_FILENAME" "$PREREQS_OVERRIDE_FILENAME" 2>/dev/null )
done < <( "$YQ_CMD" "${_CUR_YQ_META_QUERY_PFX_} .pre_reqs | .[]" "meta.yml" 2>/dev/null )
}

__error () {
Expand Down Expand Up @@ -225,10 +222,22 @@ __run_hooks () {
fi
}

__show_message () {
local stage="$1"
[ -z "${2:-}" ] || stage="$1.$2"

while IFS= read -r msg ; do
echo -n "${_fg_white_}${_bg_magenta_}${_bold_} * ${_normal_} "
_CUR_COMP_="$_CUR_COMP_" _CUR_VERB_="$_CUR_VERB_" \
bash -c "set -a ; source '$SCRIPTS_DIR/colors.sh' ; source .env ; echo '$msg'"
done < <( "$YQ_CMD" "${_CUR_YQ_META_QUERY_PFX_} .messages.$stage | .[]" "meta.yml" 2>/dev/null )
}

__verify_volumes () {
local query='.services.[] | with_entries(select(.key == "volumes")) | .[] | .[] as $v | $v'
local mounted_volumes=( )
for yml in "${_CUR_COMPOSE_FILES_[@]}" "${_CUR_COMPOSE_OVERRIDE_FILES_[@]}" ; do
for vol in $($YQ_CMD -M '.services.[] | with_entries(select(.key == "volumes")) | .[] | .[] as $v | $v' "$yml") ; do
for vol in $( "$YQ_CMD" -M "$query" "$yml" ) ; do
case $vol in
./* | /* ) mounted_volumes+=( "$vol" ) ;;
* ) ;;
Expand Down Expand Up @@ -518,7 +527,8 @@ fi
COMPOSITIONS=( "$@" )
OPTIONS_FROM_ARGS=( "$OPTION_DEVICES" "$OPTION_HOOKS" "$OPTION_LABELS" "$OPTION_LOGGING" "$OPTION_PORTS" )

_FINAL_EXIT_CODE_=0 ; _CUR_STAGE_=0 ; unset _CUR_COMP_ _CUR_VERB_ ; __print_sepator_line
_FINAL_EXIT_CODE_=0 ; _CUR_STAGE_=0 ; _CUR_YQ_META_QUERY_PFX_=""
unset _CUR_COMP_ _CUR_VERB_ ; __print_sepator_line
for _CUR_COMP_ in "${COMPOSITIONS[@]}" ; do
_CUR_COMP_="${_CUR_COMP_%/}"
if ! cd "$SELF_DIR/$_CUR_COMP_" 2>/dev/null ; then
Expand All @@ -530,6 +540,8 @@ for _CUR_COMP_ in "${COMPOSITIONS[@]}" ; do
__maybe_fail_fast $EXIT_CODE_COMPOSITION_NOT_FOUND || continue
fi

[ ! -f "meta.override.yml" ] || _CUR_YQ_META_QUERY_PFX_='. *= load("meta.override.yml") | '

_CUR_COMPOSE_FILES_=( "docker-compose.yml" ) ; _CUR_COMPOSE_OVERRIDE_FILES_=()
if [ "$FLAG_SKIP_OVERRIDES" != "yes" ] && [ -f "docker-compose.override.yml" ] ; then
_CUR_COMPOSE_OVERRIDE_FILES_=( "docker-compose.override.yml")
Expand Down Expand Up @@ -576,10 +588,12 @@ for _CUR_COMP_ in "${COMPOSITIONS[@]}" ; do
__gen_templates || __maybe_fail_fast $EXIT_CODE_SETUP_ERROR || continue
[ "$OPTION_HOOKS" != "yes" ] || __run_hooks pre \
|| __maybe_fail_fast $EXIT_CODE_PRE_HOOK_SCRIPT_ERROR || continue
__show_message pre
fi

[ "$OPTION_HOOKS" != "yes" ] || __run_hooks "$_CUR_VERB_" pre \
|| __maybe_fail_fast $EXIT_CODE_PRE_HOOK_SCRIPT_ERROR || continue
__show_message "$_CUR_VERB_" pre

if __will_invoke_compose ; then
__verify_volumes || __maybe_fail_fast $EXIT_CODE_SETUP_ERROR || continue
Expand All @@ -595,10 +609,12 @@ for _CUR_COMP_ in "${COMPOSITIONS[@]}" ; do
if __will_invoke_compose ; then
[ "$OPTION_HOOKS" != "yes" ] || __run_hooks post \
|| __maybe_fail_fast $EXIT_CODE_POST_HOOK_SCRIPT_ERROR || continue
__show_message post
fi

[ "$OPTION_HOOKS" != "yes" ] || __run_hooks "$_CUR_VERB_" post \
|| __maybe_fail_fast $EXIT_CODE_POST_HOOK_SCRIPT_ERROR
__show_message "$_CUR_VERB_" post
done
unset _CUR_VERB_ ; __print_sepator_line
done
Expand Down
10 changes: 0 additions & 10 deletions gitea/docker-compose.up.post_hook.sh

This file was deleted.

9 changes: 9 additions & 0 deletions gitea/meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
messages:
up:
post:
- >-
${_bold_}${_CUR_COMP_}${_normal_} may now be accessed on
${_fg_magenta_}${_uline_}https://${SERVER_WAN_FQDN}:${SERVER_WAN_HTTPS_PORT}/${GITEA_BASE_PATH}/${_normal_}
pre_reqs:
- traefik
1 change: 0 additions & 1 deletion gitea/pre.reqs

This file was deleted.

10 changes: 0 additions & 10 deletions hass/docker-compose.up.post_hook.sh

This file was deleted.

9 changes: 9 additions & 0 deletions hass/meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
messages:
up:
post:
- >-
${_bold_}${_CUR_COMP_}${_normal_} may now be accessed on
${_fg_magenta_}${_uline_}https://${SERVER_WAN_FQDN}:${SERVER_WAN_HTTPS_PORT}/${_normal_}
pre_reqs:
- traefik
1 change: 0 additions & 1 deletion hass/pre.reqs

This file was deleted.

10 changes: 0 additions & 10 deletions indexarr/docker-compose.up.post_hook.sh

This file was deleted.

9 changes: 9 additions & 0 deletions indexarr/meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
messages:
up:
post:
- >-
${_bold_}${_CUR_COMP_}${_normal_} may now be accessed on
${_fg_magenta_}${_uline_}https://${SERVER_WAN_FQDN}:${SERVER_WAN_HTTPS_PORT}/${JACKETT_BASE_PATH}/${_normal_}
pre_reqs:
- traefik
1 change: 0 additions & 1 deletion indexarr/pre.reqs

This file was deleted.

10 changes: 0 additions & 10 deletions influxdb/docker-compose.up.post_hook.sh

This file was deleted.

6 changes: 6 additions & 0 deletions influxdb/meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
messages:
up:
post:
- >-
${_bold_}${_CUR_COMP_}${_normal_} may now be accessed on
${_fg_magenta_}${_uline_}https://${SERVER_LAN_FQDN}:8086/${_normal_}
16 changes: 0 additions & 16 deletions monitarr/docker-compose.up.post_hook.sh

This file was deleted.

15 changes: 15 additions & 0 deletions monitarr/meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
messages:
up:
post:
- >-
${_bold_}${_CUR_COMP_}-lidarr${_normal_} may now be accessed on
${_fg_magenta_}${_uline_}https://${SERVER_WAN_FQDN}:${SERVER_WAN_HTTPS_PORT}/${LIDARR_BASE_PATH}/${_normal_}
- >-
${_bold_}${_CUR_COMP_}-radarr${_normal_} may now be accessed on
${_fg_magenta_}${_uline_}https://${SERVER_WAN_FQDN}:${SERVER_WAN_HTTPS_PORT}/${RADARR_BASE_PATH}/${_normal_}
- >-
${_bold_}${_CUR_COMP_}-sonarr${_normal_} may now be accessed on
${_fg_magenta_}${_uline_}https://${SERVER_WAN_FQDN}:${SERVER_WAN_HTTPS_PORT}/${SONARR_BASE_PATH}/${_normal_}
pre_reqs:
- traefik
1 change: 0 additions & 1 deletion monitarr/pre.reqs

This file was deleted.

10 changes: 0 additions & 10 deletions navidrome/docker-compose.up.post_hook.sh

This file was deleted.

9 changes: 9 additions & 0 deletions navidrome/meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
messages:
up:
post:
- >-
${_bold_}${_CUR_COMP_}${_normal_} may now be accessed on
${_fg_magenta_}${_uline_}https://${SERVER_WAN_FQDN}:${SERVER_WAN_HTTPS_PORT}/${NAVIDROME_BASE_PATH}/${_normal_}
pre_reqs:
- traefik
1 change: 0 additions & 1 deletion navidrome/pre.reqs

This file was deleted.

10 changes: 0 additions & 10 deletions nextcloud/docker-compose.up.post_hook.sh

This file was deleted.

9 changes: 9 additions & 0 deletions nextcloud/meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
messages:
up:
post:
- >-
${_bold_}${_CUR_COMP_}${_normal_} may now be accessed on
${_fg_magenta_}${_uline_}https://${SERVER_WAN_FQDN}:${SERVER_WAN_HTTPS_PORT}/${NEXTCLOUD_BASE_PATH}/${_normal_}
pre_reqs:
- traefik
1 change: 0 additions & 1 deletion nextcloud/pre.reqs

This file was deleted.

10 changes: 0 additions & 10 deletions pihole/docker-compose.up.post_hook.sh

This file was deleted.

9 changes: 9 additions & 0 deletions pihole/meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
messages:
up:
post:
- >-
${_bold_}${_CUR_COMP_}${_normal_} may now be accessed on
${_fg_magenta_}${_uline_}https://${SERVER_LAN_FQDN}:${SERVER_LAN_HTTPS_PORT}/${PIHOLE_BASE_PATH}/${_normal_}
pre_reqs:
- traefik
1 change: 0 additions & 1 deletion pihole/pre.reqs

This file was deleted.

10 changes: 0 additions & 10 deletions qbittorrent/docker-compose.up.post_hook.sh

This file was deleted.

9 changes: 9 additions & 0 deletions qbittorrent/meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
messages:
up:
post:
- >-
${_bold_}${_CUR_COMP_}${_normal_} may now be accessed on
${_fg_magenta_}${_uline_}https://${SERVER_WAN_FQDN}:${SERVER_WAN_HTTPS_PORT}/${QBITTORRENT_BASE_PATH}/${_normal_}
pre_reqs:
- traefik
1 change: 0 additions & 1 deletion qbittorrent/pre.reqs

This file was deleted.

9 changes: 9 additions & 0 deletions tang/meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
messages:
up:
post:
- >-
${_bold_}${_CUR_COMP_}${_normal_} is now listening on
${_fg_magenta_}${_uline_}https://${SERVER_LAN_FQDN}:${SERVER_LAN_HTTP_PORT}/${_normal_}
pre_reqs:
- traefik
1 change: 0 additions & 1 deletion tang/pre.reqs

This file was deleted.

2 changes: 2 additions & 0 deletions telegraf/meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pre_reqs:
- docker_sock
1 change: 0 additions & 1 deletion telegraf/pre.reqs

This file was deleted.

10 changes: 0 additions & 10 deletions teslamate/docker-compose.up.post_hook.sh

This file was deleted.

9 changes: 9 additions & 0 deletions teslamate/meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
messages:
up:
post:
- >-
${_bold_}${_CUR_COMP_}${_normal_} may now be accessed on
${_fg_magenta_}${_uline_}https://${SERVER_LAN_FQDN}:${SERVER_LAN_HTTPS_PORT}/${TESLAMATE_BASE_PATH}/${_normal_}
pre_reqs:
- traefik
1 change: 0 additions & 1 deletion teslamate/pre.reqs

This file was deleted.

Loading

0 comments on commit d7e34c8

Please sign in to comment.