From dfa2930afc69d38b3d859bc2470981e785ff8ede Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Wed, 3 Jan 2024 10:07:34 +0100 Subject: [PATCH] ci: Add bin-image workflow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Build and push an image containing a static CLI binary for master branch and every release branch and tag. This is a slightly adjusted copy of the bin-image workflow from docker/buildx (by @crazy-max). Co-authored-by: CrazyMax Signed-off-by: Paweł Gronowski --- .github/workflows/build.yml | 47 +++++++++++++++++++++++++++++++++++++ Dockerfile | 3 +++ docker-bake.hcl | 24 +++++++++++++++++++ 3 files changed, 74 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8a0d384915..8487e4d3c3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,6 +4,9 @@ concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true +env: + VERSION: ${{ github.ref }} + on: workflow_dispatch: push: @@ -86,6 +89,50 @@ jobs: path: /tmp/out/* if-no-files-found: error + bin-image: + runs-on: ubuntu-20.04 + if: ${{ github.event_name != 'pull_request' && github.repository == 'docker/cli' }} + 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 + id: meta + uses: docker/metadata-action@v5 + with: + images: dockereng/cli-bin + tags: | + type=semver,pattern={{version}} + type=ref,event=branch + type=ref,event=pr + type=sha + - + name: Login to DockerHub + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_CLIBIN_USERNAME }} + password: ${{ secrets.DOCKERHUB_CLIBIN_TOKEN }} + - + name: Build and push image + uses: docker/bake-action@v4 + with: + files: | + ./docker-bake.hcl + ${{ steps.meta.outputs.bake-file }} + targets: bin-image-cross + push: ${{ github.event_name != 'pull_request' }} + set: | + *.cache-from=type=gha,scope=bin-image + *.cache-to=type=gha,scope=bin-image,mode=max + prepare-plugins: runs-on: ubuntu-20.04 outputs: diff --git a/Dockerfile b/Dockerfile index ac9a9ad6b4..5a8f890af0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -123,5 +123,8 @@ COPY --link . . FROM scratch AS plugins COPY --from=build-plugins /out . +FROM scratch AS bin-image +COPY --from=build /out/docker /docker + FROM scratch AS binary COPY --from=build /out . diff --git a/docker-bake.hcl b/docker-bake.hcl index b5de2da990..d8570f4503 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -165,3 +165,27 @@ target "e2e-gencerts" { dockerfile = "./e2e/testdata/Dockerfile.gencerts" output = ["./e2e/testdata"] } + +target "docker-metadata-action" { + tags = ["cli-bin:local"] +} + +target "bin-image" { + inherits = ["binary", "docker-metadata-action"] + target = "bin-image" + output = ["type=docker"] +} + +target "bin-image-cross" { + inherits = ["bin-image"] + output = ["type=image"] + platforms = [ + "linux/amd64", + "linux/arm/v6", + "linux/arm/v7", + "linux/arm64", + "linux/ppc64le", + "linux/s390x", + "windows/amd64" + ] +}