diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 3eacc19..38be8b3 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -5,7 +5,9 @@ }, "overrideCommand": false, "mounts": [ - "source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind" + "source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind", + // This allows sharing the build cache when running in GitHub Actions + "source=${localEnv:HOME}/.docker,target=/home/devcontainer/.docker,type=bind" ], "runArgs": ["--network=host"], "postCreateCommand": [".devcontainer/post_create.sh"], diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eb4b10f..d01c9b8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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/ci@v0.3 + 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