-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathDockerfile_template
48 lines (40 loc) · 1.26 KB
/
Dockerfile_template
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
ARG BUILDER_IMAGE=ghcr.io/geonet/base-images/go:1.21
ARG RUNNER_IMAGE=ghcr.io/geonet/base-images/static:latest
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
# Project to build
ARG BUILD
ARG SOURCEPATH
# Git commit SHA
ARG GIT_COMMIT_SHA
COPY ${SOURCEPATH} /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 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
# 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} /${BUILD}
# Copy the assets
ARG ASSET_DIR
COPY ${ASSET_DIR} /assets
ARG RUN_USER=nobody
USER ${RUN_USER}
# Requires a CMD ["/${BUILD}"] appended by build.sh