From 884a64ac6e39b1d680d643b86dda921262aecf14 Mon Sep 17 00:00:00 2001 From: Puskar Basu <45908484+pskrbasu@users.noreply.github.com> Date: Thu, 7 Mar 2024 18:22:37 +0530 Subject: [PATCH] Fix docker publish workflow to only set the `latest` tag for final releases (#254) --- .github/workflows/03-powerpipe-container.yaml | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/.github/workflows/03-powerpipe-container.yaml b/.github/workflows/03-powerpipe-container.yaml index 2c887469..52733f40 100644 --- a/.github/workflows/03-powerpipe-container.yaml +++ b/.github/workflows/03-powerpipe-container.yaml @@ -14,10 +14,30 @@ env: # Defines the build and release job. jobs: + check_pre_release: + name: Check if pre-release + runs-on: ubuntu-latest + outputs: + is_pre_release: ${{ steps.pre_release_check.outputs.is_pre_release }} + steps: + - name: Check if pre-release + id: pre_release_check + run: | + if [[ "${{ github.event.inputs.version }}" =~ -alpha|-beta|-rc|-dev ]]; then + echo "is_pre_release=true" >> $GITHUB_OUTPUT + echo "This is a pre-release. The 'latest' tag will not be updated." + else + echo "is_pre_release=false" >> $GITHUB_OUTPUT + echo "This is a final release. The 'latest' tag will be set." + fi + build_and_release: name: Build and Release + needs: check_pre_release # The type of runner that the job will run on. runs-on: ubuntu-latest + # check if it's a final release + if: needs.check_pre_release.outputs.is_pre_release == 'false' steps: # Checks out the Powerpipe repository code. - name: Checkout Powerpipe repository @@ -67,3 +87,59 @@ jobs: # Outputs the image digest after the build. - name: Image digest run: echo ${{ steps.docker_build.outputs.digest }} + + build_and_release_pre_release: + name: Build and Release (For Pre-releases) + needs: check_pre_release + # The type of runner that the job will run on. + runs-on: ubuntu-latest + # check if it's a pre-release + if: needs.check_pre_release.outputs.is_pre_release == 'true' + steps: + # Checks out the Powerpipe repository code. + - name: Checkout Powerpipe repository + uses: actions/checkout@v4 + with: + path: powerpipe # Directory path under $GITHUB_WORKSPACE to place the repository. + + # Sets up QEMU for multi-architecture builds, allowing builds for architectures like ARM and AMD64. + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + # Sets up Docker Buildx for extended Docker build capabilities, including building multi-arch images. + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + # Logs in to the GitHub Container Registry to allow pushing and pulling images. + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GH_ACCESS_TOKEN }} + + # Remove the 'v' from the version to get the docker tag + - name: Clean Version for Tag + id: generate_docker_tag + run: | + echo "docker_tag=${POWERPIPE_VERSION#"v"}" >> $GITHUB_OUTPUT + + # Builds the Docker image and pushes it to the GitHub Container Registry. + - name: Build and Push to Container Registry + id: docker_build + uses: docker/build-push-action@v5 + with: + # The Docker build context. + context: powerpipe/docker/ + push: true + platforms: linux/amd64, linux/arm64 + build-args: | + TARGETVERSION=${{ github.event.inputs.version }} + tags: | + ghcr.io/${{ github.repository_owner }}/powerpipe:${{ steps.generate_docker_tag.outputs.docker_tag }} + outputs: type=image,name=powerpipe,annotation-index.org.opencontainers.image.description=${{ env.IMAGE_DESCRIPTION }} + + + # Outputs the image digest after the build. + - name: Image digest + run: echo ${{ steps.docker_build.outputs.digest }} \ No newline at end of file