Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize dockerfile #29

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
FROM alpine:3.19.0 as builder
# syntax=docker/dockerfile:1

WORKDIR /go/src/github.com/systemli/prometheus-mastodon-exporter
# Build the application from source
FROM golang:1.21.4 AS build-stage

ENV USER=appuser
ENV UID=10001
WORKDIR /app

RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
"${USER}"
COPY go.mod go.sum ./
RUN go mod download

RUN apk add --no-cache --update ca-certificates
COPY *.go ./

FROM scratch
RUN CGO_ENABLED=0 GOOS=linux go build -o /prometheus-mastodon-exporter

COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /etc/group /etc/group
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY prometheus-mastodon-exporter /prometheus-mastodon-exporter
# Run the tests in the container
FROM build-stage AS run-test-stage
RUN go test -v ./...

USER appuser:appuser
# Deploy the application binary into a lean image
FROM gcr.io/distroless/base-debian11 AS build-release-stage

WORKDIR /

COPY --from=build-stage /prometheus-mastodon-exporter /prometheus-mastodon-exporter

EXPOSE 13120

USER nonroot:nonroot

ENTRYPOINT ["/prometheus-mastodon-exporter"]