This repository has been archived by the owner on Jan 3, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
FROM golang:alpine as builder | ||
|
||
ENV CGO_ENABLED=0 | ||
ENV GOOS=linux | ||
ENV GOARCH=amd64 | ||
ENV GO111MODULE=on | ||
|
||
RUN apk update && apk add --no-cache git ca-certificates tzdata && update-ca-certificates | ||
|
||
RUN adduser -D -g '' appuser | ||
|
||
ADD . ${GOPATH}/src/app/ | ||
WORKDIR ${GOPATH}/src/app | ||
|
||
RUN go build -a -installsuffix cgo -ldflags="-w -s" -o /go/bin/speedtest_exporter | ||
|
||
FROM scratch | ||
ARG VCS_REF | ||
ARG BUILD_DATE | ||
|
||
LABEL org.label-schema.build-date=$BUILD_DATE \ | ||
org.label-schema.vcs-ref=$VCS_REF \ | ||
org.label-schema.vcs-url="https://github.com/nlamirault/speedtest_exporter" \ | ||
org.label-schema.docker.cmd="docker run tnwhitwell/speedtest_exporter" \ | ||
org.label-schema.schema-version="1.0" \ | ||
maintainer="tom@whi.tw" | ||
|
||
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo | ||
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ | ||
COPY --from=builder /etc/passwd /etc/passwd | ||
|
||
COPY --from=builder /go/bin/speedtest_exporter /go/bin/speedtest_exporter | ||
|
||
USER appuser | ||
|
||
ENTRYPOINT [ "/go/bin/speedtest_exporter" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
# $IMAGE_NAME var is injected into the build so the tag is correct. | ||
docker build --build-arg VCS_REF=`git rev-parse --short HEAD` \ | ||
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \ | ||
-t $IMAGE_NAME . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
docker tag $IMAGE_NAME $DOCKER_REPO:$SOURCE_COMMIT | ||
docker push $DOCKER_REPO:$SOURCE_COMMIT | ||
export GO_VERSION=$(cat version/version.go | awk 'match($0, /[0-9].[0-9].[0-9]/) {print substr( $0, RSTART, RLENGTH )}') | ||
docker tag $IMAGE_NAME $DOCKER_REPO:${GO_VERSION} | ||
docker push $DOCKER_REPO:${GO_VERSION} |