From 2f8f43e6f7cc22ca0a3d28fece504b1e30b20eed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Molinero=20Fern=C3=A1ndez?= Date: Tue, 14 Jun 2022 23:45:37 +0200 Subject: [PATCH] Build common stages separately --- .github/workflows/main.yml | 46 +++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bc4c932..50f6df4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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: