From ab1348625ea83c831b9aa50aab7635d21246d3ba Mon Sep 17 00:00:00 2001 From: Ramon Wijnands Date: Tue, 3 Dec 2019 15:41:38 +0100 Subject: [PATCH 1/2] Fix black docker image builds The newest version of black broke our dockerfile because it requires gcc to be installed. I've modified the black Dockerfile to a two-staged such that the image size stays small. --- black/Dockerfile | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/black/Dockerfile b/black/Dockerfile index 5fcb246..e190d6b 100644 --- a/black/Dockerfile +++ b/black/Dockerfile @@ -1,10 +1,18 @@ +FROM python:3-alpine as black-build + +# we don't want gcc in the final image, so let's do a multi stage build +RUN apk update && apk add --no-cache build-base +RUN pip install --user --upgrade black + FROM python:3-alpine LABEL io.whalebrew.name 'black' LABEL io.whalebrew.config.working_dir '/workdir' WORKDIR /workdir -RUN pip install --upgrade black +# copy only the installed files from black +COPY --from=black-build /root/.local /root/.local +ENV PATH=/root/.local/bin:$PATH ENTRYPOINT ["black"] CMD ["--help"] \ No newline at end of file From de5c26ed4a996f3d0c3929314481ebd36427c453 Mon Sep 17 00:00:00 2001 From: Ramon Wijnands Date: Wed, 29 Jul 2020 11:05:05 +0200 Subject: [PATCH 2/2] Convert black back to a single stage based on review comments --- black/Dockerfile | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/black/Dockerfile b/black/Dockerfile index e190d6b..705e4d0 100644 --- a/black/Dockerfile +++ b/black/Dockerfile @@ -1,18 +1,13 @@ -FROM python:3-alpine as black-build - -# we don't want gcc in the final image, so let's do a multi stage build -RUN apk update && apk add --no-cache build-base -RUN pip install --user --upgrade black - FROM python:3-alpine LABEL io.whalebrew.name 'black' LABEL io.whalebrew.config.working_dir '/workdir' WORKDIR /workdir -# copy only the installed files from black -COPY --from=black-build /root/.local /root/.local -ENV PATH=/root/.local/bin:$PATH +# we don't want gcc in the final image, so remove it in one docker layer +RUN apk add --no-cache build-base \ + && pip install --no-cache-dir --upgrade black \ + && apk del build-base ENTRYPOINT ["black"] CMD ["--help"] \ No newline at end of file