-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
57 lines (39 loc) · 1.46 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
49
50
51
52
53
# Inspired by https://chemidy.medium.com/create-the-smallest-and-secured-golang-docker-image-based-on-scratch-4752223b7324
# first, build the go binary
FROM 502859415194.dkr.ecr.us-east-1.amazonaws.com/golang:1.16.2-alpine as go
RUN apk update && apk add --no-cache git ca-certificates && update-ca-certificates
# Create appuser.
ENV USER=appuser
ENV UID=10001
# See https://stackoverflow.com/a/55757473/12429735RUN
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
"${USER}"
COPY . /go/src/github.com/briansimoni/stereodose
WORKDIR /go/src/github.com/briansimoni/stereodose
RUN CGO_ENABLED=0 GOOS=linux go build -mod=vendor -a -installsuffix cgo -o stereodose .
# next, install node_modules and run a build for react
FROM node:14-alpine as node
WORKDIR /stereodose/
COPY --from=go /go/src/github.com/briansimoni/stereodose/stereodose .
COPY --from=go /go/src/github.com/briansimoni/stereodose/app/views ./app/views/
WORKDIR /stereodose/app/views/
RUN npm install
RUN npm run build
RUN rm -rf node_modules
FROM scratch
# Import the user and group files from the builder.
COPY --from=go /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=go /etc/passwd /etc/passwd
COPY --from=go /etc/group /etc/group
WORKDIR /stereodose/
# Copy our static executable.
COPY --from=node /stereodose/ .
# Use an unprivileged user.
USER appuser:appuser
CMD ["./stereodose"]