From 5d18726aac15d2963448efb12964f920627e57de Mon Sep 17 00:00:00 2001 From: Nick Sieger Date: Wed, 24 Aug 2022 11:52:19 -0500 Subject: [PATCH] Build and push docker/docker-compose images upon release Signed-off-by: Nick Sieger --- .github/workflows/ci.yml | 47 ++++++++++++++++++++++++++++++++++++++++ Dockerfile | 6 +++++ Makefile | 4 ++++ docker-bake.hcl | 20 +++++++++++++++++ 4 files changed, 77 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0f4675cc696..db385b49305 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,6 +22,7 @@ env: GO_VERSION: "1.18.5" # for non sandboxed e2e tests DESTDIR: "./bin" DOCKER_CLI_VERSION: "20.10.17" + REPO_SLUG: "docker/docker-compose" jobs: prepare: @@ -223,3 +224,49 @@ jobs: generateReleaseNotes: true draft: true token: ${{ secrets.GITHUB_TOKEN }} + + bin-image: + runs-on: ubuntu-latest + if: ${{ github.event_name != 'pull_request' }} + steps: + - + name: Checkout + uses: actions/checkout@v3 + - + name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + with: + version: latest + - + name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: | + ${{ env.REPO_SLUG }} + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + - + name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Build and push image + uses: docker/bake-action@v2 + with: + files: | + ./docker-bake.hcl + ${{ steps.meta.outputs.bake-file }} + targets: release-image + push: ${{ startsWith(github.ref, 'refs/tags/v') }} + set: | + *.cache-from=type=gha,scope=bin-image + *.cache-to=type=gha,scope=bin-image,mode=max diff --git a/Dockerfile b/Dockerfile index bd78ad29687..1c136ab7ad1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -186,3 +186,9 @@ COPY --from=releaser /out/ / # see open-pr job in .github/workflows/docs.yml for more details FROM scratch AS docs-reference COPY docs/reference/*.yaml . + +FROM base AS release-image +WORKDIR /root +COPY --link --from=build /usr/bin/docker-compose /usr/bin/ +RUN mkdir -p /usr/local/lib/docker/cli-plugins +RUN ln -s /usr/bin/docker-compose /usr/local/lib/docker/cli-plugins/ diff --git a/Makefile b/Makefile index b72a7f5c15e..358d6e0a47b 100644 --- a/Makefile +++ b/Makefile @@ -82,6 +82,10 @@ build-and-e2e: compose-plugin e2e-compose e2e-compose-standalone ## Compile the cross: ## Compile the CLI for linux, darwin and windows $(BUILDX_CMD) bake binary +.PHONY: image +image: ## Build the docker/docker-compose image locally and load it into Docker + $(BUILDX_CMD) bake image + .PHONY: test test: ## Run unit tests $(BUILDX_CMD) bake test diff --git a/docker-bake.hcl b/docker-bake.hcl index 8946f79be9c..01a04b0566e 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -124,3 +124,23 @@ target "docs-update" { target = "docs-update" output = ["./docs"] } + +target "docker-metadata-action" {} + +target "release-image" { + inherits = ["docker-metadata-action"] + target = "release-image" + platforms = [ + "linux/amd64", + "linux/arm/v6", + "linux/arm/v7", + "linux/arm64", + ] +} + +target "image" { + inherits = ["release-image"] + platforms = [] + tags = ["docker.io/docker/docker-compose"] + output = ["type=docker"] +}