From 70c8974865a467099f178f628953d93cc53031df Mon Sep 17 00:00:00 2001 From: Falahati Date: Thu, 17 Nov 2022 14:44:14 +0330 Subject: [PATCH] faster and more efficient docker file --- Dockerfile | 55 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/Dockerfile b/Dockerfile index 487fe7fc..90c71c7d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,23 +1,32 @@ -FROM alpine:latest as build - -ADD . /sslh - -RUN \ - apk add \ - gcc \ - libconfig-dev \ - make \ - musl-dev \ - pcre2-dev \ - perl && \ - cd /sslh && \ - make sslh-select && \ - strip sslh-select - -FROM alpine:latest - -COPY --from=build /sslh/sslh-select /sslh - -RUN apk --no-cache add libconfig pcre2 - -ENTRYPOINT [ "/sslh", "--foreground"] +########################################################################################## +## BUILD APPLICATION +########################################################################################## +FROM alpine:latest as build + +# install required packages first to be able to take advantage of caching +RUN apk add \ + gcc \ + libconfig-dev \ + make \ + musl-dev \ + pcre2-dev \ + perl + +# copy files and build the app +WORKDIR /sslh +ADD . . +RUN make sslh-select && \ + strip sslh-select + + +########################################################################################## +## PACKAGE APPLICATION +########################################################################################## +FROM alpine:latest + +# install required packages first and in parallel with the build container execution +RUN apk --no-cache add libconfig pcre2 + +# copy the final executable from the build container +COPY --from=build /sslh/sslh-select /sslh +ENTRYPOINT [ "/sslh", "--foreground"]