Skip to content

Commit 63655ff

Browse files
committed
build dockerfile with git releaser
1 parent 1ff4ab5 commit 63655ff

File tree

4 files changed

+115
-112
lines changed

4 files changed

+115
-112
lines changed

.github/workflows/docker.yml

Lines changed: 0 additions & 67 deletions
This file was deleted.

.github/workflows/release.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,22 @@ jobs:
2222
uses: actions/setup-go@v2
2323
with:
2424
go-version: 1.17
25+
-
26+
name: Docker Login
27+
uses: docker/login-action@v1
28+
with:
29+
registry: ghcr.io
30+
username: ${{ github.repository_owner }}
31+
password: ${{ secrets.GH_TOKEN }}
32+
-
33+
name: Login to Docker Hub
34+
uses: docker/login-action@v1
35+
with:
36+
username: ${{ secrets.DOCKERHUB_USERNAME }}
37+
password: ${{ secrets.DOCKERHUB_TOKEN }}
38+
-
39+
name: Docker Setup Buildx
40+
uses: docker/[email protected]
2541
-
2642
name: Run GoReleaser
2743
uses: goreleaser/goreleaser-action@v2

.goreleaser.yml

Lines changed: 92 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ before:
44
builds:
55
- env:
66
- CGO_ENABLED=0
7-
binary: rabbitmq_exporter-{{.Version}}.{{.Target}}
7+
#binary: rabbitmq_exporter-{{.Version}}.{{.Target}}
88
targets:
99
- linux_amd64
1010
- linux_arm64
@@ -28,4 +28,94 @@ changelog:
2828
- '^docs:'
2929
- '^test:'
3030
release:
31-
discussion_category_name: Announcements
31+
discussion_category_name: Announcements
32+
33+
dockers:
34+
- goos: linux
35+
goarch: amd64
36+
image_templates:
37+
- "kbudde/rabbitmq-exporter:linux-amd64-{{.ShortCommit}}"
38+
- "ghcr.io/kbudde/rabbitmq_exporter:linux-amd64-{{.ShortCommit}}"
39+
use: buildx
40+
build_flag_templates:
41+
- "--label=org.opencontainers.image.created={{.Date}}"
42+
- "--label=org.opencontainers.image.title={{.ProjectName}}"
43+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
44+
- "--label=org.opencontainers.image.version={{.Version}}"
45+
- "--label=org.opencontainers.image.source=https://github.com/kbudde/rabbitmq_exporter"
46+
- "--platform=linux/amd64"
47+
48+
- goos: linux
49+
goarch: arm
50+
goarm: 6
51+
image_templates:
52+
- "kbudde/rabbitmq-exporter:linux-arm6-{{.ShortCommit}}"
53+
- "ghcr.io/kbudde/rabbitmq_exporter:linux-arm6-{{.ShortCommit}}"
54+
use: buildx
55+
build_flag_templates:
56+
- "--label=org.opencontainers.image.created={{.Date}}"
57+
- "--label=org.opencontainers.image.title={{.ProjectName}}"
58+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
59+
- "--label=org.opencontainers.image.version={{.Version}}"
60+
- "--label=org.opencontainers.image.source=https://github.com/kbudde/rabbitmq_exporter"
61+
- "--platform=linux/arm/v6"
62+
63+
- goos: linux
64+
goarch: arm
65+
goarm: 7
66+
image_templates:
67+
- "kbudde/rabbitmq-exporter:linux-arm7-{{.ShortCommit}}"
68+
- "ghcr.io/kbudde/rabbitmq_exporter:linux-arm7-{{.ShortCommit}}"
69+
use: buildx
70+
build_flag_templates:
71+
- "--label=org.opencontainers.image.created={{.Date}}"
72+
- "--label=org.opencontainers.image.title={{.ProjectName}}"
73+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
74+
- "--label=org.opencontainers.image.version={{.Version}}"
75+
- "--label=org.opencontainers.image.source=https://github.com/kbudde/rabbitmq_exporter"
76+
- "--platform=linux/arm/v7"
77+
78+
- goos: linux
79+
goarch: arm64
80+
image_templates:
81+
- "kbudde/rabbitmq-exporter:linux-arm64-{{.ShortCommit}}"
82+
- "ghcr.io/kbudde/rabbitmq_exporter:linux-arm64-{{.ShortCommit}}"
83+
use: buildx
84+
build_flag_templates:
85+
- "--label=org.opencontainers.image.created={{.Date}}"
86+
- "--label=org.opencontainers.image.title={{.ProjectName}}"
87+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
88+
- "--label=org.opencontainers.image.version={{.Version}}"
89+
- "--label=org.opencontainers.image.source=https://github.com/kbudde/rabbitmq_exporter"
90+
- "--platform=linux/arm64"
91+
92+
93+
docker_manifests:
94+
-
95+
name_template: ghcr.io/kbudde/rabbitmq_exporter:latest
96+
image_templates:
97+
- ghcr.io/kbudde/rabbitmq_exporter:linux-amd64-{{.ShortCommit}}
98+
- ghcr.io/kbudde/rabbitmq_exporter:linux-arm6-{{.ShortCommit}}
99+
- ghcr.io/kbudde/rabbitmq_exporter:linux-arm7-{{.ShortCommit}}
100+
- ghcr.io/kbudde/rabbitmq_exporter:linux-arm64-{{.ShortCommit}}
101+
-
102+
name_template: kbudde/rabbitmq-exporter:latest
103+
image_templates:
104+
- kbudde/rabbitmq-exporter:linux-amd64-{{.ShortCommit}}
105+
- kbudde/rabbitmq-exporter:linux-arm6-{{.ShortCommit}}
106+
- kbudde/rabbitmq-exporter:linux-arm7-{{.ShortCommit}}
107+
- kbudde/rabbitmq-exporter:linux-arm64-{{.ShortCommit}}
108+
-
109+
name_template: ghcr.io/kbudde/rabbitmq_exporter:{{.Version}}
110+
image_templates:
111+
- ghcr.io/kbudde/rabbitmq_exporter:linux-amd64-{{.ShortCommit}}
112+
- ghcr.io/kbudde/rabbitmq_exporter:linux-arm6-{{.ShortCommit}}
113+
- ghcr.io/kbudde/rabbitmq_exporter:linux-arm7-{{.ShortCommit}}
114+
- ghcr.io/kbudde/rabbitmq_exporter:linux-arm64-{{.ShortCommit}}
115+
-
116+
name_template: kbudde/rabbitmq-exporter:{{.Version}}
117+
image_templates:
118+
- kbudde/rabbitmq-exporter:linux-amd64-{{.ShortCommit}}
119+
- kbudde/rabbitmq-exporter:linux-arm6-{{.ShortCommit}}
120+
- kbudde/rabbitmq-exporter:linux-arm7-{{.ShortCommit}}
121+
- kbudde/rabbitmq-exporter:linux-arm64-{{.ShortCommit}}

