Build common stages separately

This commit is contained in:
Héctor Molinero Fernández 2022-06-14 23:45:37 +02:00
parent d3bb0c7b75
commit 2f8f43e6f7

View File

@ -12,9 +12,34 @@ permissions: {}

jobs:

build-common-stages:
name: 'Build common stages'
runs-on: 'ubuntu-22.04'
permissions:
contents: 'read'
strategy:
matrix:
stage: ['build']
steps:
- name: 'Checkout project'
uses: 'actions/checkout@v3'
- name: 'Build and save image'
run: |
make \
IMAGE_REGISTRY="localhost" IMAGE_NAMESPACE="stage" IMAGE_PROJECT="${{ matrix.stage }}" \
IMAGE_BUILD_OPTS="--pull --target ${{ matrix.stage }} --build-arg BUILDKIT_INLINE_CACHE=1" \
build-native-image save-native-image
- name: 'Upload artifacts'
uses: 'actions/upload-artifact@v3'
with:
name: 'dist-common-stages'
path: './dist/'
retention-days: 1

build:
name: 'Build ${{ matrix.arch }} image'
runs-on: 'ubuntu-latest'
needs: ['build-common-stages']
runs-on: 'ubuntu-22.04'
permissions:
contents: 'read'
strategy:
@ -23,13 +48,24 @@ jobs:
steps:
- name: 'Checkout project'
uses: 'actions/checkout@v3'
- name: 'Download artifacts'
uses: 'actions/download-artifact@v3'
with:
name: 'dist-common-stages'
path: './dist/'
- name: 'Load common stages'
run: |
docker system prune --all --force
make IMAGE_REGISTRY="localhost" IMAGE_NAMESPACE="stage" IMAGE_PROJECT="build" load-native-image clean
- name: 'Register binfmt entries'
if: "matrix.arch != 'native'"
run: |
make binfmt-register
- name: 'Build and save image'
run: |
make IMAGE_BUILD_OPTS="--pull" "build-${{ matrix.arch }}-image" "save-${{ matrix.arch }}-image"
make \
IMAGE_BUILD_OPTS="--cache-from localhost/stage/build:latest" \
"build-${{ matrix.arch }}-image" "save-${{ matrix.arch }}-image"
- name: 'Upload artifacts'
if: "startsWith(github.ref, 'refs/tags/v') && matrix.arch != 'native'"
uses: 'actions/upload-artifact@v3'
@ -42,7 +78,7 @@ jobs:
name: 'Push ${{ matrix.arch }} image'
if: "startsWith(github.ref, 'refs/tags/v')"
needs: ['build']
runs-on: 'ubuntu-latest'
runs-on: 'ubuntu-22.04'
permissions:
contents: 'read'
strategy:
@ -70,7 +106,7 @@ jobs:
name: 'Push manifest'
if: "startsWith(github.ref, 'refs/tags/v')"
needs: ['push']
runs-on: 'ubuntu-latest'
runs-on: 'ubuntu-22.04'
permissions:
contents: 'read'
steps:
@ -90,7 +126,7 @@ jobs:
name: 'Create GitHub release'
if: "startsWith(github.ref, 'refs/tags/v')"
needs: ['push-manifest']
runs-on: 'ubuntu-latest'
runs-on: 'ubuntu-22.04'
permissions:
contents: 'write'
steps: