-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
30 lines (24 loc) · 1.18 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
FROM golang:1
ENV PROJECT=go-fthealth
COPY . /${PROJECT}/
WORKDIR /${PROJECT}
ARG GITHUB_USERNAME
ARG GITHUB_TOKEN
RUN BUILDINFO_PACKAGE="github.com/Financial-Times/service-status-go/buildinfo." \
&& 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)" \
&& if [ ! -z ${GITHUB_USERNAME} ] && [ ! -z ${GITHUB_TOKEN} ]; then \
GOPRIVATE="github.com/Financial-Times" ; \
git config --global url."https://${GITHUB_USERNAME}:${GITHUB_TOKEN}@github.com".insteadOf "https://github.com" ; \
fi \
&& LDFLAGS="-s -w -X '"${BUILDINFO_PACKAGE}$VERSION"' -X '"${BUILDINFO_PACKAGE}$DATETIME"' -X '"${BUILDINFO_PACKAGE}$REPOSITORY"' -X '"${BUILDINFO_PACKAGE}$REVISION"' -X '"${BUILDINFO_PACKAGE}$BUILDER"'" \
&& CGO_ENABLED=0 go build -mod=readonly -a -o /artifacts/${PROJECT} -ldflags="${LDFLAGS}" \
&& echo "Build flags: ${LDFLAGS}"
# Multi-stage build - copy certs and the binary from the first stage
FROM scratch
WORKDIR /
COPY --from=0 /artifacts/* /
CMD [ "/go-fthealth" ]