build: rework dockerfile for development use only

This commit is contained in:
Thibault VINCENT
2022-09-17 14:12:20 +02:00
parent e5ff47e3d0
commit 2446ce6dc7

View File

@@ -1,10 +1,9 @@
## Build Stage
# https://github.com/hadolint/hadolint/issues/861
# hadolint ignore=DL3029
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.18.6-alpine as build
ARG TARGETOS
ARG TARGETARCH
WORKDIR $GOPATH/src/github.com/enix/x509-certificate-exporter
COPY go.mod go.mod
@@ -15,10 +14,15 @@ RUN go mod download
COPY internal internal
COPY cmd cmd
ARG VERSION="devel"
ARG VCS_REF="unknown"
ARG TARGETOS
ARG TARGETARCH
ENV GOOS=${TARGETOS}
ENV GOARCH=${TARGETARCH}
ARG VERSION="0.0.0"
RUN go build -v \
-tags netgo,osusergo \
-ldflags "-X \"github.com/enix/x509-certificate-exporter/v3/internal.Version=${VERSION}\" \
-X \"github.com/enix/x509-certificate-exporter/v3/internal.CommitHash=${VCS_REF}\" \
@@ -28,25 +32,12 @@ ARG VERSION="0.0.0"
## Production Stage
LABEL maintainer="Enix <no-reply@enix.fr>" \
org.opencontainers.image.title="X.509 Certificate Exporter" \
org.opencontainers.image.description="A Prometheus exporter for certificates focusing on expiration monitoring." \
org.opencontainers.image.url="https://github.com/enix/x509-certificate-exporter" \
org.opencontainers.image.sources="https://github.com/enix/x509-certificate-exporter/blob/master/Dockerfile" \
org.opencontainers.image.documentation="https://github.com/enix/x509-certificate-exporter/blob/master/README.md" \
org.opencontainers.image.authors="Enix <no-reply@enix.fr>" \
org.opencontainers.image.licenses="MIT"
FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:3.14.7
# https://github.com/hadolint/hadolint/issues/861
# hadolint ignore=DL3029
FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:3.16.2
COPY --from=build /go/src/github.com/enix/x509-certificate-exporter/x509-certificate-exporter /x509-certificate-exporter
EXPOSE 9793/tcp
ENTRYPOINT [ "/x509-certificate-exporter" ]
#ARG VCS_REF
#ARG BUILD_DATE
LABEL org.opencontainers.image.version="$VERSION"
# org.opencontainers.image.revision="$VCS_REF" \
# org.opencontainers.image.created="$BUILD_DATE"