From 5d97d36168eff331dda0e4a37d194b4d7f72e05e Mon Sep 17 00:00:00 2001 From: eshanized Date: Thu, 2 Jan 2025 04:23:47 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20verify=20docker=20image?= =?UTF-8?q?=20first?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/snigdhaos-docker.yml | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/.github/workflows/snigdhaos-docker.yml b/.github/workflows/snigdhaos-docker.yml index 222e48b..e0ddd3f 100644 --- a/.github/workflows/snigdhaos-docker.yml +++ b/.github/workflows/snigdhaos-docker.yml @@ -17,7 +17,7 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - # Set up QEMU for multi-architecture builds (optional, now removed arm64) + # Set up QEMU for multi-architecture builds - name: Set up QEMU uses: docker/setup-qemu-action@v3 @@ -43,6 +43,7 @@ jobs: # Build and push Docker image (only for amd64 platform now) - name: Build and push Docker image + id: build uses: docker/build-push-action@v4 with: context: ./snigdhaos # Ensure the Dockerfile is inside the snigdhaos directory @@ -52,8 +53,9 @@ jobs: cache-to: type=inline # Use inline caching cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/snigdhaos:latest # Use cached layers from Docker Hub - # Tag Docker image with version based on the latest Git tag + # Check if build succeeded and tag Docker image with version based on the latest Git tag - name: Tag Docker image with version + if: success() # Only proceed if the build was successful run: | VERSION=$(git tag -l | tail -n 1 || echo "latest") # Get the latest tag or fallback to "latest" @@ -62,6 +64,12 @@ jobs: VERSION="latest" fi - # Tag and push the image - docker tag ${{ secrets.DOCKERHUB_USERNAME }}/snigdhaos:latest ${{ secrets.DOCKERHUB_USERNAME }}/snigdhaos:${VERSION} - docker push ${{ secrets.DOCKERHUB_USERNAME }}/snigdhaos:${VERSION} + # Verify if the image exists before tagging + if docker image inspect ${{ secrets.DOCKERHUB_USERNAME }}/snigdhaos:latest > /dev/null 2>&1; then + echo "Image exists, tagging with version: $VERSION" + docker tag ${{ secrets.DOCKERHUB_USERNAME }}/snigdhaos:latest ${{ secrets.DOCKERHUB_USERNAME }}/snigdhaos:${VERSION} + docker push ${{ secrets.DOCKERHUB_USERNAME }}/snigdhaos:${VERSION} + else + echo "Docker image not found, skipping tag and push." + exit 1 # Fail the step if the image does not exist + fi