Include amd64 Docker image suffix and build it last #625
Workflow file for this run
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: Docker build and push | |
| # limit concurrency | |
| # https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#examples-using-concurrency-and-the-default-behavior | |
| concurrency: docker_mmgis_main | |
| on: | |
| push: | |
| # Only activate for `master` branch | |
| branches: | |
| - master | |
| - development | |
| # Plus for all tags | |
| tags: | |
| - "*" | |
| # Plus for any pull-requests | |
| pull_request: | |
| branches: | |
| - master | |
| - development | |
| # And for any final releases | |
| release: | |
| types: [published] | |
| env: | |
| # Will be "NASA-AMMOS/MMGIS" for the main repo, for forks "user-name-of-fork/MMGIS" | |
| # For generating the tag, all will be converted to lowercase | |
| IMAGE_SLUG: ${{ github.repository }} | |
| jobs: | |
| # Generate shared tags for both architectures | |
| # The image tag pattern is: | |
| # for pull-requests: <PATCH_VERSION>-<DATE>-<PR_NUMBER>, eg: 1.35.2-20210125-25 | |
| # for tags: <TAG> | |
| # for `master` branch: latest,<PATCH_VERSION>-latest,<MINOR_VERSION>-latest,<MAJOR_VERSION>-latest,<PATCH_VERSION>-<DATE>-<SHA> | |
| # for `development` branch: development,<MAJOR_VERSION>-development,<PATCH_VERSION>-<DATE>-<SHA> | |
| # for releases: release,<PATCH_VERSION>-release,<MINOR_VERSION>-release,<MAJOR_VERSION>-release,<PATCH_VERSION>-<DATE>-<SHA> | |
| # Version is parsed from package.json | |
| generate-tags: | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'push' || github.event_name == 'pull_request' || github.event_name == 'release' | |
| outputs: | |
| tags: ${{ steps.generate.outputs.TAGS }} | |
| image-id: ${{ steps.generate.outputs.IMAGE_ID }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v3 | |
| - name: Generate tags | |
| id: generate | |
| run: | | |
| IMAGE_ID=$(echo "ghcr.io/$IMAGE_SLUG" | tr '[A-Z]' '[a-z]') | |
| PATCH_VERSION=$(jq .version -r ./package.json) | |
| BRANCH_OR_TAG=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') | |
| TAGS="" | |
| if [ "${{ github.event_name }}" == "pull_request" ]; then | |
| PR_NUMBER=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\)/merge,\1,') | |
| TAGS="$PATCH_VERSION-$(date +%Y%m%d)-$PR_NUMBER" | |
| elif [[ "$BRANCH_OR_TAG" == "master" ]]; then | |
| TAGS="latest $PATCH_VERSION-latest" | |
| elif [[ "$BRANCH_OR_TAG" == "development" ]]; then | |
| TAGS="development" | |
| elif [[ "${{ github.ref }}" == "refs/tags/"* ]]; then | |
| TAGS="$BRANCH_OR_TAG" | |
| fi | |
| echo "Generated tags: $TAGS" | |
| echo "TAGS=$TAGS" >> $GITHUB_OUTPUT | |
| echo "IMAGE_ID=$IMAGE_ID" >> $GITHUB_OUTPUT | |
| # Build and push AMD64 image on x64 runner | |
| build-amd64: | |
| needs: generate-tags | |
| runs-on: ubuntu-latest # x64 runner for native AMD64 builds | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to GHCR | |
| run: echo ${{ secrets.GITHUB_TOKEN }} | docker login -u ${{ github.actor }} --password-stdin ghcr.io | |
| - name: Docker buildx build and push (AMD64) | |
| run: | | |
| IMAGE_ID=${{ needs.generate-tags.outputs.image-id }} | |
| # Create a set of --tag arguments with the -amd64 suffix | |
| ARCH_TAGS=$(for tag in ${{ needs.generate-tags.outputs.tags }}; do echo "--tag $IMAGE_ID:$tag-amd64"; done) | |
| docker buildx build \ | |
| --platform linux/amd64 \ | |
| $ARCH_TAGS \ | |
| --push \ | |
| --no-cache \ | |
| . | |
| # Build and push ARM64 image on ARM64 runner | |
| build-arm64: | |
| needs: generate-tags | |
| runs-on: ubuntu-24.04-arm # ARM64 runner for native ARM64 builds | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to GHCR | |
| run: echo ${{ secrets.GITHUB_TOKEN }} | docker login -u ${{ github.actor }} --password-stdin ghcr.io | |
| - name: Docker buildx build and push (ARM64) | |
| run: | | |
| IMAGE_ID=${{ needs.generate-tags.outputs.image-id }} | |
| # Create a set of --tag arguments with the -arm64 suffix | |
| ARCH_TAGS=$(for tag in ${{ needs.generate-tags.outputs.tags }}; do echo "--tag $IMAGE_ID:$tag-arm64"; done) | |
| docker buildx build \ | |
| --platform linux/arm64 \ | |
| $ARCH_TAGS \ | |
| --push \ | |
| --no-cache \ | |
| . | |
| # Create and push multi-arch manifest | |
| publish-manifest: | |
| needs: [build-amd64, build-arm64] # Runs after both builds are successful | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Login to GHCR | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Create and push manifest list | |
| run: | | |
| IMAGE_ID=${{ needs.generate-tags.outputs.image-id }} | |
| for tag in ${{ needs.generate-tags.outputs.tags }}; do | |
| echo "Creating manifest for $IMAGE_ID:$tag" | |
| docker manifest create $IMAGE_ID:$tag \ | |
| --amend $IMAGE_ID:$tag-amd64 \ | |
| --amend $IMAGE_ID:$tag-arm64 | |
| echo "Pushing manifest for $IMAGE_ID:$tag" | |
| docker manifest push $IMAGE_ID:$tag | |
| done |