Dockerfile

Lines changed: 7 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,32 @@
1-
# Accept the Go version for the image to be set as a build argument.
2-
ARG GO_VERSION=1.15
3-
# First stage: build the executable.
4-
FROM golang:${GO_VERSION}-alpine AS builder
5-
6-
ARG VERSION=""
7-
ARG BRANCH=""
8-
ARG COMMIT=""
9-
10-
11-
# Create the user and group files that will be used in the running container to
12-
# run the process as an unprivileged user.
13-
RUN mkdir /user && \
14-
echo 'nobody:x:65534:65534:nobody:/:' > /user/passwd && \
15-
echo 'nobody:x:65534:' > /user/group
1+
FROM alpine AS builder
162

173
# Install the Certificate-Authority certificates for the app to be able to make
184
# calls to HTTPS endpoints.
195
# Git is required for fetching the dependencies.
20-
RUN apk add --no-cache ca-certificates git
21-
22-
# Set the working directory outside $GOPATH to enable the support for modules.
23-
WORKDIR /src
24-
25-
# Fetch dependencies first; they are less susceptible to change on every build
26-
# and will therefore be cached for speeding up the next build
27-
COPY ./go.mod ./go.sum ./
28-
RUN go mod download
29-
30-
# Import the code from the context.
31-
COPY ./ ./
32-
33-
# Build the executable to `/app`. Mark the build as statically linked.
34-
RUN CGO_ENABLED=0 go build \
35-
-installsuffix 'static' \
36-
-ldflags "-X main.Revision=${COMMIT} \
37-
-X main.Branch=${BRANCH} \
38-
-X main.Version=${VERSION} \
39-
-X main.BuildDate=$(date -u ""+%Y%m%d-%H:%M:%S"")" \
40-
-o /app .
6+
RUN apk add --no-cache ca-certificates
417

428
# Final stage: the running container.
439
FROM scratch AS final
4410

4511
# Add maintainer label in case somebody has questions.
4612
LABEL maintainer="[email protected]"
4713

48-
# Import the user and group files from the first stage.
49-
COPY --from=builder /user/group /user/passwd /etc/
50-
5114
# Import the Certificate-Authority certificates for enabling HTTPS.
5215
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
5316

5417
# Import the compiled executable from the first stage.
55-
COPY --from=builder /app /app
18+
COPY rabbitmq_exporter /rabbitmq_exporter
5619

5720
# Declare the port on which the webserver will be exposed.
5821
# As we're going to run the executable as an unprivileged user, we can't bind
5922
# to ports below 1024.
6023
EXPOSE 9419
6124

6225
# Perform any further action as an unprivileged user.
63-
USER nobody:nobody
26+
USER 65535:65535
6427

6528
# Check if exporter is alive; 10 retries gives prometheus some time to retrieve bad data (5 minutes)
66-
HEALTHCHECK --retries=10 CMD ["/app", "-check-url", "http://localhost:9419/health"]
29+
HEALTHCHECK --retries=10 CMD ["/rabbitmq_exporter", "-check-url", "http://localhost:9419/health"]
30+
6731
# Run the compiled binary.
68-
ENTRYPOINT ["/app"]
32+
ENTRYPOINT ["/rabbitmq_exporter"]

0 commit comments

Comments
 (0)