-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix build cache in CI not being used properly
Refs docker/buildx#1044
- Loading branch information
Showing
2 changed files
with
78 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,13 +10,81 @@ on: | |
merge_group: | ||
|
||
jobs: | ||
ci: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
architecture: | ||
- amd64 | ||
- arm64 | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Build to export cache | ||
uses: docker/bake-action@v4 | ||
with: | ||
set: | | ||
devcontainer.platform=linux/${{ matrix.architecture }} | ||
jenkins-agent-dind.platform=linux/${{ matrix.architecture }} | ||
devcontainer.cache-from=type=gha,scope=devcontainer-${{ matrix.architecture }} | ||
jenkins-agent-dind.cache-from=type=gha,scope=jenkins-agent-dind-${{ matrix.architecture }} | ||
devcontainer.cache-to=type=gha,scope=devcontainer-${{ matrix.architecture }},mode=max | ||
jenkins-agent-dind.cache-to=type=gha,scope=jenkins-agent-dind-${{ matrix.architecture }},mode=max | ||
test: | ||
needs: build | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
with: | ||
driver-opts: network=host | ||
|
||
- name: Build to import cache | ||
uses: docker/bake-action@v4 | ||
with: | ||
set: | | ||
devcontainer.cache-from=type=gha,scope=devcontainer-amd64 | ||
jenkins-agent-dind.cache-from=type=gha,scope=jenkins-agent-dind-amd64 | ||
load: true | ||
|
||
- name: Test | ||
uses: devcontainers/[email protected] | ||
with: | ||
runCmd: ./test.sh | ||
|
||
push: | ||
needs: test | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Docker meta (devcontainer) | ||
id: docker-meta-devcontainer | ||
uses: docker/metadata-action@v5 | ||
|
@@ -62,56 +130,6 @@ jobs: | |
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
with: | ||
driver-opts: network=host | ||
|
||
- name: Install pkgx | ||
uses: pkgxdev/setup@v2 | ||
|
||
- name: Install test dependencies | ||
run: .devcontainer/post_create.sh | ||
|
||
# Build devcontainer first otherwise docker bake will start building devcontainer twice | ||
# as jenkins-agent-dind depends on it. | ||
- name: Build (devcontainer only) | ||
uses: docker/bake-action@v4 | ||
with: | ||
targets: devcontainer | ||
files: | | ||
./docker-bake.hcl | ||
${{ steps.docker-meta-devcontainer.outputs.bake-file }} | ||
set: | | ||
*.platform=linux/amd64,linux/arm64 | ||
devcontainer.cache-from=type=gha,scope=cached-stage-devcontainer | ||
devcontainer.cache-to=type=gha,scope=cached-stage-devcontainer,mode=max | ||
- name: Build | ||
uses: docker/bake-action@v4 | ||
with: | ||
files: | | ||
./docker-bake.hcl | ||
${{ steps.docker-meta-devcontainer.outputs.bake-file }} | ||
${{ steps.docker-meta-jenkins-agent-dind.outputs.bake-file }} | ||
set: | | ||
*.platform=linux/amd64,linux/arm64 | ||
devcontainer.cache-from=type=gha,scope=cached-stage-devcontainer | ||
jenkins-agent-dind.cache-from=type=gha,scope=cached-stage-jenkins-agent-dind | ||
devcontainer-jenkins-agent-dind.cache-from=type=gha,scope=cached-stage-devcontainer-jenkins-agent-dind | ||
devcontainer.cache-to=type=gha,scope=cached-stage-devcontainer,mode=max | ||
jenkins-agent-dind.cache-to=type=gha,scope=cached-stage-jenkins-agent-dind,mode=max | ||
devcontainer-jenkins-agent-dind.cache-to=type=gha,scope=cached-stage-devcontainer-jenkins-agent-dind,mode=max | ||
*.cache-to=type=inline | ||
- name: Test | ||
env: | ||
GITHUB_ACTIONS: "true" | ||
run: ./test.sh | ||
|
||
- name: Push | ||
uses: docker/bake-action@v4 | ||
with: | ||
|
@@ -120,5 +138,10 @@ jobs: | |
${{ steps.docker-meta-devcontainer.outputs.bake-file }} | ||
${{ steps.docker-meta-jenkins-agent-dind.outputs.bake-file }} | ||
set: | | ||
*.platform=linux/amd64,linux/arm64 | ||
devcontainer.platform=linux/amd64,linux/arm64 | ||
jenkins-agent-dind.platform=linux/amd64,linux/arm64 | ||
devcontainer.cache-from=type=gha,scope=devcontainer-amd64 | ||
devcontainer.cache-from=type=gha,scope=devcontainer-arm64 | ||
jenkins-agent-dind.cache-from=type=gha,scope=jenkins-agent-dind-amd64 | ||
jenkins-agent-dind.cache-from=type=gha,scope=jenkins-agent-dind-arm64 | ||
push: true |