2022-02-09 15:17:50 +08:00
ARG BASE_IMAGE
2020-07-06 23:45:29 +08:00
# Build the manager binary
2023-07-04 15:39:58 +08:00
FROM golang:1.19-alpine3.18 as builder
2020-07-06 23:45:29 +08:00
WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
2021-11-09 13:06:55 +08:00
# It's a proxy for CN developer, please unblock it if you have network issue
2021-12-28 10:26:07 +08:00
ARG GOPROXY
2023-06-15 14:50:20 +08:00
ENV GOPROXY = ${ GOPROXY :- https : //proxy.golang.org }
2021-11-09 13:06:55 +08:00
2020-07-06 23:45:29 +08:00
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download
2022-11-28 17:56:38 +08:00
# Copy the go source for building core
COPY cmd/core/ cmd/core/
2020-11-27 11:02:02 +08:00
COPY apis/ apis/
2020-08-18 11:00:18 +08:00
COPY pkg/ pkg/
2020-12-04 16:15:00 +08:00
COPY version/ version/
2022-02-17 13:58:48 +08:00
COPY references/ references/
2020-07-06 23:45:29 +08:00
# Build
2020-11-19 14:02:27 +08:00
ARG TARGETARCH
2020-12-04 16:15:00 +08:00
ARG VERSION
ARG GITVERSION
2021-04-09 20:12:57 +08:00
RUN GO111MODULE = on CGO_ENABLED = 0 GOOS = linux GOARCH = ${ TARGETARCH } \
go build -a -ldflags " -s -w -X github.com/oam-dev/kubevela/version.VelaVersion= ${ VERSION :- undefined } -X github.com/oam-dev/kubevela/version.GitRevision= ${ GITVERSION :- undefined } " \
2022-11-28 17:56:38 +08:00
-o manager-${ TARGETARCH } cmd/core/main.go
2020-07-06 23:45:29 +08:00
2021-04-09 20:12:57 +08:00
# Use alpine as base image due to the discussion in issue #1448
2021-03-15 12:24:12 +08:00
# You can replace distroless as minimal base image to package the manager binary
2020-07-06 23:45:29 +08:00
# Refer to https://github.com/GoogleContainerTools/distroless for more details
2021-04-09 20:12:57 +08:00
# Overwrite `BASE_IMAGE` by passing `--build-arg=BASE_IMAGE=gcr.io/distroless/static:nonroot`
2023-07-04 15:39:58 +08:00
FROM ${BASE_IMAGE:-alpine:3.18}
2022-05-26 10:27:31 +08:00
# This is required by daemon connecting with cri
2022-02-09 15:17:50 +08:00
RUN apk add --no-cache ca-certificates bash expat
2020-11-19 14:02:27 +08:00
2020-07-06 23:45:29 +08:00
WORKDIR /
2020-11-19 14:02:27 +08:00
ARG TARGETARCH
2021-04-09 20:12:57 +08:00
COPY --from= builder /workspace/manager-${ TARGETARCH } /usr/local/bin/manager
2020-07-06 23:45:29 +08:00
2021-04-09 20:12:57 +08:00
COPY entrypoint.sh /usr/local/bin/
ENTRYPOINT [ "entrypoint.sh" ]
CMD [ "manager" ]