-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDockerfile
executable file
·35 lines (28 loc) · 1.43 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
FROM golang:1
ENV PROJECT=upp-aggregate-healthcheck
ENV ORG_PATH="github.com/Financial-Times"
ENV SRC_FOLDER="${GOPATH}/src/${ORG_PATH}/${PROJECT}"
ENV BUILDINFO_PACKAGE="github.com/Financial-Times/service-status-go/buildinfo."
ARG GITHUB_USERNAME
ARG GITHUB_TOKEN
WORKDIR ${SRC_FOLDER}
# Build app
COPY . ${SRC_FOLDER}
RUN VERSION="version=$(git describe --tag --always 2> /dev/null)" \
&& DATETIME="dateTime=$(date -u +%Y%m%d%H%M%S)" \
&& REPOSITORY="repository=$(git config --get remote.origin.url)" \
&& REVISION="revision=$(git rev-parse HEAD)" \
&& BUILDER="builder=$(go version)" \
&& LDFLAGS="-s -w -X '"${BUILDINFO_PACKAGE}$VERSION"' -X '"${BUILDINFO_PACKAGE}$DATETIME"' -X '"${BUILDINFO_PACKAGE}$REPOSITORY"' -X '"${BUILDINFO_PACKAGE}$REVISION"' -X '"${BUILDINFO_PACKAGE}$BUILDER"'" \
&& git config --global url."https://${GITHUB_USERNAME}:${GITHUB_TOKEN}@github.com".insteadOf "https://github.com" \
&& CGO_ENABLED=0 go build -mod=readonly -a -o /artifacts/${PROJECT} -ldflags="${LDFLAGS}" \
&& cp -R resources /artifacts/resources \
&& cp -R html-templates /artifacts/html-templates
# Multi-stage build - copy only the certs and the binary into the image
FROM scratch
WORKDIR /
COPY --from=0 /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=0 /artifacts/* /
COPY --from=0 /artifacts/resources /resources
COPY --from=0 /artifacts/html-templates /html-templates
CMD [ "/upp-aggregate-healthcheck" ]