Skip to content

Build multi-arch docker images. #196

Build multi-arch docker images.

Build multi-arch docker images. #196

Workflow file for this run

name: Build
on:
pull_request:
branches: [ "master" ]
push:
branches: [ "master", "release/v*" ]
tags: [ "*.*.*" ]
jobs:
build:
strategy:
matrix:
os: [ linux ]
arch: [ x86_64, aarch64 ]
compiler: [ ghc963 ]
runs-on: ${{ matrix.arch == 'x86_64' && 'ubuntu-latest' || 'buildjet-4vcpu-ubuntu-2204-arm' }}
steps:
- name: 📥 Checkout repository
uses: actions/checkout@v3
with:
submodules: true
- name: 🧰 Install dependencies
shell: sh
run: |
sudo apt update
sudo apt install -y pandoc
- name: ❄️ Install Nix
uses: cachix/install-nix-action@v22
with:
extra_nix_config: |
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ= loony-tools:pr9m4BkM/5/eSTZlkQyRt57Jz7OMBxNSUiMC4FkcNfk= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
substituters = https://cache.iog.io/ https://cache.zw3rk.com/ https://cache.nixos.org/
nix_path: nixpkgs=channel:nixos-unstable
- name: 🧊 Prepare Cache
shell: bash
run: |
make configure
- name: 💾 Cache
uses: actions/cache@v3
with:
path: |
~/.cabal-static/packages
~/.cabal-static/store
key: cabal-${{ matrix.os }}-${{ matrix.arch }}-${{ matrix.compiler }}-${{ hashFiles('cabal.project.freeze') }}
restore-keys: |
cabal-${{ matrix.os }}-${{ matrix.arch }}-${{ matrix.compiler }}
- name: 🔨 Build
run: |
make
env:
GIT_SHA: ${{ github.sha }}
- name: 🔎 Verify
run: |
./dist/bin/kupo --version
./dist/bin/kupo +RTS --info -RTS
- name: 📎 Upload Artifact
uses: actions/upload-artifact@v3
with:
name: kupo-${{ github.sha }}-${{ matrix.arch }}-${{ matrix.os }}
path: |
dist/bin
dist/share
docker:
needs: [ build ]
strategy:
matrix:
os: [ linux ]
arch: [ x86_64, aarch64 ]
runs-on: ${{ matrix.os == 'linux' && 'ubuntu-latest' }}
steps:
- name: 📥 Checkout repository
uses: actions/checkout@v3
with:
submodules: true
- name: 🧰 Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: 🧐 hadolint
uses: hadolint/hadolint-action@v3.0.0
with:
dockerfile: "./Dockerfile"
failure-threshold: warning
ignore: DL3059, SC2086, DL3029
- name: 🐳 Login to DockerHub
if: ${{ github.event_name == 'push' }}
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: cardanosolutions/kupo
- name: 📝 Base Variables
id: base-variables
run: |
echo "image=cardanosolutions/kupo" >> $GITHUB_OUTPUT
- name: 📝 Tag Variables
if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags') }}
id: tag-variables
run: |
echo "tag=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_OUTPUT
- name: 📥 Download
uses: actions/download-artifact@v3
with:
name: kupo-${{ github.sha }}-${{ matrix.arch }}-${{ matrix.os }}
- name: 🔨 Build and push (latest)
id: build
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
uses: docker/build-push-action@v3
with:
context: .
platforms: ${{ matrix.os }}/${{ matrix.arch == 'x86_64' && 'amd64' || 'arm64' }}
tags: ${{ steps.base-variables.outputs.image }}:latest
target: kupo
cache-from: type=registry,ref=${{ steps.base-variables.outputs.image }}:latest
cache-to: type=inline
outputs: type=image,name=cardanosolutions/kupo,push-by-digest=true,name-canonical=true,push=true
- name: 🏷️ Build and push (tag)
if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags') }}
uses: docker/build-push-action@v3
with:
context: .
platforms: ${{ matrix.os }}/${{ matrix.arch == 'x86_64' && 'amd64' || 'arm64' }}
tags: ${{ steps.base-variables.outputs.image }}:${{ steps.tag-variables.outputs.tag }}
target: kupo
cache-from: type=registry,ref=${{ steps.base-variables.outputs.image }}:latest
cache-to: type=inline
outputs: type=image,name=cardanosolutions/kupo,push-by-digest=true,name-canonical=true,push=true
- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v3
with:
name: digests
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
registry:
needs: [ docker ]
runs-on: ubuntu-latest
steps:
- name: Download digests
uses: actions/download-artifact@v3
with:
name: digests
path: /tmp/digests
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: cardanosolutions/kupo
- name: 🐳 Login to DockerHub
if: ${{ github.event_name == 'push' }}
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}
- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect cardanosolutions/kupo:${{ steps.meta.outputs.version }}