Skip to content

Commit

Permalink
Reduce docker container from 776.9MB to 246.6MB (uncompressed) (mozil…
Browse files Browse the repository at this point in the history
…la-releng#153). r=bhearsum

Each command in a Dockerfile creates a new layer. To keep the final
docker image small build dependencies must be removed in the same
Dockerfile command. Removing data in separate commands does not make
the final image smaller.

This commit uses the above technique for adding and building with pip+gcc
and node+npm dependencies. It also adds a few extra cleanup commands for
files in /root/cache/.pip, /root/.npm and /tmp/phantomjs.
  • Loading branch information
mostlygeek authored and bhearsum committed Oct 19, 2016
1 parent 281a2ba commit c2f64e2
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ MAINTAINER [email protected]
# Node and npm are to build the frontend. nodejs-legacy is needed by this version of npm. These will get removed after building.
# libmysqlclient-dev is required to use SQLAlchemy with MySQL, which we do in production.
RUN apt-get -q update \
&& apt-get -q --yes install libpcre3 libpcre3-dev nodejs nodejs-legacy npm libmysqlclient-dev \
&& apt-get -q --yes install libpcre3 libpcre3-dev libmysqlclient-dev \
&& apt-get clean

WORKDIR /app
Expand All @@ -15,7 +15,12 @@ WORKDIR /app
# these rarely change and is more cache friendly
# ... really speeds up building new containers
COPY requirements.txt /app/
RUN pip install -r requirements.txt
RUN apt-get install -q --yes gcc && \
pip install -r requirements.txt && \
apt-get -q --yes remove gcc && \
apt-get -q --yes autoremove && \
apt-get clean && \
rm -rf /root/.cache

# Copying Balrog to /app instead of installing it means that production can run
# it, and we can bind mount to override it for local development.
Expand All @@ -24,19 +29,19 @@ COPY ui/ /app/ui/
COPY uwsgi/ /app/uwsgi/
COPY scripts/manage-db.py scripts/run-batch-deletes.sh scripts/run.sh /app/scripts/
COPY version.json /app/
RUN rm -rf /app/auslib/test

WORKDIR /app/ui
RUN npm install
RUN npm run build

RUN find . -maxdepth 1 -not -name dist -exec rm -rf {} \;

RUN apt-get -q --yes remove nodejs nodejs-legacy npm \
&& apt-get clean

WORKDIR /app

RUN cd ui && \
apt-get -q --yes install nodejs nodejs-legacy npm && \
npm install && \
npm run build && \
apt-get -q --yes remove nodejs nodejs-legacy npm && \
apt-get -q --yes autoremove && \
apt-get clean && \
rm -rf /root/.npm /tmp/phantomjs && \
find . -maxdepth 1 -not -name dist -exec rm -rf {} \;

# Using /bin/bash as the entrypoint works around some volume mount issues on Windows
# where volume-mounted files do not have execute bits set.
# https://github.com/docker/compose/issues/2301#issuecomment-154450785 has additional background.
Expand Down

0 comments on commit c2f64e2

Please sign in to comment.