-
-
Notifications
You must be signed in to change notification settings - Fork 258
/
Copy pathyml_merge.sh
72 lines (70 loc) · 3.78 KB
/
yml_merge.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env bash
set -Eeuo pipefail
IFS=$'\n\t'
yml_merge() {
run_script 'appvars_create_all'
run_script 'env_update'
local COMPOSE_FILE=""
notice "Adding enabled app templates to merge docker-compose.yml. Please be patient, this can take a while."
while IFS= read -r line; do
local APPNAME=${line%%_ENABLED=*}
local FILENAME=${APPNAME,,}
local APPTEMPLATES="${SCRIPTPATH}/compose/.apps/${FILENAME}"
if [[ -d ${APPTEMPLATES}/ ]]; then
if [[ -f ${APPTEMPLATES}/${FILENAME}.yml ]]; then
local APPDEPRECATED
APPDEPRECATED=$(grep --color=never -Po "\scom\.dockstarter\.appinfo\.deprecated: \K.*" "${APPTEMPLATES}/${FILENAME}.labels.yml" | sed -E 's/^([^"].*[^"])$/"\1"/' | xargs || echo false)
if [[ ${APPDEPRECATED} == true ]]; then
warn "${APPNAME} IS DEPRECATED!"
warn "Please edit ${COMPOSE_ENV} and set ${APPNAME}_ENABLED to false."
continue
fi
if [[ ! -f ${APPTEMPLATES}/${FILENAME}.${ARCH}.yml ]]; then
error "${APPTEMPLATES}/${FILENAME}.${ARCH}.yml does not exist."
continue
fi
COMPOSE_FILE="${COMPOSE_FILE}:${APPTEMPLATES}/${FILENAME}.${ARCH}.yml"
local APPNETMODE
APPNETMODE=$(run_script 'env_get' "${APPNAME}_NETWORK_MODE")
if [[ -z ${APPNETMODE} ]] || [[ ${APPNETMODE} == "bridge" ]]; then
if [[ -f ${APPTEMPLATES}/${FILENAME}.hostname.yml ]]; then
COMPOSE_FILE="${COMPOSE_FILE}:${APPTEMPLATES}/${FILENAME}.hostname.yml"
else
info "${APPTEMPLATES}/${FILENAME}.hostname.yml does not exist."
fi
if [[ -f ${APPTEMPLATES}/${FILENAME}.ports.yml ]]; then
COMPOSE_FILE="${COMPOSE_FILE}:${APPTEMPLATES}/${FILENAME}.ports.yml"
else
info "${APPTEMPLATES}/${FILENAME}.ports.yml does not exist."
fi
elif [[ -n ${APPNETMODE} ]]; then
if [[ -f ${APPTEMPLATES}/${FILENAME}.netmode.yml ]]; then
COMPOSE_FILE="${COMPOSE_FILE}:${APPTEMPLATES}/${FILENAME}.netmode.yml"
else
info "${APPTEMPLATES}/${FILENAME}.netmode.yml does not exist."
fi
fi
COMPOSE_FILE="${COMPOSE_FILE}:${APPTEMPLATES}/${FILENAME}.yml"
info "All configurations for ${APPNAME} are included."
else
warn "${APPTEMPLATES}/${FILENAME}.yml does not exist."
fi
else
error "${APPTEMPLATES}/ does not exist."
fi
done < <(grep --color=never -P '_ENABLED='"'"'?true'"'"'?$' "${COMPOSE_ENV}")
if [[ -z ${COMPOSE_FILE} ]]; then
fatal "No enabled apps found."
fi
info "Running compose config to create docker-compose.yml file from enabled templates."
export COMPOSE_FILE="${COMPOSE_FILE#:}"
eval "docker compose --project-directory ${SCRIPTPATH}/compose/ config > ${SCRIPTPATH}/compose/docker-compose.yml" || fatal "Failed to output compose config.\nFailing command: ${F[C]}docker compose --project-directory ${SCRIPTPATH}/compose/ config > \"${SCRIPTPATH}/compose/docker-compose.yml\""
info "Merging docker-compose.yml complete."
}
test_yml_merge() {
run_script 'appvars_create' WATCHTOWER
cat "${COMPOSE_ENV}"
run_script 'yml_merge'
eval "docker compose --project-directory ${SCRIPTPATH}/compose/ config" || fatal "Failed to display compose config.\nFailing command: ${F[C]}docker compose --project-directory ${SCRIPTPATH}/compose/ config"
run_script 'appvars_purge' WATCHTOWER
}