Skip to content

Commit 19b04f1

Browse files
authored
add buildkit release workflow (#165)
1 parent 0a7abf7 commit 19b04f1

2 files changed

Lines changed: 236 additions & 0 deletions

File tree

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
name: Build & Push BuildKit Docker Image
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: 'Version tag for the BuildKit image (e.g., v1.0.0)'
8+
required: true
9+
type: string
10+
push_latest:
11+
description: 'Also tag as latest'
12+
required: false
13+
type: boolean
14+
default: false
15+
16+
jobs:
17+
prepare-metadata:
18+
runs-on: ubuntu-latest
19+
outputs:
20+
version: ${{ steps.meta.outputs.version }}
21+
major: ${{ steps.meta.outputs.major }}
22+
major_minor: ${{ steps.meta.outputs.major_minor }}
23+
tags_suffix: ${{ steps.tags.outputs.tags_suffix }}
24+
steps:
25+
- name: Validate inputs
26+
run: |
27+
VERSION="${{ github.event.inputs.version }}"
28+
29+
if ! [[ "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
30+
echo "Error: version must be in format v1.2.3"
31+
exit 1
32+
fi
33+
34+
- name: Extract metadata
35+
id: meta
36+
run: |
37+
VERSION="${{ github.event.inputs.version }}"
38+
echo "version=$VERSION" >> $GITHUB_OUTPUT
39+
40+
if [[ "$VERSION" =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
41+
MAJOR="v${BASH_REMATCH[1]}"
42+
MINOR="${BASH_REMATCH[2]}"
43+
MAJOR_MINOR="v${BASH_REMATCH[1]}.${MINOR}"
44+
echo "major=$MAJOR" >> $GITHUB_OUTPUT
45+
echo "major_minor=$MAJOR_MINOR" >> $GITHUB_OUTPUT
46+
fi
47+
48+
- name: Determine Docker tags
49+
id: tags
50+
run: |
51+
TAGS_SUFFIX="${{ steps.meta.outputs.version }}"
52+
TAGS_SUFFIX="$TAGS_SUFFIX,${{ steps.meta.outputs.major }}"
53+
TAGS_SUFFIX="$TAGS_SUFFIX,${{ steps.meta.outputs.major_minor }}"
54+
55+
if [[ "${{ github.event.inputs.push_latest }}" == "true" ]]; then
56+
TAGS_SUFFIX="$TAGS_SUFFIX,latest"
57+
fi
58+
59+
echo "tags_suffix=$TAGS_SUFFIX" >> $GITHUB_OUTPUT
60+
61+
build-amd64:
62+
runs-on: ubuntu-latest
63+
needs: prepare-metadata
64+
steps:
65+
- name: Check out repository
66+
uses: actions/checkout@v4
67+
68+
- name: Set up Docker Buildx
69+
uses: docker/setup-buildx-action@v4
70+
with:
71+
buildkitd-flags: --debug
72+
73+
- name: Log in to Docker Hub
74+
uses: docker/login-action@v3
75+
with:
76+
username: ${{ secrets.DOCKERHUB_USERNAME }}
77+
password: ${{ secrets.DOCKERHUB_TOKEN }}
78+
79+
- name: Build and push AMD64 image
80+
id: build
81+
uses: docker/build-push-action@v6
82+
with:
83+
context: .
84+
file: buildkit.Dockerfile
85+
platforms: linux/amd64
86+
outputs: type=image,name=lifecycleoss/buildkit,push-by-digest=true,name-canonical=true,push=true
87+
cache-from: type=registry,ref=lifecycleoss/buildkit:buildcache-amd64
88+
cache-to: type=registry,ref=lifecycleoss/buildkit:buildcache-amd64,mode=max
89+
90+
- name: Export digest
91+
run: |
92+
mkdir -p /tmp/digests
93+
digest="${{ steps.build.outputs.digest }}"
94+
touch "/tmp/digests/${digest#sha256:}"
95+
96+
- name: Upload digest
97+
uses: actions/upload-artifact@v4
98+
with:
99+
name: digests-amd64
100+
path: /tmp/digests/*
101+
if-no-files-found: error
102+
retention-days: 1
103+
104+
build-arm64:
105+
runs-on: ubuntu-latest
106+
needs: prepare-metadata
107+
steps:
108+
- name: Check out repository
109+
uses: actions/checkout@v4
110+
111+
- name: Set up QEMU
112+
uses: docker/setup-qemu-action@v3
113+
114+
- name: Set up Docker Buildx
115+
uses: docker/setup-buildx-action@v4
116+
with:
117+
buildkitd-flags: --debug
118+
119+
- name: Log in to Docker Hub
120+
uses: docker/login-action@v3
121+
with:
122+
username: ${{ secrets.DOCKERHUB_USERNAME }}
123+
password: ${{ secrets.DOCKERHUB_TOKEN }}
124+
125+
- name: Build and push ARM64 image
126+
id: build
127+
uses: docker/build-push-action@v6
128+
with:
129+
context: .
130+
file: buildkit.Dockerfile
131+
platforms: linux/arm64
132+
outputs: type=image,name=lifecycleoss/buildkit,push-by-digest=true,name-canonical=true,push=true
133+
cache-from: type=registry,ref=lifecycleoss/buildkit:buildcache-arm64
134+
cache-to: type=registry,ref=lifecycleoss/buildkit:buildcache-arm64,mode=max
135+
136+
- name: Export digest
137+
run: |
138+
mkdir -p /tmp/digests
139+
digest="${{ steps.build.outputs.digest }}"
140+
touch "/tmp/digests/${digest#sha256:}"
141+
142+
- name: Upload digest
143+
uses: actions/upload-artifact@v4
144+
with:
145+
name: digests-arm64
146+
path: /tmp/digests/*
147+
if-no-files-found: error
148+
retention-days: 1
149+
150+
merge-and-push:
151+
runs-on: ubuntu-latest
152+
needs:
153+
- prepare-metadata
154+
- build-amd64
155+
- build-arm64
156+
steps:
157+
- name: Download digests
158+
uses: actions/download-artifact@v4
159+
with:
160+
path: /tmp/digests
161+
162+
- name: Set up Docker Buildx
163+
uses: docker/setup-buildx-action@v4
164+
165+
- name: Log in to Docker Hub
166+
uses: docker/login-action@v3
167+
with:
168+
username: ${{ secrets.DOCKERHUB_USERNAME }}
169+
password: ${{ secrets.DOCKERHUB_TOKEN }}
170+
171+
- name: Create manifest list and push
172+
env:
173+
TAGS_SUFFIX: ${{ needs.prepare-metadata.outputs.tags_suffix }}
174+
run: |
175+
AMD64_DIGEST=$(find /tmp/digests/digests-amd64 -type f | head -1)
176+
ARM64_DIGEST=$(find /tmp/digests/digests-arm64 -type f | head -1)
177+
178+
AMD64_SHA=$(basename "$AMD64_DIGEST")
179+
ARM64_SHA=$(basename "$ARM64_DIGEST")
180+
181+
DIGESTS="lifecycleoss/buildkit@sha256:$AMD64_SHA lifecycleoss/buildkit@sha256:$ARM64_SHA"
182+
183+
IFS=',' read -ra TAG_ARRAY <<< "$TAGS_SUFFIX"
184+
185+
for TAG_SUFFIX in "${TAG_ARRAY[@]}"; do
186+
TAG_SUFFIX=$(echo "$TAG_SUFFIX" | xargs)
187+
FULL_TAG="lifecycleoss/buildkit:${TAG_SUFFIX}"
188+
docker buildx imagetools create -t "$FULL_TAG" $DIGESTS
189+
done
190+
191+
- name: Inspect final image
192+
run: |
193+
docker buildx imagetools inspect lifecycleoss/buildkit:${{ needs.prepare-metadata.outputs.version }}
194+
195+
- name: Create GitHub Release
196+
uses: actions/create-release@v1
197+
env:
198+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
199+
with:
200+
tag_name: buildkit-${{ needs.prepare-metadata.outputs.version }}
201+
release_name: BuildKit Image ${{ needs.prepare-metadata.outputs.version }}
202+
body: |
203+
BuildKit image release for lifecycle.
204+
205+
Docker Hub: `lifecycleoss/buildkit:${{ needs.prepare-metadata.outputs.version }}`
206+
207+
Tags created:
208+
- `lifecycleoss/buildkit:${{ needs.prepare-metadata.outputs.version }}`
209+
- `lifecycleoss/buildkit:${{ needs.prepare-metadata.outputs.major }}`
210+
- `lifecycleoss/buildkit:${{ needs.prepare-metadata.outputs.major_minor }}`
211+
${{ github.event.inputs.push_latest == 'true' && '- `lifecycleoss/buildkit:latest`' || '' }}
212+
draft: false
213+
prerelease: false

‎buildkit.Dockerfile‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright 2025 GoodRx, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
ARG BUILDKIT_VERSION=v0.28.1
16+
17+
FROM golang:1.24-alpine AS builder
18+
RUN go install github.com/awslabs/amazon-ecr-credential-helper/ecr-login/cli/docker-credential-ecr-login@v0.12.0
19+
20+
FROM moby/buildkit:${BUILDKIT_VERSION}
21+
COPY --from=builder /go/bin/docker-credential-ecr-login /usr/bin/
22+
RUN mkdir -p /root/.docker && \
23+
echo '{"credsStore":"ecr-login"}' > /root/.docker/config.json

0 commit comments

Comments
 (0)