From 0b2254336c180963bc7f55460176e569214c7c98 Mon Sep 17 00:00:00 2001 From: Shihaam Abdul Rahman Date: Fri, 6 Oct 2023 01:17:47 +0500 Subject: [PATCH] added support to build --- container-compose | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/container-compose b/container-compose index ba5437f..c827b51 100755 --- a/container-compose +++ b/container-compose @@ -3,6 +3,10 @@ check_file() { file="" engine="" + pull="false" + push="false" + build="false" + local opt local OPTARG local OPTIND=1 @@ -14,6 +18,18 @@ check_file() { engine="${arg#*=}" shift # Remove --engine= from positional parameters ;; + build) + build=true + shift # Remove build from positional parameters + ;; + push) + push=push + shift # Remove build from positional parameters + ;; + pull) + pull=true + shift # Remove build from positional parameters + ;; esac done @@ -107,3 +123,37 @@ for service in $services; do echo "Dockerfile: $dockerfile" echo "---------------------" done + + +build(){ + services=$(yq e '.services | keys | .[]' "$file") + for service in $services; do + + platform=$(yq e ".services.$service.platform" "$file") + image=$(yq e ".services.$service.image" "$file") + context=$(yq e ".services.$service.build.context" "$file") + dockerfile=$(yq e ".services.$service.build.dockerfile" "$file") + # Replace '/' and ':' with '-' in the platform string to make it suitable for a tag + platform_tag=$(echo "$platform" | tr '/:' '-') + # Append platform information to the image tag + new_image_tag="${image}-${platform_tag}" + + $engine buildx build --platform $platform -t $new_image_tag -f $context/$dockerfile $context + done +} +#push(){ +#} + +pull(){ + services=$(yq e '.services | keys | .[]' "$file") + for service in $services; do + $engine pull $(yq e ".services.$service.image" "$file") + done +} + +# If pull argument is provided, then pull +if [ "$pull" = true ]; then + pull +elif [ "$build" = true ]; then + build +fi