diff --git a/build_and_push_ghcr.sh b/build_and_push_ghcr.sh index 62ddd69..30e6e4a 100644 --- a/build_and_push_ghcr.sh +++ b/build_and_push_ghcr.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +# filepath: e:\infoalloggi-monorepo\build_and_push_ghcr.sh set -euo pipefail # Build and push multiple Docker images to a registry (GHCR or self-hosted) @@ -36,6 +37,18 @@ else echo "No credentials provided; assuming you're already logged into ${IMAGE_REGISTRY} or using a credential helper." fi +# Get last git commit info (once for all images) +GIT_COMMIT_ID=$(git rev-parse --short HEAD) +GIT_COMMIT_MSG=$(git log -1 --pretty=%B | tr -d '\n') +DESCRIPTION="Commit: ${GIT_COMMIT_ID} - ${GIT_COMMIT_MSG}" + +# Array to store built images +declare -a BUILT_IMAGES=() + +echo "================================" +echo "PHASE 1: Building all images" +echo "================================" + for svc in ${SERVICES}; do case "${svc}" in db) @@ -56,17 +69,40 @@ for svc in ${SERVICES}; do ;; esac - # Get last git commit info - GIT_COMMIT_ID=$(git rev-parse --short HEAD) - GIT_COMMIT_MSG=$(git log -1 --pretty=%B | tr -d '\n') - DESCRIPTION="Commit: ${GIT_COMMIT_ID} - ${GIT_COMMIT_MSG}" - IMAGE="${IMAGE_REGISTRY}/${OWNER}/${PREFIX}-${svc}:${TAG}" + echo "" echo "Building ${PREFIX}-${svc} -> ${IMAGE} (context: ${ctx})" - docker build --build-arg ENV_FILE="${ENV_FILE}" -t "${IMAGE}" --label "org.opencontainers.image.description=${DESCRIPTION}" -f "$ctx/$dockerfile" "$ctx" - - echo "Pushing ${IMAGE}" - docker push "${IMAGE}" + + docker build \ + --build-arg ENV_FILE="${ENV_FILE}" \ + -t "${IMAGE}" \ + --label "org.opencontainers.image.description=${DESCRIPTION}" \ + -f "$ctx/$dockerfile" \ + "$ctx" + + # Store the image name for later pushing + BUILT_IMAGES+=("${IMAGE}") + echo "✓ Built ${IMAGE}" done -echo "All done. Built and pushed services: ${SERVICES} with tag ${TAG} to ${IMAGE_REGISTRY}/${OWNER}/${PREFIX}-:${TAG}" +echo "" +echo "================================" +echo "PHASE 2: Pushing all images" +echo "================================" + +for IMAGE in "${BUILT_IMAGES[@]}"; do + echo "" + echo "Pushing ${IMAGE}" + docker push "${IMAGE}" + echo "✓ Pushed ${IMAGE}" +done + +echo "" +echo "================================" +echo "All done!" +echo "Built and pushed ${#BUILT_IMAGES[@]} images with tag ${TAG}" +echo "Images:" +for IMAGE in "${BUILT_IMAGES[@]}"; do + echo " - ${IMAGE}" +done +echo "================================" \ No newline at end of file