Skip to content
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

decrease optional var logging level and allow to pass extra opts to pavics-compose.sh up -d #426

Merged
merged 11 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,32 @@
[Unreleased](https://github.com/bird-house/birdhouse-deploy/tree/master) (latest)
------------------------------------------------------------------------------------------------------------------

[//]: # (list changes here, using '-' for each new entry, remove this when items are added)
## Changes

- logging: decrease logging level for empty optional vars from WARN to DEBUG

To avoid drowning real WARN messages. Many optional vars can be valid if empty.

- config: add sample config to configure docker-compose to remove orphans

To remove orphans containers when components are disabled. Also link to full
documentations if other env var can be used.

- compose script: allow to pass extra options to `up` operation

The previous docker-compose built-in env var was not working so had to add
this homegrown solution.

When disabling components, their existing containers will not be removed
unless option `--remove-orphans` is given together with `./pavics-compose.sh up -d`.

This change allow any additional options, not just `--remove-orphans`.

- compose script: exit early when any errors occurred during invocation

Before, all the `post-docker-compose-up` would still execute after
`docker-compose` has an error.


[2.1.0](https://github.com/bird-house/birdhouse-deploy/tree/2.1.0) (2024-02-23)
------------------------------------------------------------------------------------------------------------------
Expand Down
17 changes: 17 additions & 0 deletions birdhouse/env.local.example
Original file line number Diff line number Diff line change
Expand Up @@ -593,3 +593,20 @@ export CATALOG_PASSWORD="${__DEFAULT__CATALOG_PASSWORD}"
export CATALOG_THREDDS_SERVICE="thredds"
export PHOENIX_PASSWORD="${__DEFAULT__PHOENIX_PASSWORD}"
export PHOENIX_PASSWORD_HASH="${__DEFAULT__PHOENIX_PASSWORD_HASH}"

#############################################################################
# Compose vars
# https://docs.docker.com/compose/environment-variables/envvars/
# https://docs.docker.com/compose/environment-variables/envvars-precedence/
# https://docs.docker.com/engine/reference/commandline/cli/#environment-variables
#############################################################################

# Remove orphans containers, useful when disabling components.
# Harmless when left enabled all the time.
# Not working at the time of this writing, see https://github.com/docker/compose/issues/11374.
# Use COMPOSE_UP_EXTRA_OPTS below as a work-around.
#export COMPOSE_REMOVE_ORPHANS=true

# Extra options for 'pavics-compose.sh up'.
# --remove-orphans useful when disabling components. Harmless when left enabled all the time.
#export COMPOSE_UP_EXTRA_OPTS="--remove-orphans"
10 changes: 9 additions & 1 deletion birdhouse/pavics-compose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ if [ x"$1" = x"info" ]; then
exit 0
fi

COMPOSE_EXTRA_OPTS=""

if [ x"$1" = x"up" ]; then
COMPOSE_EXTRA_OPTS="${COMPOSE_UP_EXTRA_OPTS}"
for adir in $ALL_CONF_DIRS; do
COMPONENT_PRE_COMPOSE_UP="$adir/pre-docker-compose-up"
if [ -x "$COMPONENT_PRE_COMPOSE_UP" ]; then
Expand All @@ -115,9 +118,14 @@ if [ x"$1" = x"up" ]; then
done
fi

log INFO "Executing docker-compose with extra options: $* ${COMPOSE_EXTRA_OPTS}"
# the PROXY_SECURE_PORT is a little trick to make the compose file invalid without the usage of this wrapper script
PROXY_SECURE_PORT=443 HOSTNAME=${PAVICS_FQDN} docker-compose ${COMPOSE_CONF_LIST} $*
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be some kind of duplicate filtering, or we simply let the command fail with any (possibility ambiguous) error message?
For example, COMPOSE_EXTRA_OPTS="-d" and the user does pavics-compose up -d by mistake.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, yes double -d do not work ! Weird ! Which reason would motivate such a strict cli args parsing !

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Often CLI libraries support duplicating flags to increase some level. For example, -v means verbose level 1 and -v -v means verbose level 2.
Differentiating between options that support this duplication and those that don't are important to these argument parsing libraries.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right ! But activating this "strict count" for all options seems excessive !

PROXY_SECURE_PORT=443 HOSTNAME=${PAVICS_FQDN} docker-compose ${COMPOSE_CONF_LIST} $* ${COMPOSE_EXTRA_OPTS}
ERR=$?
if [ ${ERR} -gt 0 ]; then
log ERROR "docker-compose error, exit code ${ERR}"
exit ${ERR}
fi

# execute post-compose function if exists and no error occurred
type post-compose 2>&1 | grep 'post-compose is a function' > /dev/null
Expand Down
2 changes: 1 addition & 1 deletion birdhouse/read-configs.include.sh
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ check_default_vars() {
result=`echo "${d}" | grep -c "${default}"`
if [ -z "`eval "echo ${v}"`" ]
then
log WARN "Optional variable [${n}] is not set. Check env.local file."
log DEBUG "Optional variable [${n}] is not set. Check env.local file."
fi
if [ "${result}" -gt 0 ]
then
Expand Down
Loading