diff mbox

[v2,05/21] docker: compact debian base

Message ID 20170508221759.15616-6-f4bug@amsat.org
State New
Headers show

Commit Message

Philippe Mathieu-Daudé May 8, 2017, 10:17 p.m. UTC
- install common/basic tools at once
- use eatmydata and remove apt cache to save space
- add bison and flex and git
- create deb-src entry and setup Emdebian in the same layer

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 tests/docker/dockerfiles/debian.docker | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

Comments

Fam Zheng May 9, 2017, 4:04 a.m. UTC | #1
On Mon, 05/08 19:17, Philippe Mathieu-Daudé wrote:
> - install common/basic tools at once
> - use eatmydata and remove apt cache to save space
> - add bison and flex and git
> - create deb-src entry and setup Emdebian in the same layer
> 
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
>  tests/docker/dockerfiles/debian.docker | 26 +++++++++++++-------------
>  1 file changed, 13 insertions(+), 13 deletions(-)
> 
> diff --git a/tests/docker/dockerfiles/debian.docker b/tests/docker/dockerfiles/debian.docker
> index d08def6a8d..dcded3ce84 100644
> --- a/tests/docker/dockerfiles/debian.docker
> +++ b/tests/docker/dockerfiles/debian.docker
> @@ -9,17 +9,17 @@
>  #
>  FROM debian:stable-slim
>  
> -# Setup some basic tools we need
> -RUN apt update
> -RUN apt install -yy aptitude ca-certificates curl
> +# Install some basic tools and common build utilities
> +RUN apt-get update && \
> +    DEBIAN_FRONTEND=noninteractive apt-get install -yy \
> +        eatmydata && \
> +    DEBIAN_FRONTEND=noninteractive eatmydata apt-get install -y --no-install-recommends \
> +        aptitude ca-certificates curl \
> +        build-essential clang git \
> +        bison flex && \
> +    apt-get clean

Any particular reason to make multiple "RUN" directives into one?

Fam

>  
> -# Setup Emdebian
> -RUN echo "deb http://emdebian.org/tools/debian/ jessie main" >> /etc/apt/sources.list
> -RUN curl http://emdebian.org/tools/debian/emdebian-toolchain-archive.key | apt-key add -
> -
> -# Duplicate deb line as deb-src
> -RUN cat /etc/apt/sources.list | sed "s/deb/deb-src/" >> /etc/apt/sources.list
> -
> -# Install common build utilities
> -RUN apt update
> -RUN apt install -yy build-essential clang
> +# Duplicate deb line as deb-src, setup Emdebian
> +RUN cat /etc/apt/sources.list | sed "s/deb/deb-src/" >> /etc/apt/sources.list && \
> +    echo "deb http://emdebian.org/tools/debian/ jessie main" >> /etc/apt/sources.list && \
> +    curl http://emdebian.org/tools/debian/emdebian-toolchain-archive.key | apt-key add -
> -- 
> 2.11.0
>
Alex Bennée May 9, 2017, 7:46 a.m. UTC | #2
Fam Zheng <famz@redhat.com> writes:

> On Mon, 05/08 19:17, Philippe Mathieu-Daudé wrote:
>> - install common/basic tools at once
>> - use eatmydata and remove apt cache to save space
>> - add bison and flex and git
>> - create deb-src entry and setup Emdebian in the same layer
>>
>> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
>> ---
>>  tests/docker/dockerfiles/debian.docker | 26 +++++++++++++-------------
>>  1 file changed, 13 insertions(+), 13 deletions(-)
>>
>> diff --git a/tests/docker/dockerfiles/debian.docker b/tests/docker/dockerfiles/debian.docker
>> index d08def6a8d..dcded3ce84 100644
>> --- a/tests/docker/dockerfiles/debian.docker
>> +++ b/tests/docker/dockerfiles/debian.docker
>> @@ -9,17 +9,17 @@
>>  #
>>  FROM debian:stable-slim
>>
>> -# Setup some basic tools we need
>> -RUN apt update
>> -RUN apt install -yy aptitude ca-certificates curl
>> +# Install some basic tools and common build utilities
>> +RUN apt-get update && \
>> +    DEBIAN_FRONTEND=noninteractive apt-get install -yy \
>> +        eatmydata && \
>> +    DEBIAN_FRONTEND=noninteractive eatmydata apt-get install -y --no-install-recommends \
>> +        aptitude ca-certificates curl \
>> +        build-essential clang git \
>> +        bison flex && \
>> +    apt-get clean
>
> Any particular reason to make multiple "RUN" directives into one?

It reduces the number of layers you generate during the building
process. I'm not sure how much space that saves in the long run though
(disk space is pretty cheap ;-).

