forked from kbudde/rabbitmq_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
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
4 changed files
with
115 additions
and
112 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -22,6 +22,22 @@ jobs: | |
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.17 | ||
- | ||
name: Docker Login | ||
uses: docker/login-action@v1 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GH_TOKEN }} | ||
- | ||
name: Login to Docker Hub | ||
uses: docker/login-action@v1 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
- | ||
name: Docker Setup Buildx | ||
uses: docker/[email protected] | ||
- | ||
name: Run GoReleaser | ||
uses: goreleaser/goreleaser-action@v2 | ||
|
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
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 |
---|---|---|
@@ -1,68 +1,32 @@ | ||
# Accept the Go version for the image to be set as a build argument. | ||
ARG GO_VERSION=1.15 | ||
# First stage: build the executable. | ||
FROM golang:${GO_VERSION}-alpine AS builder | ||
|
||
ARG VERSION="" | ||
ARG BRANCH="" | ||
ARG COMMIT="" | ||
|
||
|
||
# Create the user and group files that will be used in the running container to | ||
# run the process as an unprivileged user. | ||
RUN mkdir /user && \ | ||
echo 'nobody:x:65534:65534:nobody:/:' > /user/passwd && \ | ||
echo 'nobody:x:65534:' > /user/group | ||
FROM alpine AS builder | ||
|
||
# Install the Certificate-Authority certificates for the app to be able to make | ||
# calls to HTTPS endpoints. | ||
# Git is required for fetching the dependencies. | ||
RUN apk add --no-cache ca-certificates git | ||
|
||
# Set the working directory outside $GOPATH to enable the support for modules. | ||
WORKDIR /src | ||
|
||
# Fetch dependencies first; they are less susceptible to change on every build | ||
# and will therefore be cached for speeding up the next build | ||
COPY ./go.mod ./go.sum ./ | ||
RUN go mod download | ||
|
||
# Import the code from the context. | ||
COPY ./ ./ | ||
|
||
# Build the executable to `/app`. Mark the build as statically linked. | ||
RUN CGO_ENABLED=0 go build \ | ||
-installsuffix 'static' \ | ||
-ldflags "-X main.Revision=${COMMIT} \ | ||
-X main.Branch=${BRANCH} \ | ||
-X main.Version=${VERSION} \ | ||
-X main.BuildDate=$(date -u ""+%Y%m%d-%H:%M:%S"")" \ | ||
-o /app . | ||
RUN apk add --no-cache ca-certificates | ||
|
||
# Final stage: the running container. | ||
FROM scratch AS final | ||
|
||
# Add maintainer label in case somebody has questions. | ||
LABEL maintainer="[email protected]" | ||
|
||
# Import the user and group files from the first stage. | ||
COPY --from=builder /user/group /user/passwd /etc/ | ||
|
||
# Import the Certificate-Authority certificates for enabling HTTPS. | ||
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ | ||
|
||
# Import the compiled executable from the first stage. | ||
COPY --from=builder /app /app | ||
COPY rabbitmq_exporter /rabbitmq_exporter | ||
|
||
# Declare the port on which the webserver will be exposed. | ||
# As we're going to run the executable as an unprivileged user, we can't bind | ||
# to ports below 1024. | ||
EXPOSE 9419 | ||
|
||
# Perform any further action as an unprivileged user. | ||
USER nobody:nobody | ||
USER 65535:65535 | ||
|
||
# Check if exporter is alive; 10 retries gives prometheus some time to retrieve bad data (5 minutes) | ||
HEALTHCHECK --retries=10 CMD ["/app", "-check-url", "http://localhost:9419/health"] | ||
HEALTHCHECK --retries=10 CMD ["/rabbitmq_exporter", "-check-url", "http://localhost:9419/health"] | ||
|
||
# Run the compiled binary. | ||
ENTRYPOINT ["/app"] | ||
ENTRYPOINT ["/rabbitmq_exporter"] |