Skip to content

Commit dd5044e

Browse files
committed
ci: speedup docker builds with cache reuse
1 parent 6a9e8a7 commit dd5044e

File tree

2 files changed

+49
-24
lines changed

2 files changed

+49
-24
lines changed

.github/workflows/release.yaml

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,30 +31,49 @@ jobs:
3131
fetch-depth: 0
3232

3333
- name: Calculate new version with autotag
34+
id: autotag
3435
run: |
3536
curl -sL https://git.io/autotag-install | sh -s -- -b "${RUNNER_TEMP}/bin"
3637
set -x
3738
version=$(${RUNNER_TEMP}/bin/autotag -n)
38-
echo "version=$version" >> $GITHUB_ENV
39+
echo "version=${version}" >> $GITHUB_ENV
40+
echo "version=${version}" >> $GITHUB_OUTPUT
3941
4042
- name: Set up Docker Buildx
4143
uses: docker/setup-buildx-action@988b5a0280414f521da01fcc63a27aeeb4b104db # v3
4244

43-
- name: Release
44-
run: |
45-
set -eou pipefail
46-
set -x
47-
48-
image="ghcr.io/planetscale/k8s-node-tagger:v${version}"
45+
- name: Cache
46+
uses: actions/cache@v3
47+
id: cache
48+
with:
49+
path: |
50+
go-pkg-mod
51+
go-build
52+
key: ${{ runner.os }}-go-cache-${{ hashFiles('**/go.sum') }}-v2
4953

50-
git reset --hard && git clean -ffdx && git pull
54+
- name: inject go caches into docker
55+
uses: reproducible-containers/[email protected]
56+
with:
57+
cache-map: |
58+
{
59+
"go-pkg-mod": "/go/pkg/mod",
60+
"go-build": "/root/.cache/go-build"
61+
}
62+
skip-extraction: ${{ steps.cache.outputs.cache-hit }}
5163

52-
docker buildx build \
53-
-t "$image" \
54-
--platform linux/amd64,linux/arm64 \
55-
--push \
56-
.
64+
- name: Build and push
65+
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5
66+
with:
67+
context: .
68+
platforms: linux/amd64,linux/arm64
69+
push: true
70+
tags: ghcr.io/planetscale/k8s-node-tagger:v${{ steps.autotag.outputs.version }}
5771

58-
gh release create "v${version}" --target main --title "v${version}" --generate-notes
72+
- name: Create Release
5973
env:
60-
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
74+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
75+
run: |
76+
gh release create "v${version}" \
77+
--target main \
78+
--title "v${version}" \
79+
--generate-notes

Dockerfile

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
# syntax=docker/dockerfile:1.9
22
FROM --platform=$BUILDPLATFORM pscale.dev/wolfi-prod/go:1.23 AS builder
3-
ARG TARGETOS
4-
ARG TARGETARCH
5-
63
WORKDIR /work
7-
COPY . /work
84

5+
RUN \
6+
--mount=type=cache,target=/go/pkg/mod,sharing=locked \
7+
--mount=type=bind,source=go.mod,target=go.mod \
8+
--mount=type=bind,source=go.sum,target=go.sum \
9+
go mod download
10+
11+
COPY . .
912
ENV CGO_ENABLED=0
10-
RUN GOOS=${TARGETOS} GOOARCH=${TARGETARCH} go build -trimpath -v -o ./k8s-node-tagger .
13+
ARG TARGETOS
14+
ARG TARGETARCH
1115

12-
# -- runtime image: --
13-
FROM pscale.dev/wolfi-prod/static:latest
16+
RUN \
17+
--mount=type=cache,target=/root/.cache/go-build,sharing=locked \
18+
--mount=type=cache,target=/go/pkg/mod,sharing=locked \
19+
GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -trimpath -v -o ./k8s-node-tagger .
1420

21+
FROM pscale.dev/wolfi-prod/static:latest
1522
COPY --from=builder /work/k8s-node-tagger /k8s-node-tagger
16-
17-
ENTRYPOINT ["/k8s-node-tagger"]
23+
ENTRYPOINT ["/k8s-node-tagger"]

0 commit comments

Comments
 (0)