Skip to content

Commit 49b103f

Browse files
committed
refactor: simpler dockerfile builder
Signed-off-by: peefy <[email protected]>
1 parent 953e32c commit 49b103f

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,6 @@ jobs:
8282
builder: ${{ steps.buildx.outputs.name }}
8383
context: .
8484
file: ./Dockerfile
85-
platforms: linux/amd64, linux/arm64
85+
platforms: linux/amd64
8686
tags: ${{ steps.meta.outputs.tags }}
8787
labels: ${{ steps.meta.outputs.labels }}

Dockerfile

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,43 @@
1+
# We use the Go 1.22 version unless asked to use something else.
2+
# The GitHub Actions CI job sets this argument for a consistent Go version.
13
ARG GO_VERSION=1.22
4+
ARG BASE_IMAGE=kcllang/kcl
25

6+
# Setup the base environment. The BUILDPLATFORM is set automatically by Docker.
7+
# The --platform=${BUILDPLATFORM} flag tells Docker to build the function using
8+
# the OS and architecture of the host running the build, not the OS and
9+
# architecture that we're building the function for.
310
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION} as build
411

512
COPY / /src
613
WORKDIR /src
714

15+
ENV CGO_ENABLED=0
16+
17+
# We run go mod download in a separate step so that we can cache its results.
18+
# This lets us avoid re-downloading modules if we don't need to. The type=target
19+
# mount tells Docker to mount the current directory read-only in the WORKDIR.
20+
# The type=cache mount tells Docker to cache the Go modules cache across builds.
21+
RUN --mount=target=. --mount=type=cache,target=/go/pkg/mod go mod download
22+
823
# The TARGETOS and TARGETARCH args are set by docker. We set GOOS and GOARCH to
924
# these values to ask Go to compile a binary for these architectures. If
1025
# TARGETOS and TARGETOS are different from BUILDPLATFORM, Go will cross compile
1126
# for us (e.g. compile a linux/amd64 binary on a linux/arm64 build machine).
1227
ARG TARGETOS
1328
ARG TARGETARCH
1429

15-
# build
16-
ENV CGO_ENABLED=0
17-
RUN go build -a -o kcl-controller cmd/main.go
18-
19-
FROM kcllang/kcl
30+
# Build the function binary. The type=target mount tells Docker to mount the
31+
# current directory read-only in the WORKDIR. The type=cache mount tells Docker
32+
# to cache the Go modules cache across builds.
33+
RUN --mount=target=. \
34+
--mount=type=cache,target=/go/pkg/mod \
35+
--mount=type=cache,target=/root/.cache/go-build \
36+
GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -a -o kcl-controller cmd/main.go
2037

38+
FROM ${BASE_IMAGE} as image
2139
RUN apt-get update && apt-get install -y ca-certificates tini
22-
2340
COPY --from=build /src/kcl-controller /usr/local/bin/
24-
2541
# RUN addgroup -S controller && adduser -S controller -G controller
2642
RUN groupadd controller && useradd -g controller controller
2743

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,7 @@ nginx-deployment-1 1/1 1 0 4s
112112
```
113113

114114
kcl-controller creates a `nginx-deployment-1` according to the KCL program in the repository.
115+
116+
git tag v0.3.1
117+
git push origin v0.3.1
118+
gh release create v0.3.1 --draft --generate-notes --title "v0.3.1 Release"

0 commit comments

Comments
 (0)