Skip to content

Instantly share code, notes, and snippets.

@jtbonhomme
Last active July 20, 2019 18:15
Show Gist options
  • Save jtbonhomme/f83d8f7baf69058792cda7cd95b5f163 to your computer and use it in GitHub Desktop.
Save jtbonhomme/f83d8f7baf69058792cda7cd95b5f163 to your computer and use it in GitHub Desktop.
Dockerfile with version data injection
FROM docker.io/golang:1.11.4
# use go module by default
ENV GO111MODULE=on
# declare workdir, create if does not exist
WORKDIR /service/
# Copy current dir in workdir
COPY . .
# Build go executable
RUN CGO_ENABLED=0 GOOS=linux go build -o app -a -installsuffix cgo \
-ldflags "-X gitlab.private.fr/service.git/endpoint.GITCOMMIT=$(git describe --tags --match '[0-9]*\.[0-9]*\.[0-9]*') \
-X gitlab.private.fr/service.git/endpoint.CIJOB=${CI_JOB_ID} \
-X gitlab.private.fr/service.git/endpoint.BUILDTIME=$(date -u +%FT%T%z)" .
# Expose server listening port
FROM alpine:3.8
EXPOSE 8080
COPY --from=builder /service/app /app
RUN chmod +x /app
CMD ["/app"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment