Skip to content

Commit 643557d

Browse files
gloursndeloof
authored andcommitted
build and push binaries images when a PR is merged or a tag pushed
Signed-off-by: Guillaume Lours <[email protected]>
1 parent 200f47e commit 643557d

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

.github/workflows/merge.yml

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ on:
1010
- 'v2'
1111
tags:
1212
- 'v*'
13-
workflow_dispatch:
1413

1514
permissions:
1615
contents: read # to fetch code (actions/checkout)
1716

17+
env:
18+
REPO_SLUG: "docker/compose-bin"
19+
1820
jobs:
1921
e2e:
2022
name: Build and test
@@ -72,3 +74,47 @@ jobs:
7274
run: |
7375
make e2e-compose-standalone
7476
77+
bin-image:
78+
runs-on: ubuntu-22.04
79+
steps:
80+
-
81+
name: Checkout
82+
uses: actions/checkout@v3
83+
-
84+
name: Set up QEMU
85+
uses: docker/setup-qemu-action@v2
86+
-
87+
name: Set up Docker Buildx
88+
uses: docker/setup-buildx-action@v2
89+
-
90+
name: Docker meta
91+
id: meta
92+
uses: docker/metadata-action@v4
93+
with:
94+
images: |
95+
${{ env.REPO_SLUG }}
96+
tags: |
97+
type=ref,event=tag
98+
type=edge
99+
bake-target: meta-helper
100+
-
101+
name: Login to DockerHub
102+
if: github.event_name != 'pull_request'
103+
uses: docker/login-action@v2
104+
with:
105+
username: ${{ secrets.DOCKERPUBLICBOT_USERNAME }}
106+
password: ${{ secrets.DOCKERPUBLICBOT_WRITE_PAT }}
107+
-
108+
name: Build and push image
109+
uses: docker/bake-action@v2
110+
with:
111+
files: |
112+
./docker-bake.hcl
113+
${{ steps.meta.outputs.bake-file }}
114+
targets: image-cross
115+
push: ${{ github.event_name != 'pull_request' }}
116+
set: |
117+
*.cache-from=type=gha,scope=bin-image
118+
*.cache-to=type=gha,scope=bin-image,mode=max
119+
*.attest=type=sbom
120+
*.attest=type=provenance,mode=max,builder-id=https://github.com/${{ env.GITHUB_REPOSITORY }}/actions/runs/${{ env.GITHUB_RUN_ID }}

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ FROM binary-unix AS binary-linux
168168
FROM scratch AS binary-windows
169169
COPY --link --from=build /usr/bin/docker-compose /docker-compose.exe
170170
FROM binary-$TARGETOS AS binary
171+
# enable scanning for this stage
172+
ARG BUILDKIT_SBOM_SCAN_STAGE=true
171173

172174
FROM --platform=$BUILDPLATFORM alpine AS releaser
173175
WORKDIR /work

docker-bake.hcl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ function "bindir" {
3333
result = DESTDIR != "" ? DESTDIR : "./bin/${defaultdir}"
3434
}
3535

36+
# Special target: https://github.com/docker/metadata-action#bake-definition
37+
target "meta-helper" {}
38+
3639
target "_common" {
3740
args = {
3841
GO_VERSION = GO_VERSION
@@ -134,3 +137,8 @@ target "docs-update" {
134137
target = "docs-update"
135138
output = ["./docs"]
136139
}
140+
141+
target "image-cross" {
142+
inherits = ["meta-helper", "binary-cross"]
143+
output = ["type=image"]
144+
}

0 commit comments

Comments
 (0)