Merge pull request #29 from samply/feature/robustcompose

Support docker compose as well as docker-compose
This commit is contained in:
Martin Lablans 2022-10-28 13:07:03 +02:00 committed by GitHub
commit 79fc157ad4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 3 deletions

View File

@ -58,15 +58,17 @@ if [ -f "$PROJECT/docker-compose.override.yml" ]; then
OVERRIDE+=" -f ./$PROJECT/docker-compose.override.yml" OVERRIDE+=" -f ./$PROJECT/docker-compose.override.yml"
fi fi
detectCompose
case "$ACTION" in case "$ACTION" in
start) start)
hc_send log "Bridgehead $PROJECT startup: Checking requirements ..." hc_send log "Bridgehead $PROJECT startup: Checking requirements ..."
checkRequirements checkRequirements
hc_send log "Bridgehead $PROJECT startup: Requirements checked out. Now starting bridgehead ..." hc_send log "Bridgehead $PROJECT startup: Requirements checked out. Now starting bridgehead ..."
exec docker-compose -f ./$PROJECT/docker-compose.yml $OVERRIDE up --abort-on-container-exit exec $COMPOSE -f ./$PROJECT/docker-compose.yml $OVERRIDE up --abort-on-container-exit
;; ;;
stop) stop)
exec docker-compose -f ./$PROJECT/docker-compose.yml $OVERRIDE down exec $COMPOSE -f ./$PROJECT/docker-compose.yml $OVERRIDE down
;; ;;
update) update)
exec ./lib/update-bridgehead.sh $PROJECT exec ./lib/update-bridgehead.sh $PROJECT

View File

@ -2,6 +2,15 @@
source lib/log.sh source lib/log.sh
detectCompose() {
if [[ "$(docker compose version 2>/dev/null)" == *"Docker Compose version"* ]]; then
COMPOSE="docker compose"
else
COMPOSE="docker-compose"
# This is intended to fail on startup in the next prereq check.
fi
}
exitIfNotRoot() { exitIfNotRoot() {
if [ "$EUID" -ne 0 ]; then if [ "$EUID" -ne 0 ]; then
log "ERROR" "Please run as root" log "ERROR" "Please run as root"

View File

@ -2,6 +2,8 @@
source lib/functions.sh source lib/functions.sh
detectCompose
if ! id "bridgehead" &>/dev/null; then if ! id "bridgehead" &>/dev/null; then
log ERROR "User bridgehead does not exist. Please consult readme for installation." log ERROR "User bridgehead does not exist. Please consult readme for installation."
exit 1 exit 1
@ -12,7 +14,7 @@ checkOwner /etc/bridgehead bridgehead || exit 1
## Check if user is a su ## Check if user is a su
log INFO "Checking if all prerequisites are met ..." log INFO "Checking if all prerequisites are met ..."
prerequisites="git docker docker-compose" prerequisites="git docker $COMPOSE"
for prerequisite in $prerequisites; do for prerequisite in $prerequisites; do
$prerequisite --version 2>&1 $prerequisite --version 2>&1
is_available=$? is_available=$?