forked from GeoNet/pagerduty-jobs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
53 lines (45 loc) · 1.45 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
ARG BUILDER_IMAGE=quay.io/geonet/golang:1.15-alpine
ARG RUNNER_IMAGE=quay.io/geonet/alpine:3.10
ARG RUN_USER=nobody
# Only support image based on AlpineLinux
FROM ${BUILDER_IMAGE} as builder
# Obtain ca-cert and tzdata, which we will add to the container
RUN apk add --update ca-certificates tzdata
# Project to build
ARG BUILD
# Git commit SHA
ARG GIT_COMMIT_SHA
COPY ./ /repo
WORKDIR /repo
# Set a bunch of go env flags
ENV GOBIN /repo/gobin
ENV GOPATH /usr/src/go
ENV GOFLAGS -mod=vendor
ENV GOOS linux
ENV GOARCH amd64
ENV CGO_ENABLED 0
RUN echo 'nobody:x:65534:65534:Nobody:/:\' > /passwd
RUN go install -a -installsuffix cgo -ldflags "-X main.Prefix=${BUILD}/${GIT_COMMIT_SHA}" /repo/cmd/${BUILD}
FROM ${RUNNER_IMAGE}
# Export a port, default to 8080
ARG EXPOSE_PORT=8080
EXPOSE $EXPOSE_PORT
# Asset directory to copy to /assets
# Add common resource for ssl and timezones from the build container
ADD ./ /
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
COPY --from=builder /passwd /etc/passwd
# Same ARG as before
ARG BUILD
# Need to make this an env for it to be interpolated by the shell
ENV TZ Pacific/Auckland
ENV BUILD_BIN=${BUILD}
# We have to make our binary have a fixed name, otherwise, we cannot run it without a shell
COPY --from=builder /repo/gobin/${BUILD} /app
# Copy the assets
ARG ASSET_DIR
COPY ${ASSET_DIR} /assets
ARG RUN_USER=nobody
USER ${RUN_USER}
ENTRYPOINT ["/app"]