From d10b55087821b73471e68cdd551db127c4b73c98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20=C3=81lvaro?= Date: Sun, 12 May 2024 18:50:33 +0200 Subject: [PATCH] feat: Add podman support --- compose-check.sh | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/compose-check.sh b/compose-check.sh index 756f495..a57b647 100755 --- a/compose-check.sh +++ b/compose-check.sh @@ -2,28 +2,40 @@ # Verifies that files passed in are valid for docker-compose set -e -if command -v docker &> /dev/null && docker help compose &> /dev/null; then - COMPOSE="docker compose" -elif command -v docker-compose &> /dev/null ; then - COMPOSE=docker-compose +# Check if docker or podman commands are available +if [[ -z "${CONTAINER_ENGINE}" ]]; then + if command -v docker &>/dev/null; then + CONTAINER_ENGINE=docker + elif command -v podman &>/dev/null; then + CONTAINER_ENGINE=podman + else + echo "ERROR: Neither 'docker' or 'podman' were found" + exit 1 + fi +fi + +if command -v "${CONTAINER_ENGINE}" &>/dev/null && ${CONTAINER_ENGINE} help compose &> /dev/null; then + COMPOSE="${CONTAINER_ENGINE} compose" +elif command -v "${CONTAINER_ENGINE}-compose" &> /dev/null; then + COMPOSE="${CONTAINER_ENGINE}-compose" else - echo "ERROR: Neither 'docker-compose' or 'docker compose' were found" + echo "ERROR: Neither '${CONTAINER_ENGINE}-compose' or '${CONTAINER_ENGINE} compose' were found" exit 1 fi check_file() { local file=$1 - env $COMPOSE --file "$file" config --quiet 2>&1 \ - | sed "/variable is not set. Defaulting/d" + env $COMPOSE --file "$file" config --quiet 2>&1 | + sed "/variable is not set. Defaulting/d" return "${PIPESTATUS[0]}" } check_files() { local all_files=( "$@" ) has_error=0 - for file in "${all_files[@]}" ; do + for file in "${all_files[@]}"; do if [[ -f "$file" ]]; then - if ! check_file "$file" ; then + if ! check_file "$file"; then echo "ERROR: $file" has_error=1 fi @@ -32,7 +44,7 @@ check_files() { return $has_error } -if ! check_files "$@" ; then +if ! check_files "$@"; then echo "Some compose files failed" fi