build: split docker build into two images (#9)

Update the docker build file to use two images - one for building, and one
for running/deployment. This helps reduce the size of the final image.
This commit is contained in:
Hector 2021-03-27 17:29:28 +00:00
parent 3de54b0b71
commit 3c4a8f5495

View file

@ -1,5 +1,5 @@
# Using golang:latest instead of alpine because of issues with sqlite3 # Using golang:latest instead of alpine because of issues with sqlite3
FROM golang:latest FROM golang:latest AS build
# Create build folder to compile tool # Create build folder to compile tool
WORKDIR /build WORKDIR /build
@ -11,12 +11,14 @@ RUN ln -s /go/src/ /build/src
# Compile the tool using a Make command # Compile the tool using a Make command
RUN make build/docker RUN make build/docker
FROM debian:buster-slim
# Create main app folder to run from # Create main app folder to run from
WORKDIR /app WORKDIR /app
# Move compiled binary to app folder and delete build folder # Copy compiled binary to release image
RUN mv /build/src/exporter /app/fail2ban-prometheus-exporter COPY --from=build /build/src/exporter /app/fail2ban-prometheus-exporter
RUN rm -rf /build
# Copy init script into main app folder and set as entry point # Copy init script into main app folder and set as entry point
COPY docker/run.sh /app/ COPY docker/run.sh /app/