-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
66 lines (53 loc) · 2.08 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
FROM golang:1.14 as build
WORKDIR /go/src/app
# Create appuser to isolate potential vulnerabilities
# See https://stackoverflow.com/a/55757473/12429735RUN
ENV USER=appuser
ENV UID=10001
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
"${USER}"
# Update ca-certificates, for final stage.
RUN apt-get update && apt-get install -y ca-certificates
# Build
RUN CGO_ENABLED=0 go get -u github.com/vmware/govmomi/vcsim
###############################################################################
# final stage
FROM scratch
# Allow container to use latest TLS certificates
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
# Copy over appuser to run as non-root
COPY --from=build /etc/passwd /etc/passwd
COPY --from=build /etc/group /etc/group
# Copy over the /tmp directory for golang/os.TmpDir
COPY --chown=appuser --from=build /tmp /tmp
# Run all commands as non-root
USER appuser:appuser
# Build arguments for consistency
ARG APPLICATION="go-executable"
ARG BUILD_RFC3339="1970-01-01T00:00:00Z"
ARG COMMIT="local"
ARG DESCRIPTION="no description"
ARG VERSION="dirty"
# Labels for the container
LABEL org.opencontainers.image.ref.name="jnovack/${APPLICATION}" \
org.opencontainers.image.created=$BUILD_RFC3339 \
org.opencontainers.image.authors="Justin J. Novack <jnovack@gmail.com>" \
org.opencontainers.image.documentation="https://github.com/jnovack/${APPLICATION}/README.md" \
org.opencontainers.image.description="${DESCRIPTION}" \
org.opencontainers.image.licenses="MIT" \
org.opencontainers.image.source="https://github.com/jnovack/${APPLICATION}" \
org.opencontainers.image.revision=$COMMIT \
org.opencontainers.image.version=$VERSION \
org.opencontainers.image.url="https://hub.docker.com/r/jnovack/${APPLICATION}/"
# Application runs on local port
EXPOSE 8989
# Copy application from build stage
COPY --from=build /go/bin/${APPLICATION} /app
# Set entrypoint to application with container defaults
ENTRYPOINT ["/app", "-l", "0.0.0.0:8989"]