-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: speedup docker builds with cache reuse
- Loading branch information
Showing
2 changed files
with
71 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,30 +31,75 @@ jobs: | |
fetch-depth: 0 | ||
|
||
- name: Calculate new version with autotag | ||
id: autotag | ||
run: | | ||
curl -sL https://git.io/autotag-install | sh -s -- -b "${RUNNER_TEMP}/bin" | ||
set -x | ||
version=$(${RUNNER_TEMP}/bin/autotag -n) | ||
echo "version=$version" >> $GITHUB_ENV | ||
echo "version=${version}" >> $GITHUB_OUTPUT | ||
- name: Cache | ||
uses: actions/cache@v3 | ||
id: cache | ||
with: | ||
path: | | ||
go-pkg-mod | ||
go-build | ||
key: cache-${{ hashFiles('./Dockerfile') }} | ||
|
||
- name: inject cache into docker | ||
uses: reproducible-containers/[email protected] | ||
with: | ||
cache-map: | | ||
{ | ||
"go-pkg-mod": "/go/pkg/mod", | ||
"go-build": "/root/.cache/go-build" | ||
} | ||
skip-extraction: ${{ steps.cache.outputs.cache-hit }} | ||
|
||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@988b5a0280414f521da01fcc63a27aeeb4b104db # v3 | ||
|
||
- name: Release | ||
- name: Build and push | ||
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5 | ||
with: | ||
context: . | ||
platforms: linux/amd64,linux/arm64 | ||
push: true | ||
tags: ghcr.io/planetscale/k8s-node-tagger:v${{ steps.autotag.outputs.version }} | ||
cache-from: | | ||
type=gha,scope=go-cache | ||
cache-to: | | ||
type=gha,mode=max,scope=go-cache | ||
- name: Create Release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
set -eou pipefail | ||
set -x | ||
gh release create "v${version}" \ | ||
--target main \ | ||
--title "v${version}" \ | ||
--generate-notes | ||
image="ghcr.io/planetscale/k8s-node-tagger:v${version}" | ||
# - name: Release | ||
# run: | | ||
# set -eou pipefail | ||
# set -x | ||
|
||
git reset --hard && git clean -ffdx && git pull | ||
# image="ghcr.io/planetscale/k8s-node-tagger:v${version}" | ||
|
||
docker buildx build \ | ||
-t "$image" \ | ||
--platform linux/amd64,linux/arm64 \ | ||
--push \ | ||
. | ||
# git reset --hard && git clean -ffdx && git pull | ||
|
||
gh release create "v${version}" --target main --title "v${version}" --generate-notes | ||
env: | ||
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} | ||
# docker buildx build \ | ||
# -t "$image" \ | ||
# --platform linux/amd64,linux/arm64 \ | ||
# --push \ | ||
# . | ||
|
||
# gh release create "v${version}" --target main --title "v${version}" --generate-notes | ||
# env: | ||
# GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
# syntax=docker/dockerfile:1.9 | ||
FROM --platform=$BUILDPLATFORM pscale.dev/wolfi-prod/go:1.23 AS builder | ||
ARG TARGETOS | ||
ARG TARGETARCH | ||
|
||
WORKDIR /work | ||
COPY . /work | ||
|
||
RUN --mount=type=cache,target=/go/pkg/mod \ | ||
--mount=type=bind,source=go.mod,target=go.mod \ | ||
--mount=type=bind,source=go.sum,target=go.sum \ | ||
go mod download | ||
|
||
COPY . . | ||
ENV CGO_ENABLED=0 | ||
RUN GOOS=${TARGETOS} GOOARCH=${TARGETARCH} go build -trimpath -v -o ./k8s-node-tagger . | ||
ARG TARGETOS | ||
ARG TARGETARCH | ||
|
||
# -- runtime image: -- | ||
FROM pscale.dev/wolfi-prod/static:latest | ||
RUN --mount=type=cache,target=/root/.cache/go-build \ | ||
--mount=type=cache,target=/go/pkg/mod \ | ||
GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -trimpath -v -o ./k8s-node-tagger . | ||
|
||
FROM pscale.dev/wolfi-prod/static:latest | ||
COPY --from=builder /work/k8s-node-tagger /k8s-node-tagger | ||
|
||
ENTRYPOINT ["/k8s-node-tagger"] | ||
ENTRYPOINT ["/k8s-node-tagger"] |