Skip to content

Commit

Permalink
Use multi-stage building to eliminate multiple layers of the Docker i…
Browse files Browse the repository at this point in the history
…mage which are not needed
  • Loading branch information
stumpylog committed Nov 15, 2023
1 parent 46d9533 commit 95dcfc3
Showing 1 changed file with 47 additions and 18 deletions.
65 changes: 47 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
ARG ARCH
FROM ${ARCH}python:3.11-slim
FROM python:3.11-slim as base

# set version label
ARG BUILD_DATE
Expand All @@ -14,20 +13,56 @@ ENV APPRISE_CONFIG_DIR /config
ENV APPRISE_ATTACH_DIR /attach
ENV APPRISE_PLUGIN_PATHS /plugin

# Install nginx, supervisord, and cryptography dependencies
RUN apt-get update -qq && \
apt-get install -y -qq nginx supervisor git curl \
build-essential libffi-dev libssl-dev pkg-config python3-dev
FROM base as builder

WORKDIR /build/

# Cryptography documents that the latest version of pip3 must always be used
RUN pip3 install --upgrade pip
# Install nginx, supervisord, and cryptography dependencies
RUN set -eux && \
echo "Installing build dependencies" && \
apt-get update -qq && \
apt-get install -y -qq \
curl \
build-essential \
libffi-dev \
libssl-dev \
pkg-config && \
echo "Updating pip and getting requirements to build" && \
# Cryptography documents that the latest version of pip3 must always be used
python3 -m pip install --upgrade \
pip \
wheel && \
echo "Installing latest rustc" && \
# Pull in bleeding edge of rust to keep up with cryptography build requirements
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal && \
. "$HOME/.cargo/env" && \
echo "Buildingcryptography" && \
python3 -m pip wheel \
--no-binary cryptography \
cryptography

# Pull in bleeding edge of rust to keep up with cryptography build requirements
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
FROM base as runtime

# Install requirements and gunicorn
COPY ./requirements.txt /etc/requirements.txt
RUN . "$HOME/.cargo/env" && pip3 install --no-cache-dir -q -r /etc/requirements.txt gunicorn --no-binary cryptography
COPY --from=builder /build/*.whl .
RUN set -eux && \
echo "Installing cryptography" && \
pip3 install *.whl && \
echo "Installing python requirements" && \
pip3 install --no-cache-dir -q -r /etc/requirements.txt gunicorn supervisor && \
echo "Installing nginx" && \
apt-get update -qq && \
apt-get install -y -qq \
nginx && \
echo "Cleaning up" && \
apt-get --yes autoremove --purge && \
apt-get clean --yes && \
rm --recursive --force --verbose /var/lib/apt/lists/* && \
rm --recursive --force --verbose /tmp/* && \
rm --recursive --force --verbose /var/tmp/* && \
rm --recursive --force --verbose /var/cache/apt/archives/* && \
truncate --size 0 /var/log/*log

# Copy our static content in place
COPY apprise_api/static /usr/share/nginx/html/s/
Expand All @@ -38,12 +73,6 @@ WORKDIR /opt/apprise
# Copy over Apprise API
COPY apprise_api/ webapp

# Cleanup
RUN . "$HOME/.cargo/env" && rustup self uninstall -y && \
apt-get remove -y -qq curl build-essential libffi-dev libssl-dev python3-dev pkg-config && \
apt-get clean autoclean && \
apt-get autoremove --yes && \
rm -rf /var/lib/{apt,dpkg,cache,log}/
#
# # Configuration Permissions (to run nginx as a non-root user)
RUN umask 0002 && \
Expand All @@ -56,4 +85,4 @@ VOLUME /config
VOLUME /attach
VOLUME /plugin
EXPOSE 8000
CMD ["/usr/bin/supervisord", "-c", "/opt/apprise/webapp/etc/supervisord.conf"]
CMD ["/usr/local/bin/supervisord", "-c", "/opt/apprise/webapp/etc/supervisord.conf"]

0 comments on commit 95dcfc3

Please sign in to comment.