Build and Push Image #9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and Push Image | |
| on: | |
| pull_request: | |
| branches: [ main ] | |
| push: | |
| tags: | |
| - '*' | |
| branches: | |
| - main | |
| paths-ignore: | |
| - '**.md' | |
| workflow_dispatch: | |
| schedule: | |
| - cron: "0 0 * * *" # every day at midnight | |
| env: | |
| IMAGE_REGISTRY: quay.io | |
| jobs: | |
| build-and-push: | |
| name: Build and push must-gather image to Quay.io | |
| runs-on: ubuntu-latest | |
| steps: | |
| # Checkout must-gather github repository | |
| - name: Checkout must-gather repo | |
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
| - name: Prepare | |
| id: prep | |
| run: | | |
| DOCKER_IMAGE=${{ env.IMAGE_REGISTRY }}/${{ secrets.QUAY_REGISTRY_USERNAME }}/dev-spaces-must-gather | |
| SHORTREF=${GITHUB_SHA::8} | |
| LATEST_TAG=",${DOCKER_IMAGE}:latest" | |
| # If this is git tag, use the tag name as a docker tag | |
| if [[ $GITHUB_REF == refs/tags/* ]]; then | |
| VERSION=${GITHUB_REF#refs/tags/} | |
| TAGS="${DOCKER_IMAGE}:${VERSION},${DOCKER_IMAGE}:${SHORTREF}${LATEST_TAG}" | |
| else | |
| # For main branch, just use commit SHA and latest | |
| TAGS="${DOCKER_IMAGE}:${SHORTREF}${LATEST_TAG}" | |
| fi | |
| # Set output parameters. | |
| echo "tags=${TAGS}" >> "$GITHUB_OUTPUT" | |
| echo "docker_image=${DOCKER_IMAGE}" >> "$GITHUB_OUTPUT" | |
| # Setup qemu and buildx | |
| - name: Setup QEMU | |
| uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3.2.0 | |
| with: | |
| platforms: all | |
| - name: Setup Docker Buildx | |
| id: buildx | |
| uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3.7.1 | |
| # Auth on registry | |
| - name: Login to Quay.io | |
| if: github.event_name != 'pull_request' | |
| uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0 | |
| with: | |
| registry: ${{ env.IMAGE_REGISTRY }} | |
| username: ${{ secrets.QUAY_REGISTRY_USERNAME }} | |
| password: ${{ secrets.QUAY_REGISTRY_PASSWORD }} | |
| # Build image using buildx | |
| - name: Build | |
| uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 # v6.9.0 | |
| with: | |
| builder: ${{ steps.buildx.outputs.name }} | |
| context: . | |
| file: ./Containerfile | |
| platforms: linux/amd64 | |
| push: ${{ github.event_name != 'pull_request' }} | |
| tags: ${{ steps.prep.outputs.tags }} |