-
Notifications
You must be signed in to change notification settings - Fork 15
/
Dockerfile.tmplate
49 lines (42 loc) · 1.35 KB
/
Dockerfile.tmplate
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
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
RUN apk add --no-cache --update gcc make musl-dev
# Project to build
ARG BUILD
# Git commit SHA
ARG GIT_COMMIT_SHA
WORKDIR /repo
COPY go.* /repo/
COPY internal /repo/internal
COPY vendor /repo/vendor
COPY cmd/$BUILD /repo/cmd/$BUILD
# 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
RUN CGO_ENABLED=0 go install -a -ldflags "-X main.Prefix=${BUILD}/${GIT_COMMIT_SHA} -extldflags -static" /repo/cmd/${BUILD}
FROM ${RUNNER_IMAGE}
# Export a port, default to 8080
ARG EXPOSE_PORT=8080
EXPOSE $EXPOSE_PORT
# Add common resource for ssl and timezones from the build container
# Create a nobody user
# 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