SEED-platform / seed

Standard Energy Efficiency Data (SEED) Platform™ is a web-based application that helps organizations easily manage data on the energy performance of large groups of buildings.
Other
106 stars 55 forks source link

Use Docker multi-stage builds #4632

Open axelstudios opened 2 months ago

axelstudios commented 2 months ago

Describe the bug With the latest release, the compressed Docker images have ballooned to 1.13 GB. We should be publishing minimal Docker images using multi-stage builds to remove development dependencies, and only keep the development dependencies when running tests via CI.

Expected Behavior The size, and contents, of the Docker image should be the minimal amount necessary to run SEED

Actual Behavior The Docker image has 25 layers, and is bloated with development dependencies, weighing in at 1.13 GB compressed, 2.8 GB uncompressed.

Layers

Size Layer Command
5.6 MB ADD file:9663235f252e072c52b0f9e25845841e4321cce2caa7467a0d736c6003b05c00 in /
0 B CMD ["/bin/sh"]
0 B ARG NGINX_LISTEN_OPTS
3 MB COPY /usr/lib /usr/lib # buildkit
11.1 MB COPY /usr/local/lib /usr/local/lib # buildkit
5.2 MB COPY /usr/local/include /usr/local/include # buildkit
99.4 MB COPY /usr/local/bin /usr/local/bin # buildkit
1.4 GB RUN |1 NGINX_LISTEN_OPTS= RUN apk add --no-cache python3-dev postgresql-dev coreutils alpine-sdk pcre pcre-dev libxslt-dev linux-headers libffi-dev bash bash-completion nginx openssl-dev geos-dev gdal gcc musl-dev cargo tzdata && ln -sf /usr/bin/python3 /usr/bin/python && python -m ensurepip && rm -r /usr/lib/python*/ensurepip && ln -sf /usr/bin/pip3 /usr/bin/pip && pip install --upgrade pip setuptools && pip install supervisor==4.2.5 && mkdir -p /var/log/supervisord && rm -r /root/.cache && addgroup -g 1000 uwsgi && adduser -G uwsgi -H -u 1000 -S uwsgi && mkdir -p /run/nginx # buildkit
0 B WORKDIR /seed
144 B COPY ./requirements.txt /seed/requirements.txt # buildkit
3.1 kB COPY ./requirements/*.txt /seed/requirements/ # buildkit
0 B RUN |1 NGINX_LISTEN_OPTS= RUN pip uninstall -y enum34 # buildkit
648.1 MB RUN |1 NGINX_LISTEN_OPTS= RUN pip install -r requirements/aws.txt # buildkit
1.7 kB COPY ./package.json /seed/package.json # buildkit
1.9 kB COPY ./vendors/package.json /seed/vendors/package.json # buildkit
3.4 kB COPY ./README.md /seed/README.md # buildkit
390.5 MB RUN |1 NGINX_LISTEN_OPTS= RUN npm install --unsafe-perm # buildkit
0 B WORKDIR /seed
249.6 MB COPY . /seed/ # buildkit
4.1 kB COPY ./docker/wait-for-it.sh /usr/local/wait-for-it.sh # buildkit
26 B RUN |1 NGINX_LISTEN_OPTS= RUN git config --system --add safe.directory /seed # buildkit
3.9 kB COPY ./docker/nginx/*.conf /etc/nginx/ # buildkit
5 kB COPY ./docker/nginx/nginx.conf.template /etc/nginx/nginx.conf.template # buildkit
4.8 MB RUN |1 NGINX_LISTEN_OPTS= RUN apk add --no-cache gettext && if [ -z "${NGINX_LISTEN_OPTS}" ]; then echo "NGINX_LISTEN_OPTS is unset or empty, defaulting to: HTTP1.1"; else echo "NGINX_LISTEN_OPTS is set to: ${NGINX_LISTEN_OPTS}"; fi && envsubst '${NGINX_LISTEN_OPTS}' < /etc/nginx/nginx.conf.template > /etc/nginx/nginx.conf # buildkit
0 B RUN |1 NGINX_LISTEN_OPTS= RUN ln -sf /seed/collected_static/maintenance.html /var/lib/nginx/html/maintenance.html # buildkit
0 B RUN |1 NGINX_LISTEN_OPTS= RUN chmod +x ./docker/maintenance.sh # buildkit
1.4 kB COPY ./docker/supervisor-seed.conf /etc/supervisor/supervisord.conf # buildkit
510 B COPY ./docker/seed-entrypoint.sh /usr/local/bin/seed-entrypoint # buildkit
510 B RUN |1 NGINX_LISTEN_OPTS= RUN chmod 775 /usr/local/bin/seed-entrypoint # buildkit
0 B ENTRYPOINT ["seed-entrypoint"]
0 B EXPOSE map[80/tcp:{}]
0 B CMD ["supervisord"]