-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDockerfile
39 lines (27 loc) · 933 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
31
32
33
34
35
36
37
38
39
################################################################
# STEP 1 use a temporary image to build a static monolith binary
################################################################
FROM golang:1.17 AS builder
# Pull build dependencies
ENV GOPATH=$APP_ROOT
ENV GOBIN=$APP_ROOT/bin
USER root
WORKDIR $GOPATH/src/
COPY . .
RUN go mod download
# Build static image.
RUN go get -d github.com/alvaroloes/enumer && \
go generate ./... && \
GIT_SHA=$(git rev-parse --short HEAD) && \
CGO_ENABLED=1 GOARCH=amd64 GOOS=linux go build -a \
-ldflags "-extldflags '-static' -w -s -X main.appSha=$GIT_SHA" \
-o /opt/app-root/src/github.com/ignalina/shredder/shredder \
github.com/ignalina/shredder
FROM golang:1.17
USER root
RUN mkdir /app \
&& chown -R 1001:1001 /app
USER 1001
WORKDIR /opt/bin
COPY --from=builder /opt/app-root/src/github.com/ignalina/shredder/shredder /opt/bin/shredder
CMD /opt/bin/shredder