Skip to content

Commit

Permalink
refactor: simpler dockerfile builder
Browse files Browse the repository at this point in the history
Signed-off-by: peefy <[email protected]>
  • Loading branch information
Peefy committed Aug 20, 2024
1 parent 24cdd82 commit 953e32c
Showing 1 changed file with 11 additions and 22 deletions.
33 changes: 11 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,37 +1,26 @@
ARG GO_VERSION=1.22
ARG XX_VERSION=1.2.1

FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION} as builder
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION} as build

# Copy the build utilities.
COPY --from=xx / /
COPY / /src
WORKDIR /src

ARG TARGETPLATFORM

WORKDIR /workspace

# copy modules manifests
COPY go.mod go.mod
COPY go.sum go.sum

# cache modules
RUN go mod download

# copy source code
COPY cmd/main.go cmd/main.go
COPY api/ api/
COPY internal/controller/ internal/controller/
# The TARGETOS and TARGETARCH args are set by docker. We set GOOS and GOARCH to
# these values to ask Go to compile a binary for these architectures. If
# TARGETOS and TARGETOS are different from BUILDPLATFORM, Go will cross compile
# for us (e.g. compile a linux/amd64 binary on a linux/arm64 build machine).
ARG TARGETOS
ARG TARGETARCH

# build
ENV CGO_ENABLED=0
RUN xx-go build -a -o kcl-controller cmd/main.go
RUN go build -a -o kcl-controller cmd/main.go

FROM kcllang/kcl

RUN apt-get update && apt-get install -y ca-certificates tini

COPY --from=builder /workspace/kcl-controller /usr/local/bin/
COPY --from=build /src/kcl-controller /usr/local/bin/

# RUN addgroup -S controller && adduser -S controller -G controller
RUN groupadd controller && useradd -g controller controller
Expand Down

0 comments on commit 953e32c

Please sign in to comment.