You've already forked prometheus-fail2ban-exporter
feat: multi-stage build for container image
Adapt the Makefile and Dockerfile for a multi-stage build of the container image. It is now not anymore required to have go locally installed to build the container image. Inside the multi-stage build, the newly create make install command will be executed. The compbiled files will than be copied to a new base image with less dependencies. Further improvement would be to use instead of debian:10 scratch, because the application does not have any C dependencies (CGO_ENABLED=0). Additionally it is not possible to build the container image with alternative container runtimes like podman instead of docker. make build/container-image CONTAINER_RUNTIME=podman The used base image names are now defined as fully qualified image names (with registry host), to support local container registry mirror configurations.
This commit is contained in:
23
Dockerfile
23
Dockerfile
@ -1,10 +1,19 @@
|
||||
FROM debian:buster-slim
|
||||
FROM docker.io/library/golang:1.20.5-buster AS build
|
||||
|
||||
# Create main app folder to run from
|
||||
WORKDIR /app
|
||||
WORKDIR /workspace
|
||||
ADD . /workspace
|
||||
|
||||
# Copy compiled binary to release image
|
||||
# (must build the binary before running docker build)
|
||||
COPY fail2ban_exporter /app/fail2ban_exporter
|
||||
RUN apt update --yes && \
|
||||
apt install --yes build-essential && \
|
||||
make install \
|
||||
PREFIX=/usr \
|
||||
DESTDIR=/app \
|
||||
EXECUTABLE=fail2ban_exporter
|
||||
|
||||
ENTRYPOINT ["/app/fail2ban_exporter"]
|
||||
FROM docker.io/library/debian:10-slim
|
||||
|
||||
COPY --from=build /app /
|
||||
|
||||
EXPOSE 9191
|
||||
|
||||
ENTRYPOINT [ "/usr/bin/fail2ban_exporter" ]
|
||||
|
Reference in New Issue
Block a user