forked from clusternet/clusternet
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDockerfile
30 lines (26 loc) · 772 Bytes
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
ARG BASEIMAGE
ARG GOVERSION
ARG LDFLAGS
ARG PKGNAME
# Build the manager binary
FROM --platform=$BUILDPLATFORM golang:${GOVERSION} as builder
# Copy in the go src
WORKDIR /go/src/github.com/clusternet/clusternet
COPY pkg pkg/
COPY cmd cmd/
COPY go.mod go.mod
COPY go.sum go.sum
ARG LDFLAGS
ARG PKGNAME
ARG TARGETOS
ARG TARGETARCH
# Build
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
GOOS=$TARGETOS GOARCH=$TARGETARCH go build -ldflags="${LDFLAGS}" -a -o ${PKGNAME} /go/src/github.com/clusternet/clusternet/cmd/${PKGNAME}
# Copy the cmd into a thin image
FROM ${BASEIMAGE}
WORKDIR /root
RUN apk add gcompat
ARG PKGNAME
COPY --from=builder /go/src/github.com/clusternet/clusternet/${PKGNAME} /usr/local/bin/${PKGNAME}