>
> Fam
>
>>
>> -# Setup Emdebian
>> -RUN echo "deb http://emdebian.org/tools/debian/ jessie main" >> /etc/apt/sources.list
>> -RUN curl http://emdebian.org/tools/debian/emdebian-toolchain-archive.key | apt-key add -
>> -
>> -# Duplicate deb line as deb-src
>> -RUN cat /etc/apt/sources.list | sed "s/deb/deb-src/" >> /etc/apt/sources.list
>> -
>> -# Install common build utilities
>> -RUN apt update
>> -RUN apt install -yy build-essential clang
>> +# Duplicate deb line as deb-src, setup Emdebian
>> +RUN cat /etc/apt/sources.list | sed "s/deb/deb-src/" >> /etc/apt/sources.list && \
>> +    echo "deb http://emdebian.org/tools/debian/ jessie main" >> /etc/apt/sources.list && \
>> +    curl http://emdebian.org/tools/debian/emdebian-toolchain-archive.key | apt-key add -
>> --
>> 2.11.0
>>


--
Alex Bennée
Fam Zheng May 9, 2017, 8:05 a.m. UTC | #3
On Tue, 05/09 08:46, Alex Bennée wrote:
> 
> Fam Zheng <famz@redhat.com> writes:
> 
> > On Mon, 05/08 19:17, Philippe Mathieu-Daudé wrote:
> >> - install common/basic tools at once
> >> - use eatmydata and remove apt cache to save space
> >> - add bison and flex and git
> >> - create deb-src entry and setup Emdebian in the same layer
> >>
> >> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> >> ---
> >>  tests/docker/dockerfiles/debian.docker | 26 +++++++++++++-------------
> >>  1 file changed, 13 insertions(+), 13 deletions(-)
> >>
> >> diff --git a/tests/docker/dockerfiles/debian.docker b/tests/docker/dockerfiles/debian.docker
> >> index d08def6a8d..dcded3ce84 100644
> >> --- a/tests/docker/dockerfiles/debian.docker
> >> +++ b/tests/docker/dockerfiles/debian.docker
> >> @@ -9,17 +9,17 @@
> >>  #
> >>  FROM debian:stable-slim
> >>
> >> -# Setup some basic tools we need
> >> -RUN apt update
> >> -RUN apt install -yy aptitude ca-certificates curl
> >> +# Install some basic tools and common build utilities
> >> +RUN apt-get update && \
> >> +    DEBIAN_FRONTEND=noninteractive apt-get install -yy \
> >> +        eatmydata && \
> >> +    DEBIAN_FRONTEND=noninteractive eatmydata apt-get install -y --no-install-recommends \
> >> +        aptitude ca-certificates curl \
> >> +        build-essential clang git \
> >> +        bison flex && \
> >> +    apt-get clean
> >
> > Any particular reason to make multiple "RUN" directives into one?
> 
> It reduces the number of layers you generate during the building
> process. I'm not sure how much space that saves in the long run though
> (disk space is pretty cheap ;-).

I don't think it matters much, but refreshing an image gets slower due to
coarser cache, for example when you add a package in the big "apt-get install"
command.

I don't see a strong reason why this is better. It clutters the file and is
inconsistent.
Philippe Mathieu-Daudé May 9, 2017, 12:06 p.m. UTC | #4
On 05/09/2017 05:05 AM, Fam Zheng wrote:
> On Tue, 05/09 08:46, Alex Bennée wrote:
>>
>> Fam Zheng <famz@redhat.com> writes:
>>
>>> On Mon, 05/08 19:17, Philippe Mathieu-Daudé wrote:
>>>> - install common/basic tools at once
>>>> - use eatmydata and remove apt cache to save space
>>>> - add bison and flex and git
>>>> - create deb-src entry and setup Emdebian in the same layer
>>>>
>>>> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
>>>> ---
>>>>  tests/docker/dockerfiles/debian.docker | 26 +++++++++++++-------------
>>>>  1 file changed, 13 insertions(+), 13 deletions(-)
>>>>
>>>> diff --git a/tests/docker/dockerfiles/debian.docker b/tests/docker/dockerfiles/debian.docker
>>>> index d08def6a8d..dcded3ce84 100644
>>>> --- a/tests/docker/dockerfiles/debian.docker
>>>> +++ b/tests/docker/dockerfiles/debian.docker
>>>> @@ -9,17 +9,17 @@
>>>>  #
>>>>  FROM debian:stable-slim
>>>>
>>>> -# Setup some basic tools we need
>>>> -RUN apt update
>>>> -RUN apt install -yy aptitude ca-certificates curl
>>>> +# Install some basic tools and common build utilities
>>>> +RUN apt-get update && \
>>>> +    DEBIAN_FRONTEND=noninteractive apt-get install -yy \
>>>> +        eatmydata && \
>>>> +    DEBIAN_FRONTEND=noninteractive eatmydata apt-get install -y --no-install-recommends \
>>>> +        aptitude ca-certificates curl \
>>>> +        build-essential clang git \
>>>> +        bison flex && \
>>>> +    apt-get clean
>>>
>>> Any particular reason to make multiple "RUN" directives into one?
>>
>> It reduces the number of layers you generate during the building
>> process. I'm not sure how much space that saves in the long run though
>> (disk space is pretty cheap ;-).
>
> I don't think it matters much, but refreshing an image gets slower due to
> coarser cache, for example when you add a package in the big "apt-get install"
> command.
>
> I don't see a strong reason why this is better. It clutters the file and is
> inconsistent.

