feat: improve docker run speeds

This commit is contained in:
tooboredtocode
2024-03-22 00:31:56 +01:00
parent db310c4076
commit 1235cb8da5
2 changed files with 30 additions and 11 deletions

View File

@@ -6,6 +6,8 @@ RUN apk add --no-cache postgresql-libs postgresql-client gettext zlib libjpeg li
#Print all logs without buffering it.
ENV PYTHONUNBUFFERED 1
ENV DOCKER true
#This port will be used by gunicorn.
EXPOSE 8080
@@ -23,18 +25,23 @@ RUN \
RUN sed -i '/# Development/,$d' requirements.txt
RUN apk add --no-cache --virtual .build-deps gcc musl-dev postgresql-dev zlib-dev jpeg-dev libwebp-dev openssl-dev libffi-dev cargo openldap-dev python3-dev && \
echo -n "INPUT ( libldap.so )" > /usr/lib/libldap_r.so && \
python -m venv venv && \
/opt/recipes/venv/bin/python -m pip install --upgrade pip && \
venv/bin/pip install wheel==0.42.0 && \
venv/bin/pip install setuptools_rust==1.9.0 && \
venv/bin/pip install -r requirements.txt --no-cache-dir &&\
python -m pip install --upgrade pip && \
pip install wheel==0.42.0 && \
pip install setuptools_rust==1.9.0 && \
pip install -r requirements.txt --no-cache-dir &&\
apk --purge del .build-deps
#Copy project and execute it.
COPY . ./
# collect the static files
RUN python manage.py collectstatic_js_reverse
RUN python manage.py collectstatic --noinput
# copy the collected static files to a different location, so they can be moved into a potentially mounted volume
RUN mv /opt/recipes/staticfiles /opt/recipes/staticfiles-collect
# collect information from git repositories
RUN /opt/recipes/venv/bin/python version.py
RUN python version.py
# delete git repositories to reduce image size
RUN find . -type d -name ".git" | xargs rm -rf

22
boot.sh
View File

@@ -1,5 +1,9 @@
#!/bin/sh
source venv/bin/activate
# conditionally activate virtualenv, since the docker container does not need it
if [[ "${DOCKER}" != "true" ]]; then
source venv/bin/activate
fi
TANDOOR_PORT="${TANDOOR_PORT:-8080}"
GUNICORN_WORKERS="${GUNICORN_WORKERS:-3}"
@@ -67,12 +71,20 @@ echo "Migrating database"
python manage.py migrate
echo "Generating static files"
if [[ "${DOCKER}" == "true" ]]; then
echo "Collecting static files"
python manage.py collectstatic_js_reverse
python manage.py collectstatic --noinput
mkdir -p /opt/recipes/staticfiles
mv /opt/recipes/staticfiles-collect/* /opt/recipes/staticfiles
rm -rf /opt/recipes/staticfiles-collect
else
echo "Generating static files"
echo "Done"
python manage.py collectstatic_js_reverse
python manage.py collectstatic --noinput
echo "Done"
fi
chmod -R 755 /opt/recipes/mediafiles