-
Notifications
You must be signed in to change notification settings - Fork 10
/
Dockerfile
41 lines (34 loc) · 1.3 KB
/
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
31
32
33
34
35
36
37
38
39
40
41
ARG BASE_IMAGE
ARG BUILD_IMAGE
ARG ARCH=amd64
# Build the controller binary
FROM $BUILD_IMAGE as builder
WORKDIR /workspace
ENV GOPROXY direct
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
# 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
# Copy the go source
COPY .git/ .git/
COPY cmd/main.go cmd/main.go
COPY api/ api/
COPY pkg/ pkg/
COPY internal/ internal/
# Version package for passing the ldflags
# TODO: change this to network controller's version
ENV VERSION_PKG=github.com/aws/amazon-network-policy-controller-k8s/pkg/version
# Build
RUN GIT_VERSION=$(git describe --tags --always) && \
GIT_COMMIT=$(git rev-parse HEAD) && \
BUILD_DATE=$(date +%Y-%m-%dT%H:%M:%S%z) && \
CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} GO111MODULE=on go build \
-ldflags="-X ${VERSION_PKG}.GitVersion=${GIT_VERSION} -X ${VERSION_PKG}.GitCommit=${GIT_COMMIT} -X ${VERSION_PKG}.BuildDate=${BUILD_DATE}" -a -o controller cmd/main.go
FROM $BASE_IMAGE
WORKDIR /
COPY --from=public.ecr.aws/eks-distro/kubernetes/go-runner:v0.15.0-eks-1-27-3 /go-runner /usr/local/bin/go-runner
COPY --from=builder /workspace/controller .
USER 65532:65532
ENTRYPOINT ["/controller"]