-
Notifications
You must be signed in to change notification settings - Fork 0
/
Popular.Dockerfile
49 lines (39 loc) · 1.1 KB
/
Popular.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
49
##################
# Go app builder #
##################
FROM golang:1.14.2-alpine3.11 AS builder
# Create archuser
ENV USER=archuser
ENV UID=10001
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
"${USER}"
WORKDIR /go/src/github.com/ilya-shikhaleev/arch-course/
COPY . .
# Download modules needed to build
RUN GOOS=linux GOARCH=amd64 go list ./cmd/popular && go mod verify
# Check code
RUN CGO_ENABLED=0 go test -v ./... \
&& CGO_ENABLED=0 go vet ./...
# Build application
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o ./bin/popular ./cmd/popular
###################
# Small app image #
###################
FROM scratch
# Import user and group from the builder
COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /etc/group /etc/group
# Enviroment variables for application
ENV PORT 8000
EXPOSE $PORT
COPY --from=builder /go/src/github.com/ilya-shikhaleev/arch-course/bin/popular .
# Use archuser
USER archuser:archuser
#ENTRYPOINT ["./popular"]
CMD ["./popular"]