-
Notifications
You must be signed in to change notification settings - Fork 4
/
Dockerfile
80 lines (62 loc) · 2.05 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
FROM node:14.2.0-alpine3.10 AS base
WORKDIR /app
COPY package.json .
RUN npm install
COPY *.* ./
FROM base AS develop
RUN mkdir public
ENTRYPOINT npm run dev_docker
FROM base AS builder
COPY src src
RUN npm run build
#build go static file server minimal image
#source: https://github.com/chemidy/smallest-secured-golang-docker-image/blob/master/go_module/Dockerfile
############################
# STEP 1 build executable binary
############################
# golang alpine 1.14.1
FROM golang@sha256:244a736db4a1d2611d257e7403c729663ce2eb08d4628868f9d9ef2735496659 as gobuilder
# Install git + SSL ca certificates.
# Git is required for fetching the dependencies.
# Ca-certificates is required to call HTTPS endpoints.
RUN apk update && apk add --no-cache git ca-certificates tzdata && update-ca-certificates
# Create appuser
ENV USER=appuser
ENV UID=10001
# See https://stackoverflow.com/a/55757473/12429735
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
"${USER}"
WORKDIR $GOPATH/src/mypackage/myapp/
# use modules
COPY server/go.mod .
ENV GO111MODULE=on
RUN go mod download
RUN go mod verify
COPY server/. .
# Build the binary
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-ldflags='-w -s -extldflags "-static"' -a \
-o /go/bin/visense-frontend .
############################
# STEP 2 build a small image
############################
FROM scratch AS production
# Import from builder.
COPY --from=gobuilder /usr/share/zoneinfo /usr/share/zoneinfo
COPY --from=gobuilder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=gobuilder /etc/passwd /etc/passwd
COPY --from=gobuilder /etc/group /etc/group
# Copy our static executable
COPY --from=gobuilder /go/bin/visense-frontend /go/bin/visense-frontend
# Use an unprivileged user. commented out because of access to ssh certificates
#USER appuser:appuser
#Copy the vue static files
COPY --from=builder /app/dist /static
# Run the hello binary.
ENTRYPOINT ["/go/bin/visense-frontend"]