New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add black
Dockerfile
#1916
Add black
Dockerfile
#1916
Conversation
- Build a `black` container based on python3-slim - Test: `docker build --network-host --tag black .` ```console cooper-mbp1:black cooper$ docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE black latest 0c7636402ac2 4 seconds ago 332MB ``` Addresses part of #1914
Retested and rebased.
https://hub.docker.com/repository/docker/cooperlees/black/tags?page=1&ordering=last_updated |
When we land this I will look to automate a docker push + tagging for people to use (similar to bandersnatch) |
I'm sorry but I won't be able to review this since I have never used docker ... tip-toes away awkwardly |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to decrease layer size consider multi-stage setup or setup like
FROM python:3-slim
RUN mkdir /src
COPY . /src/
RUN cd /src && pip install --upgrade pip setuptools wheel && apt update && apt install -y git && pip install --no-cache-dir .[colorama,d] && rm -rf /src && apt remove -y git && apt autoremove -y && rm -rf /var/lib/apt/lists/*
CMD ["black"]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks reasonable to me but I have no real expertise on Docker.
Dockerfile
Outdated
@@ -0,0 +1,10 @@ | |||
FROM python:3-slim | |||
|
|||
RUN pip install --upgrade pip setuptools wheel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps also use --no-cache-dir
here?
- Combine the commands all into 1 RUN to down the size - Get to 65.98 MB image size now: https://hub.docker.com/repository/docker/cooperlees/black/tags?page=1&ordering=last_updated
Dockerfile
Outdated
&& pip install --no-cache-dir .[colorama,d] \ | ||
&& rm -rf /src \ | ||
&& apt remove -y git \ | ||
&& apt autoremove -y |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe add && rm -rf /var/lib/apt/lists/*
I had a quick look at the current state, and apart from
I shortened this list by adding That also cut 10s off the build by reducing the amount of stuff apt had to download, but the vast majority of time spent was in installing git, and it's not obvious why we need git installed here. Is it just a Deleting `/root/.cache`?For some reason,
I initially thought this would be fixed by Resulting layer tarstream non-directory entries:
I reckon that's as-minimal a layer as one could get from the python:3-slim base image. At this point, all the changes in Resulting Dockerfile: FROM python:3-slim
RUN mkdir /src
COPY . /src/
RUN pip install --no-cache-dir --disable-pip-version-check --upgrade pip setuptools wheel \
&& apt update && apt install --no-install-recommends -y git \
&& cd /src \
&& pip install --no-cache-dir --disable-pip-version-check .[colorama,d] \
&& rm -rf /src \
&& apt remove --purge -y git \
&& apt autoremove --purge -y \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /root/.cache
CMD ["black"] |
Ok, I feel I've waited long enough and had enough help from people. I'm going to merge this. |
black
container based on python3-slimdocker build --network-host --tag black .
Addresses part of #1914