Skip to content

Commit

Permalink
build(performance): use docker RUN caching
Browse files Browse the repository at this point in the history
cache apt and pip calls though pip will not cache until we use venv

refs comses/planning#220

https://docs.docker.com/build/cache/#use-the-dedicated-run-cache
  • Loading branch information
alee committed Mar 14, 2024
1 parent 704d91e commit 2006ad5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
4 changes: 3 additions & 1 deletion base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ services:
vite:
condition: service_started
env_file:
- .env
- ./.env
- path: ./override.env
required: false

secrets:
db_password:
Expand Down
21 changes: 14 additions & 7 deletions django/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@ ARG REQUIREMENTS_FILE=requirements-dev.txt
ARG RUN_SCRIPT=./deploy/dev.sh
ARG UBUNTU_MIRROR=mirror.arizona.edu/ubuntu

RUN sed -i "s|archive.ubuntu.com|${UBUNTU_MIRROR}|" /etc/apt/sources.list \
&& apt-get update && apt-get install -y wget \
&& echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list \
&& wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
RUN rm -f /etc/apt/apt.conf.d/docker-clean; echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache
RUN --mount=type=cache,target=/var/lib/apt,sharing=locked \
--mount=type=cache,target=/var/cache/apt,sharing=locked \
sed -i "s|archive.ubuntu.com|${UBUNTU_MIRROR}|" /etc/apt/sources.list \
&& apt-get update && apt-get install -y --no-install-recommends curl ca-certificates \
&& install -d /usr/share/postgresql-common/pgdg && curl -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc --fail https://www.postgresql.org/media/keys/ACCC4CF8.asc \
&& echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list \
&& apt-get update \
&& apt-get install -y \
&& apt-get install -y --no-install-recommends \
autopostgresqlbackup \
binutils \
borgbackup \
clamav \
clamav-daemon \
curl \
gdal-bin \
git \
libffi-dev \
Expand All @@ -31,6 +33,7 @@ RUN sed -i "s|archive.ubuntu.com|${UBUNTU_MIRROR}|" /etc/apt/sources.list \
python3-gdal \
python3-pip \
python3-setuptools \
python3-venv \
unrar-free \
unzip \
&& update-alternatives --install /usr/bin/python python /usr/bin/python3 1000 \
Expand All @@ -42,7 +45,11 @@ RUN sed -i "s|archive.ubuntu.com|${UBUNTU_MIRROR}|" /etc/apt/sources.list \
&& apt-get autoremove -y && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

COPY ${REQUIREMENTS_FILE} requirements.txt /tmp/
RUN pip3 install -r /tmp/${REQUIREMENTS_FILE} --no-cache-dir

# FIXME: will need to change to user later
RUN --mount=type=cache,target=/root/.cache/pip,sharing=locked \
pip3 install -r /tmp/${REQUIREMENTS_FILE}

COPY ./deploy/cron.daily/* /etc/cron.daily/
COPY ./deploy/cron.hourly/* /etc/cron.hourly/
COPY ./deploy/cron.weekly/* /etc/cron.weekly/
Expand Down
2 changes: 1 addition & 1 deletion django/deploy/db/postgresql-backup-pre
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh

/usr/local/bin/inv -r /code db.pgpass > /var/log/db-backup.log 2>&1
/usr/local/bin/inv -r /code db.pgpass >> /shared/logs/db-backup.log 2>&1
2 changes: 1 addition & 1 deletion django/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ shortuuid==1.0.11
tzdata==2023.4
uwsgi==2.0.24
uwsgitop==0.11
wagtail==5.2.2
wagtail==5.2.3
# used for institution -> affiliation data migration, unused afterwards
fuzzywuzzy==0.18.0
invoke
Expand Down

0 comments on commit 2006ad5

Please sign in to comment.