From 4e99b866d2ce6d3ef54ee4798afba6061448c293 Mon Sep 17 00:00:00 2001 From: lladdy Date: Tue, 19 Nov 2024 17:42:50 +1030 Subject: [PATCH] ci: refine docker image build / push step and error handling --- .github/workflows/release.yml | 57 ++++++++++++++++++++--------------- docker/docker-compose.yml | 8 ++--- 2 files changed, 34 insertions(+), 31 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7f10cb7..e4b65b9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -38,30 +38,37 @@ jobs: timeout-minutes: 90 steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v4 - - name: Login to DockerHub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Build and push bot image - if: needs.validate_tag.outputs.type == 'bot' - run: | - # Set version for docker-compose - export BOT_VERSION=${{ needs.validate_tag.outputs.version }} - - echo "Building and pushing bot image version ${BOT_VERSION}" - docker compose -f docker/docker-compose.yml build bot - docker compose -f docker/docker-compose.yml push bot + - name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push bot image + run: | + export IMAGE_TYPE=${{ needs.validate_tag.outputs.type }} + export VERSION=${{ needs.validate_tag.outputs.version }} # Used in the docker-compose.yml file + + echo "Building and pushing ${IMAGE_TYPE} image version ${VERSION}" + + # Build and push the image + docker compose -f docker/docker-compose.yml build ${IMAGE_TYPE} || { + echo "Error: Docker build failed" + exit 1 + } + + docker compose -f docker/docker-compose.yml push ${IMAGE_TYPE} || { + echo "Error: Docker push failed" + exit 1 + } + + # Verify the push was successful + docker pull aiarena/arenaclient-${IMAGE_TYPE}-base:${VERSION} || { + echo "Error: Unable to verify pushed image" + exit 1 + } + + echo "Successfully built and pushed ${IMAGE_TYPE} image version ${VERSION}" - - name: Build and push sc2 image - if: needs.validate_tag.outputs.type == 'sc2' - run: | - # Set version for docker-compose - export SC2_VERSION=${{ needs.validate_tag.outputs.version }} - - echo "Building and pushing sc2 image version ${SC2_VERSION}" - docker compose -f docker/docker-compose.yml build sc2 - docker compose -f docker/docker-compose.yml push sc2 diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 4dd4aba..edd6663 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -2,18 +2,14 @@ version: "3.9" services: sc2: restart: unless-stopped - image: aiarena/arenaclient-sc2-base:${SC2_VERSION:-latest} + image: aiarena/arenaclient-sc2-base:${VERSION:-latest} build: context: ../ dockerfile: ./docker/Dockerfile.sc2 - args: - SC2_VERSION: "${SC2_VERSION}" bot: restart: unless-stopped - image: aiarena/arenaclient-bot-base:${BOT_VERSION:-latest} + image: aiarena/arenaclient-bot-base:${VERSION:-latest} build: context: ../ dockerfile: ./docker/Dockerfile.bot - args: - PYTHON_VERSION: "${PYTHON_VERSION}"