Skip to content

Commit

Permalink
Use relative paths for python3 in venv
Browse files Browse the repository at this point in the history
Add the virtual env's bin directory to $PATH to allow relative paths for
python3 and coverage.
  • Loading branch information
jandd committed Oct 11, 2022
1 parent 989485d commit 0fd905b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@ RUN \
&& rm -rf /root/.cache /root/.local /tmp/*.json \
&& python3 -m pip uninstall --yes poetry

ENV PATH="/python-code/.venv/bin:$PATH"

COPY devday /app/
RUN set -eu ; \
cd /app ; \
echo 'SECRET_KEY="dummy"' > compilemessages_settings.py \
&& DJANGO_SETTINGS_MODULE=compilemessages_settings /python-code/.venv/bin/python3 manage.py compilemessages \
&& DJANGO_SETTINGS_MODULE=compilemessages_settings python3 manage.py compilemessages \
&& rm -rf compilemessages_settings.py __pycache__ /var/lib/apt/lists/*

FROM debian:bullseye-slim
Expand Down Expand Up @@ -129,4 +131,6 @@ RUN mkdir -p /app/media /app/static /app/logs ; \
VOLUME /app/media /app/static /app/logs
USER devday

ENV PATH="/python-code/.venv/bin:$PATH"

ENTRYPOINT ["dumb-init", "/app/start-application.sh"]
4 changes: 3 additions & 1 deletion app-dev.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,6 @@ EXPOSE 8000
VOLUME /app
WORKDIR /app

ENTRYPOINT ["dumb-init", "/python-code/.venv/bin/python3", "manage.py", "runserver", "0.0.0.0:8000"]
ENV PATH="/python-code/.venv/bin:$PATH"

ENTRYPOINT ["dumb-init", "python3", "manage.py", "runserver", "0.0.0.0:8000"]
4 changes: 2 additions & 2 deletions docker/app/start-application.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

set -eu

/python-code/.venv/bin/python3 manage.py migrate --noinput
/python-code/.venv/bin/python3 manage.py collectstatic --noinput
python3 manage.py migrate --noinput
python3 manage.py collectstatic --noinput
uwsgi --ini /app/uwsgi.ini
19 changes: 9 additions & 10 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ set -e
dbdump=''
mediadump=''
container='app'
container_python='/python-code/.venv/bin/python3'


setup_postgres_root_password() {
Expand Down Expand Up @@ -107,7 +106,7 @@ case "$cmd" in
echo "*** Starting all containers"
docker-compose up -d
fi
docker-compose exec "${container}" coverage run --branch manage.py test -v1 -k $@
docker-compose exec "${container}" coverage run --branch manage.py test -v1 --keepdb $@
docker-compose exec "${container}" coverage report -m
docker-compose exec "${container}" coverage html
;;
Expand All @@ -129,11 +128,11 @@ case "$cmd" in
setup_dev_env
docker-compose up -d
echo " Compiling translations"
docker-compose exec "${container}" "${container_python}" manage.py compilemessages
docker-compose exec "${container}" python3 manage.py compilemessages
echo " Running migrations"
docker-compose exec "${container}" "${container_python}" manage.py migrate
docker-compose exec "${container}" python3 manage.py migrate
echo " Filling database"
docker-compose exec "${container}" "${container_python}" manage.py devdata
docker-compose exec "${container}" python3 manage.py devdata
;;
docker-push)
if [ -n "$DOCKER_USERNAME" ]; then
Expand All @@ -148,11 +147,11 @@ case "$cmd" in
docker-compose logs -f "${container}"
;;
manage)
docker-compose exec "${container}" "${container_python}" manage.py $@
docker-compose exec "${container}" python3 manage.py $@
;;
messages)
docker-compose exec "${container}" "${container_python}" manage.py makemessages -l de --no-obsolete
docker-compose exec "${container}" "${container_python}" manage.py compilemessages -l de
docker-compose exec "${container}" python3 manage.py makemessages -l de --no-obsolete
docker-compose exec "${container}" python3 manage.py compilemessages -l de
;;
purge)
echo "*** Purge data"
Expand Down Expand Up @@ -182,7 +181,7 @@ case "$cmd" in
echo " Unpacking media dump"
docker-compose exec -T "${container}" tar xz -C /app/media < "${mediadump}"
echo "*** Running migrations"
docker-compose exec "${container}" "${container_python}" manage.py migrate
docker-compose exec "${container}" python3 manage.py migrate
echo "*** Import completed"
;;
shell)
Expand All @@ -206,7 +205,7 @@ case "$cmd" in
echo "*** Starting all containers"
docker-compose up -d
fi
docker-compose exec "${container}" "${container_python}" manage.py test -v1 -k $@
docker-compose exec "${container}" python3 manage.py test -v1 -k $@
;;
*)
echo -e "error: unknown action \"${cmd}\":\n" >&2
Expand Down

0 comments on commit 0fd905b

Please sign in to comment.