-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
48 lines (42 loc) · 1.5 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
42
43
44
45
46
47
48
FROM golang:1.14.12-alpine3.11 as base
RUN apk add --update --no-cache make bash curl git build-base
ENV PATH=/go/bin:$PATH
# Build the manager binary
FROM base as builder
# Use nonroot user for building container & running CI (some tests assume running as non-root)
ENV USER dev
ENV HOME /home/dev
RUN adduser dev --disabled-password --home $HOME
RUN mkdir /workspace && chown dev:dev /workspace
USER dev
ENV GOPATH=/go
WORKDIR /workspace
# Copy the Go Modules manifests
COPY --chown=dev:dev go.mod go.mod
COPY --chown=dev:dev 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 --chown=dev:dev main.go main.go
COPY --chown=dev:dev pkg/ pkg/
COPY --chown=dev:dev cmd/ cmd/
# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o build/app main.go
# Make CI
FROM builder as ci
COPY Makefile Makefile
ARG GO111MODULE=on
# Fail if any files are not gofmt'd
RUN fmtFiles=$(go fmt ./...); test -z $fmtFiles || (echo "**** Need to run go fmt on: $fmtFiles ****" && exit 1)
# Install deps
RUN go install
RUN mcq setup
RUN mcq ci
# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot as final
WORKDIR /
COPY --chown=nonroot:nonroot --from=builder /workspace/build/app .
USER nonroot:nonroot
ENTRYPOINT ["/app"]