Skip to content

Build Docker Image

Build Docker Image #79

Workflow file for this run

name: Build Docker Image
on:
workflow_dispatch:
workflow_run:
workflows: [CI]
types: [completed]
branches: [main]
permissions:
contents: read
packages: write
env:
IMAGE: ghcr.io/versatiles-org/versatiles-choro
BUILD_FROM_SOURCE: false
jobs:
build-amd64:
if: ${{ ( github.event_name != 'workflow_run' && github.ref == 'refs/heads/main' ) || ( github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'main' ) }}
runs-on: ubuntu-24.04
permissions:
contents: read
packages: write
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Get version from package.json
id: version
run: echo "version=$(jq -r .version package.json)" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to GHCR
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build Docker image
uses: docker/build-push-action@v7
with:
context: .
file: docker/Dockerfile
build-args: BUILD_FROM_SOURCE=${{ env.BUILD_FROM_SOURCE }}
platforms: linux/amd64
pull: true
load: true
tags: ${{ env.IMAGE }}:amd64
cache-from: type=gha,scope=amd64
cache-to: type=gha,scope=amd64,mode=max
- name: Test Docker image
run: ./docker/test.sh ${{ env.IMAGE }}:amd64
- name: Push amd64 image
uses: docker/build-push-action@v7
with:
context: .
file: docker/Dockerfile
build-args: BUILD_FROM_SOURCE=${{ env.BUILD_FROM_SOURCE }}
platforms: linux/amd64
push: true
tags: |
${{ env.IMAGE }}:amd64
${{ env.IMAGE }}:${{ steps.version.outputs.version }}-amd64
cache-from: type=gha,scope=amd64
build-arm64:
if: ${{ ( github.event_name != 'workflow_run' && github.ref == 'refs/heads/main' ) || ( github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'main' ) }}
runs-on: ubuntu-24.04-arm
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Get version from package.json
id: version
run: echo "version=$(jq -r .version package.json)" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to GHCR
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build Docker image
uses: docker/build-push-action@v7
with:
context: .
file: docker/Dockerfile
build-args: BUILD_FROM_SOURCE=${{ env.BUILD_FROM_SOURCE }}
platforms: linux/arm64
pull: true
load: true
tags: ${{ env.IMAGE }}:arm64
cache-from: type=gha,scope=arm64
cache-to: type=gha,scope=arm64,mode=max
- name: Test Docker image
run: ./docker/test.sh ${{ env.IMAGE }}:arm64
- name: Push arm64 image
uses: docker/build-push-action@v7
with:
context: .
file: docker/Dockerfile
build-args: BUILD_FROM_SOURCE=${{ env.BUILD_FROM_SOURCE }}
platforms: linux/arm64
push: true
tags: |
${{ env.IMAGE }}:arm64
${{ env.IMAGE }}:${{ steps.version.outputs.version }}-arm64
cache-from: type=gha,scope=arm64
push-manifest:
needs: [build-amd64, build-arm64]
runs-on: ubuntu-24.04
permissions:
packages: write
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to GHCR
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create and push multi-arch manifests
run: |
VERSION=${{ needs.build-amd64.outputs.version }}
# Create latest manifest
docker buildx imagetools create -t ${{ env.IMAGE }}:latest \
${{ env.IMAGE }}:amd64 \
${{ env.IMAGE }}:arm64
# Create versioned manifest
docker buildx imagetools create -t ${{ env.IMAGE }}:${VERSION} \
${{ env.IMAGE }}:${VERSION}-amd64 \
${{ env.IMAGE }}:${VERSION}-arm64