From 3c4a8f5495dc78cb9a02570f33cb963f218f22e9 Mon Sep 17 00:00:00 2001 From: Hector Date: Sat, 27 Mar 2021 17:29:28 +0000 Subject: [PATCH] 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. --- Dockerfile | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 61bcd90..1cb6bb5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # 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 WORKDIR /build @@ -11,12 +11,14 @@ RUN ln -s /go/src/ /build/src # Compile the tool using a Make command RUN make build/docker + +FROM debian:buster-slim + # Create main app folder to run from WORKDIR /app -# Move compiled binary to app folder and delete build folder -RUN mv /build/src/exporter /app/fail2ban-prometheus-exporter -RUN rm -rf /build +# Copy compiled binary to release image +COPY --from=build /build/src/exporter /app/fail2ban-prometheus-exporter # Copy init script into main app folder and set as entry point COPY docker/run.sh /app/