librecores / docker-images

CI Docker Images
MIT License
19 stars 8 forks source link

Avoid consecutive RUN commands in Dockerfiles #3

Closed andre-richter closed 7 years ago

andre-richter commented 7 years ago

https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/#apt-get

E.g. https://github.com/librecores/docker-images/blob/888a53b7d8540b0bde72b27a22151f3b1e0d54ae/librecores-ci/Dockerfile#L45

wallento commented 7 years ago

Thanks @andre-richter

I have fixed this accordingly, but I am not sure about one thing: In the tool installer dockers we use a base image (https://github.com/lccitools/base) and others that derive from that (e.g., https://github.com/lccitools/yosys). Should we delete the cache and do another update in there?

andre-richter commented 7 years ago

I'm not sure how your infrastructure looks like or if I got the question right. If we are talking local, just remove your containers docker rmi (maybe with -f) and rebuild everything.

andre-richter commented 7 years ago

Consolidating RUN commands is also advised for non-apt-get stuff. You still have a lot of consecutive RUN commands that can be merged. IIRC, each RUN command creates a new layer for the container. Finding a good balance between readability and layers is up to the user, though.

Here's a rather extreme example (e.g. https://github.com/tianon/gosu/blob/master/INSTALL.md).

wallento commented 7 years ago

We have the base image that is built on the default ubuntu image:

FROM ubuntu:16.04
[...]
RUN apt-get update && apt-get install -y \
    git python wget build-essential autoconf flex bison gperf

and then the actual tool installer images:

FROM lccitools/base:latest
[...]
RUN apt-get install -y \
    python3 gawk pkg-config tcl-dev libreadline-dev libffi-dev mercurial

Now I am wondering if we need to clear the cache after the first one or if that overall only leads to full reproducibility with version pinning..

wallento commented 7 years ago

Yeah, we actually prefered that so far to better keep track in git :)

andre-richter commented 7 years ago

Sorry, not sure myself.