forked from aws-controllers-k8s/community
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
35 lines (33 loc) · 1.23 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
# Build the manager binary
FROM golang:1.14.1 as builder
ARG service_alias
ARG work_dir=/github.com/aws/aws-controllers-k8s
WORKDIR $work_dir
# For building Go Module required
ENV GOPROXY=https://proxy.golang.org,direct
ENV GO111MODULE=on
ENV GOARCH=amd64
ENV GOOS=linux
ENV CGO_ENABLED=0
ENV VERSION_PKG=github.com/aws/aws-controllers-k8s/pkg/version
# 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 . $work_dir/
# Build
RUN GIT_VERSION=$(git describe --tags --dirty --always) && \
GIT_COMMIT=$(git rev-parse HEAD) && \
BUILD_DATE=$(date +%Y-%m-%dT%H:%M) && \
go build -ldflags="-X ${VERSION_PKG}.GitVersion=${GIT_VERSION} \
-X ${VERSION_PKG}.GitCommit=${GIT_COMMIT} \
-X ${VERSION_PKG}.BuildDate=${BUILD_DATE}" \
-a -o $work_dir/bin/controller $work_dir/services/$service_alias/cmd/controller/main.go
FROM amazonlinux:2
ARG work_dir=/github.com/aws/aws-controllers-k8s
WORKDIR /
COPY --from=builder $work_dir/bin/controller $work_dir/LICENSE $work_dir/ATTRIBUTION.md /bin/
ENTRYPOINT ["/bin/controller"]