-
-
Notifications
You must be signed in to change notification settings - Fork 239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add "APPNAME" headings in .env
, and move the "migrate" logic into appvars_create.sh
#1745
Changes from 84 commits
5f1c61a
e1f00bd
3c00400
d1461ef
441f44f
23bd9d0
dd8ef14
cbe5f50
b6dd9be
b3f5040
a28cf7d
7a74e65
c01426f
11a8ff2
134523f
796454e
182482b
11a5a96
9fd4329
3e408a2
ba51d08
c874d6e
d116c0a
5b4fd33
d2bb34b
c40f2ee
4a085c6
7abd76c
b90e022
c2e9d99
0925f3f
461d790
355e1e0
39d8efe
cbc8a95
500b717
92d63f6
f1bce7b
1093733
ef25335
72181cb
2ee2341
7f5886e
0d8ad5a
b63b341
03f57f3
f1c751f
8194fb0
1122bf2
3597d8b
550d94c
c56a512
5fd7ebf
ab090cd
a2954cd
fc178bc
33f197a
6131664
848557b
a39075c
1ffa8a9
b826348
9fe89aa
7225c85
e6f127d
8ee043d
78e9172
d35c014
e76aeb5
f65195b
2bfd750
9ccb749
fa46e23
56722f2
1bdc295
d48aaf4
f1596f9
842b0a0
df4425e
69fb677
c7cc4d8
4294686
a3b6087
b2f39cc
a2f30b5
6d7ac6c
1dbc966
1db554c
58d92b9
fe31c67
cb8b984
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,26 +5,78 @@ IFS=$'\n\t' | |
appvars_create() { | ||
local APPNAME=${1-} | ||
APPNAME=${APPNAME^^} | ||
local APPSFOLDER="${SCRIPTPATH}/compose/.apps" | ||
local FILENAME=${APPNAME,,} | ||
local APPTEMPLATES="${SCRIPTPATH}/compose/.apps/${FILENAME}" | ||
local APPTEMPLATES="${APPSFOLDER}/${FILENAME}" | ||
local APPLABELFILE="${APPTEMPLATES}/${FILENAME}.labels.yml" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same with this one; it's set once and used once. It may as well not be a variable. |
||
|
||
local -A APP_VAR_VALUE | ||
local -A APP_VAR_MIGRATE | ||
|
||
# Build variable values lookup array, APP_VAR_VALUES["variable"]="default value" | ||
{ | ||
# Read all lines with labels into temporary APP_LABEL_LINES array | ||
local -a APP_LABEL_LINES | ||
readarray -t APP_LABEL_LINES < <(grep --color=never -P "\scom\.dockstarter\.appvars\.\K[\w]+" "${APPLABELFILE}" || true) | ||
if [[ -z ${APP_LABEL_LINES[*]} ]]; then | ||
error "Unable to find labels for ${APPNAME}" | ||
return | ||
fi | ||
|
||
for line in "${APP_LABEL_LINES[@]}"; do | ||
CLHatch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
local SET_VAR | ||
local SET_VAL | ||
SET_VAR=$(echo "$line" | grep --color=never -Po "\scom\.dockstarter\.appvars\.\K[\w]+") | ||
SET_VAL=$(echo "$line" | grep --color=never -Po "\scom\.dockstarter\.appvars\.${SET_VAR}: \K.*" | sed -E 's/^([^"].*[^"])$/"\1"/' | xargs || true) | ||
if [[ -n ${SET_VAR} ]]; then | ||
APP_VAR_VALUE["${SET_VAR^^}"]=${SET_VAL} | ||
fi | ||
done | ||
} | ||
|
||
# Build migrate variable lookup array, APP_MIGRATE_VAR["variable"]="migrate from variable" | ||
for SET_VAR in "${!APP_VAR_VALUE[@]}"; do | ||
local APPNAME=${SET_VAR%%_*} | ||
local REST_VAR=${SET_VAR#"${APPNAME}_"} | ||
local VAR_TYPE=${REST_VAR%%_*} | ||
case "${VAR_TYPE}" in | ||
ENVIRONMENT | VOLUME) | ||
REST_VAR=${REST_VAR#"${VAR_TYPE}"} | ||
local MIGRATE_VAR="${APPNAME}${REST_VAR}" | ||
# shellcheck disable=SC2199 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we find a way to write the line below that doesn't require disabling shellcheck here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There some weirdness going on here that the recommended usage of |
||
if [[ " ${!APP_VAR_VALUE[@]} " != *" ${MIGRATE_VAR} "* ]]; then | ||
# Potential "migrate from" variable isn't an existing app variable, add it to the migrate list | ||
APP_VAR_MIGRATE["${SET_VAR}"]=${MIGRATE_VAR} | ||
fi | ||
;; | ||
esac | ||
done | ||
#debug "appvars_create.sh: ${APP_VAR_MIGRATE[*]@A}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we're not going to ship this uncommented, it can be removed. |
||
|
||
# Actual processing starts here | ||
info "Creating environment variables for ${APPNAME}." | ||
while IFS= read -r line; do | ||
local VAR_LABEL=${line} | ||
local SET_VAR=${VAR_LABEL^^} | ||
if grep -q -P "^${SET_VAR}=" "${COMPOSE_ENV}"; then | ||
for SET_VAR in "${!APP_VAR_VALUE[@]}"; do | ||
if grep -q -P "^\s*${SET_VAR}\s*=" "${COMPOSE_ENV}"; then | ||
# Variable already exists | ||
continue | ||
fi | ||
|
||
local DEFAULT_VAL | ||
DEFAULT_VAL=$(grep --color=never -Po "\scom\.dockstarter\.appvars\.${VAR_LABEL}: \K.*" "${APPTEMPLATES}/${FILENAME}.labels.yml" | sed -E 's/^([^"].*[^"])$/"\1"/' | xargs || true) | ||
echo "${SET_VAR}=" >> "${COMPOSE_ENV}" | ||
run_script 'env_set' "${SET_VAR}" "${DEFAULT_VAL}" | ||
done < <(grep --color=never -Po "\scom\.dockstarter\.appvars\.\K[\w]+" "${APPTEMPLATES}/${FILENAME}.labels.yml" || error "Unable to find labels for ${APPNAME}") | ||
local MIGRATE_VAR=${APP_VAR_MIGRATE["${SET_VAR}"]-} | ||
if [[ -n ${MIGRATE_VAR} ]] && grep -q -P "^\s*${MIGRATE_VAR}\s*=" "${COMPOSE_ENV}"; then | ||
# Migrate old variable | ||
run_script 'env_rename' "${MIGRATE_VAR}" "${SET_VAR}" | ||
else | ||
# Add new variable | ||
local DEFAULT_VAL=${APP_VAR_VALUE["${SET_VAR}"]} | ||
notice "Adding ${SET_VAR}='${DEFAULT_VAL}' in ${COMPOSE_ENV} file." | ||
run_script 'env_set' "${SET_VAR}" "${DEFAULT_VAL}" | ||
fi | ||
done | ||
run_script 'env_set' "${APPNAME}_ENABLED" true | ||
} | ||
|
||
test_appvars_create() { | ||
run_script 'env_update' | ||
run_script 'appvars_create' WATCHTOWER | ||
run_script 'env_update' | ||
cat "${COMPOSE_ENV}" | ||
} |
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was
APPSFOLDER
used for something else at one point while iterating through changes? It looks like currently it's only set once and used once. Could just keep the original here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forget if it was used elsewhere at some point or not. Possibly I made it a variable in case I did re-use it? I can easily remove the variable.