Skip to content

Use native arm64 runner to build docker #4

Use native arm64 runner to build docker

Use native arm64 runner to build docker #4

Workflow file for this run

name: Build and Push Docker Image
on:
push:
branches:
- main
release:
types: [published]
workflow_dispatch:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-push:
name: Build and Push Docker Image (${{ matrix.platform }})
runs-on: ${{ matrix.runner }}
permissions:
contents: read
packages: write
strategy:
matrix:
include:
- platform: linux/amd64
runner: ubuntu-latest
- platform: linux/arm64
runner: ubuntu-24.04-arm
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
# Tag with 'dev' on push to main
type=raw,value=dev,enable={{is_default_branch}}
# Tag with version number on release
type=semver,pattern={{version}}
# Tag with 'latest' on release (not pre-release)
type=raw,value=latest,enable=${{ github.event_name == 'release' && !github.event.release.prerelease }}
labels: |
org.opencontainers.image.title=Hermes Backend
org.opencontainers.image.description=NASA telemetry and commanding system backend
org.opencontainers.image.vendor=Jet Propulsion Laboratory
flavor: |
suffix=-${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
file: docker/Dockerfile.backend
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: ${{ matrix.platform }}
merge-manifests:
name: Create and Push Multi-Arch Manifest
needs: build-and-push
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=dev,enable={{is_default_branch}}
type=semver,pattern={{version}}
type=raw,value=latest,enable=${{ github.event_name == 'release' && !github.event.release.prerelease }}
- name: Create and push multi-arch manifest
run: |
for tag in ${{ steps.meta.outputs.tags }}; do
docker buildx imagetools create -t ${tag} \
${tag}-amd64 \
${tag}-arm64
done
- name: Image digest
run: echo "Multi-arch manifest created for tags ${{ steps.meta.outputs.tags }}"