Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
170 changes: 170 additions & 0 deletions .github/workflows/docker-multistage-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
---
name: Build multi-arch images

on:
workflow_call:
###
### Variables
###
inputs:
matrix:
description: 'The build matrix'
required: true
type: string
has_refs:
description: 'The ref build matrix as JSON string (list of git refs to build/deploy).'
required: true
type: string
artifact_prefix:
description: 'Unique artifact name prefix (to avoid overriding existing artifcats during parallel runs).'
required: true
type: string
flavour:
description: 'The flavour to build (Examples: base, mods, prod or work).'
required: true
type: string
flavour_prev:
description: 'The previous flavour (used for downloading previous artifact).'
required: true
type: string
run_tests:
description: 'Dertermines whether we run integration tests or not.'
required: true
type: boolean
upload_artifact:
description: 'Dertermines whether we upload the artifact not.'
required: true
type: boolean

jobs:
# -----------------------------------------------------------------------------------------------
# JOB: BUILD
# -----------------------------------------------------------------------------------------------
build:
name: ${{ matrix.name }}-${{ matrix.version }}-${{ inputs.flavour }} (${{ matrix.arch }}) ${{ matrix.refs }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include: ${{ fromJson(inputs.matrix) }}
steps:

# ------------------------------------------------------------
# Setup repository
# ------------------------------------------------------------
- name: "[SETUP] Checkout repository (current)"
uses: actions/checkout@v3
with:
fetch-depth: 0
if: inputs.has_refs == 0

- name: "[SETUP] Checkout repository (ref: ${{ matrix.refs }})"
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ matrix.refs }}
if: inputs.has_refs != 0

- name: "[SETUP] Setup QEMU environment"
uses: docker/setup-qemu-action@v1
with:
image: tonistiigi/binfmt:latest
platforms: all

- name: "[SETUP] Set artifact names"
id: set-artifact-name
run: |
PRE_HASH="$( git rev-parse HEAD | head -c 10 )"
VERSION="${{ matrix.version }}"
ARCH="$( echo "${{ matrix.arch }}" | sed 's|/|-|g' )"

NAME_PREV="${{ inputs.artifact_prefix }}-${PRE_HASH}-${VERSION}-${ARCH}-${{ inputs.flavour_prev }}"
NAME_CURR="${{ inputs.artifact_prefix }}-${PRE_HASH}-${VERSION}-${ARCH}-${{ inputs.flavour }}"
echo "::set-output name=prev::${NAME_PREV}"
echo "::set-output name=curr::${NAME_CURR}"


# ------------------------------------------------------------
# Artifact Import
# ------------------------------------------------------------

###
### Download and import previously built image (if it exists)
###
- name: "[Artifact Load] Download previously built image"
uses: Wandalen/wretry.action@v1.0.11
with:
action: actions/download-artifact@v3
with: |
name: ${{ steps.set-artifact-name.outputs.prev }}
attempt_limit: 20
attempt_delay: 10000
if: ${{ inputs.flavour_prev != '' }}

- name: "[Artifact Load] Import previously built image"
uses: cytopia/shell-command-retry-action@v0.1.2
with:
command: |
make load INFILE=${{ steps.set-artifact-name.outputs.prev }}
if: ${{ inputs.flavour_prev != '' }}


# ------------------------------------------------------------
# Build
# ------------------------------------------------------------
- name: Build
uses: cytopia/shell-command-retry-action@v0.1.2
with:
command: |
make build VERSION=${{ matrix.version }} FLAVOUR=${{ inputs.flavour }} ARCH=${{ matrix.arch }}


# ------------------------------------------------------------
# Test
# ------------------------------------------------------------
- name: Test
uses: cytopia/shell-command-retry-action@v0.1.2
with:
command: |
make test VERSION=${{ matrix.version }} FLAVOUR=${{ inputs.flavour }} ARCH=${{ matrix.arch }}
if: ${{ inputs.run_tests }}


# ------------------------------------------------------------
# Artifact Export
# ------------------------------------------------------------

###
### Export current image
###
- name: "[Artifact Save] Export currently built image"
uses: cytopia/shell-command-retry-action@v0.1.2
with:
command: |
make save-verify VERSION=${{ matrix.version }} FLAVOUR=${{ inputs.flavour }} ARCH=${{ matrix.arch }} OUTFILE=${{ steps.set-artifact-name.outputs.curr }} INFILE=${{ steps.set-artifact-name.outputs.curr }}
if: ${{ inputs.upload_artifact }}

###
### Upload current image
###
- name: "[Artifact Save] Upload currently built image"
uses: Wandalen/wretry.action@v1.0.11
with:
action: actions/upload-artifact@v3
with: |
name: ${{ steps.set-artifact-name.outputs.curr }}
path: ${{ steps.set-artifact-name.outputs.curr }}
if-no-files-found: error
attempt_limit: 20
attempt_delay: 10000
if: ${{ inputs.upload_artifact }}

###
### Verify uploaded image
###
- name: "[Artifact Save] Download (verify)"
uses: actions/download-artifact@v3
with:
name: ${{ steps.set-artifact-name.outputs.curr }}
path: ${{ steps.set-artifact-name.outputs.curr }}.tmp
if: ${{ inputs.upload_artifact }}
Loading