Skip to content

Commit

Permalink
ci: speedup docker builds with cache reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
joemiller committed Nov 8, 2024
1 parent 6a9e8a7 commit 1ef0b55
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 21 deletions.
47 changes: 34 additions & 13 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,51 @@ 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: 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
cache-to: type=gha,mode=max

- 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}}
23 changes: 15 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
# syntax=docker/dockerfile:1.9
FROM --platform=$BUILDPLATFORM pscale.dev/wolfi-prod/go:1.23 AS builder
FROM --platform=$BUILDPLATFORM pscale.dev/wolfi-prod/go:1.23 AS deps

ENV GOMODCACHE=/go/pkg/mod

WORKDIR /work

COPY go.mod go.sum ./

RUN go mod download

FROM deps AS builder
ARG TARGETOS
ARG TARGETARCH

WORKDIR /work
COPY . /work
COPY . .

ENV CGO_ENABLED=0
RUN GOOS=${TARGETOS} GOOARCH=${TARGETARCH} go build -trimpath -v -o ./k8s-node-tagger .
RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -trimpath -v -o ./k8s-node-tagger .

# -- runtime image: --
# --- runtime image ----
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"]

0 comments on commit 1ef0b55

Please sign in to comment.