I'm living in a remote place where Internet is pretty bad so it does 
save me some time to have reduced layer while using 'docker save | 
docker load', but no worry :)

I'll revert this patch and just add bison/flex/git packages, and 
eventually keep DEBIAN_FRONTEND=noninteractive to avoid harmless error 
messages.
Fam Zheng May 9, 2017, 12:18 p.m. UTC | #5
On Tue, 05/09 09:06, Philippe Mathieu-Daudé wrote:
> On 05/09/2017 05:05 AM, Fam Zheng wrote:
> > On Tue, 05/09 08:46, Alex Bennée wrote:
> > > 
> > > Fam Zheng <famz@redhat.com> writes:
> > > 
> > > > On Mon, 05/08 19:17, Philippe Mathieu-Daudé wrote:
> > > > > - install common/basic tools at once
> > > > > - use eatmydata and remove apt cache to save space
> > > > > - add bison and flex and git
> > > > > - create deb-src entry and setup Emdebian in the same layer
> > > > > 
> > > > > Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> > > > > ---
> > > > >  tests/docker/dockerfiles/debian.docker | 26 +++++++++++++-------------
> > > > >  1 file changed, 13 insertions(+), 13 deletions(-)
> > > > > 
> > > > > diff --git a/tests/docker/dockerfiles/debian.docker b/tests/docker/dockerfiles/debian.docker
> > > > > index d08def6a8d..dcded3ce84 100644
> > > > > --- a/tests/docker/dockerfiles/debian.docker
> > > > > +++ b/tests/docker/dockerfiles/debian.docker
> > > > > @@ -9,17 +9,17 @@
> > > > >  #
> > > > >  FROM debian:stable-slim
> > > > > 
> > > > > -# Setup some basic tools we need
> > > > > -RUN apt update
> > > > > -RUN apt install -yy aptitude ca-certificates curl
> > > > > +# Install some basic tools and common build utilities
> > > > > +RUN apt-get update && \
> > > > > +    DEBIAN_FRONTEND=noninteractive apt-get install -yy \
> > > > > +        eatmydata && \
> > > > > +    DEBIAN_FRONTEND=noninteractive eatmydata apt-get install -y --no-install-recommends \
> > > > > +        aptitude ca-certificates curl \
> > > > > +        build-essential clang git \
> > > > > +        bison flex && \
> > > > > +    apt-get clean
> > > > 
> > > > Any particular reason to make multiple "RUN" directives into one?
> > > 
> > > It reduces the number of layers you generate during the building
> > > process. I'm not sure how much space that saves in the long run though
> > > (disk space is pretty cheap ;-).
> > 
> > I don't think it matters much, but refreshing an image gets slower due to
> > coarser cache, for example when you add a package in the big "apt-get install"
> > command.
> > 
> > I don't see a strong reason why this is better. It clutters the file and is
> > inconsistent.
> 
> I'm living in a remote place where Internet is pretty bad so it does save me
> some time to have reduced layer while using 'docker save | docker load', but
> no worry :)

Shouldn't 'docker save' collapse the layers anyway and output final data?

On the contrary, Docker build cache saves me time too when I play with the
package list, as 'apt-get update' result is cached in a previous RUN directive,
and doesn't need to run again and again. (Yes, I live in a place where "apt-get
update" is slow :)

Fam
diff mbox

Patch

diff --git a/tests/docker/dockerfiles/debian.docker b/tests/docker/dockerfiles/debian.docker
index d08def6a8d..dcded3ce84 100644
--- a/tests/docker/dockerfiles/debian.docker
+++ b/tests/docker/dockerfiles/debian.docker
@@ -9,17 +9,17 @@ 
 #
 FROM debian:stable-slim
 
-# Setup some basic tools we need
-RUN apt update
-RUN apt install -yy aptitude ca-certificates curl
+# Install some basic tools and common build utilities
+RUN apt-get update && \
+    DEBIAN_FRONTEND=noninteractive apt-get install -yy \
+        eatmydata && \
+    DEBIAN_FRONTEND=noninteractive eatmydata apt-get install -y --no-install-recommends \
+        aptitude ca-certificates curl \
+        build-essential clang git \
+        bison flex && \
+    apt-get clean
 
-# Setup Emdebian
-RUN echo "deb http://emdebian.org/tools/debian/ jessie main" >> /etc/apt/sources.list
-RUN curl http://emdebian.org/tools/debian/emdebian-toolchain-archive.key | apt-key add -
-
-# Duplicate deb line as deb-src
-RUN cat /etc/apt/sources.list | sed "s/deb/deb-src/" >> /etc/apt/sources.list
-
-# Install common build utilities
-RUN apt update
-RUN apt install -yy build-essential clang
+# Duplicate deb line as deb-src, setup Emdebian
+RUN cat /etc/apt/sources.list | sed "s/deb/deb-src/" >> /etc/apt/sources.list && \
+    echo "deb http://emdebian.org/tools/debian/ jessie main" >> /etc/apt/sources.list && \
+    curl http://emdebian.org/tools/debian/emdebian-toolchain-archive.key | apt-key add -