Skip to content

Commit 39d863f

Browse files
authored
Run application from uv (#257)
* Run application from `uv` When running on Ubuntu 24.04, we cannot use `--system` anymore because pip complains about it. I understand we are forced to create a virtualenv when creating the Docker image. Due to that, we need to run our application using that virtualenv we created at build time. We use `uv run` for that. * Run our tasks with `uv run` * Remove install from common.sh
1 parent be3f268 commit 39d863f

File tree

6 files changed

+16
-16
lines changed

6 files changed

+16
-16
lines changed

dockerfiles/entrypoints/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# Ref https://docs.celeryq.dev/en/stable/userguide/workers.html#persistent-revokes.
1010
CELERY_STATE_DIR=/var/run/celery/
1111
mkdir -p $CELERY_STATE_DIR
12-
CMD="python3 -m celery -A ${CELERY_APP_NAME}.worker worker -Ofair -c 1 -Q builder,celery,default,build01,build:default,build:large -l ${CELERY_LOG_LEVEL} --statedb=${CELERY_STATE_DIR}worker.state"
12+
CMD="uv run python3 -m celery -A ${CELERY_APP_NAME}.worker worker -Ofair -c 1 -Q builder,celery,default,build01,build:default,build:large -l ${CELERY_LOG_LEVEL} --statedb=${CELERY_STATE_DIR}worker.state"
1313

1414
if [ -n "${DOCKER_NO_RELOAD}" ]; then
1515
echo "Running process with no reload"

dockerfiles/entrypoints/celery-beat.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
../../docker/common.sh
44

5-
CMD="python3 -m celery -A ${CELERY_APP_NAME}.worker beat -l ${CELERY_LOG_LEVEL}"
5+
CMD="uv run python3 -m celery -A ${CELERY_APP_NAME}.worker beat -l ${CELERY_LOG_LEVEL}"
66

77
# Not sure why, but the db becomes corrupted at some point
88
# and make the startup of this process to fail.

dockerfiles/entrypoints/celery.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ if [ "$SEARCH" != "" ]; then
88
../../docker/wait-for-it.sh search:9200 --timeout=180 --strict
99
fi
1010

11-
CMD="python3 -m celery -A ${CELERY_APP_NAME}.worker worker -Ofair -c 2 -Q web,web01,reindex,autoscaling -l ${CELERY_LOG_LEVEL}"
11+
CMD="uv run python3 -m celery -A ${CELERY_APP_NAME}.worker worker -Ofair -c 2 -Q web,web01,reindex,autoscaling -l ${CELERY_LOG_LEVEL}"
1212

1313
if [ -n "${DOCKER_NO_RELOAD}" ]; then
1414
echo "Running process with no reload"

dockerfiles/entrypoints/proxito.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
../../docker/common.sh
44

5-
CMD="gunicorn readthedocs.wsgi:application -w 3 -b 0.0.0.0:8000 --max-requests=10000 --timeout=0"
5+
CMD="uv run gunicorn readthedocs.wsgi:application -w 3 -b 0.0.0.0:8000 --max-requests=10000 --timeout=0"
66

77
if [ -n "${DOCKER_NO_RELOAD}" ]; then
88
echo "Running process with no reload"

dockerfiles/entrypoints/web.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ if [ -n "$INIT" ];
66
then
77
echo "Performing initial tasks..."
88
../../docker/createbuckets.sh
9-
python3 manage.py migrate
10-
python3 manage.py migrate --database telemetry
11-
cat ../../docker/createsuperuser.py | python3 manage.py shell
12-
python3 manage.py collectstatic --no-input
13-
python3 manage.py loaddata test_data
9+
uv run python3 manage.py migrate
10+
uv run python3 manage.py migrate --database telemetry
11+
cat ../../docker/createsuperuser.py | uv run python3 manage.py shell
12+
uv python3 manage.py collectstatic --no-input
13+
uv run python3 manage.py loaddata test_data
1414
fi
1515

16-
CMD="gunicorn readthedocs.wsgi:application -w 3 -b 0.0.0.0:8000 --max-requests=10000 --timeout=0"
16+
CMD="uv run gunicorn readthedocs.wsgi:application -w 3 -b 0.0.0.0:8000 --max-requests=10000 --timeout=0"
1717

1818
if [ -n "${DOCKER_NO_RELOAD}" ]; then
1919
echo "Running process with no reload"

dockerfiles/tasks.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def manage(c, command, running=True, backupdb=False):
141141
if backupdb:
142142
c.run(f'{DOCKER_COMPOSE_COMMAND} {subcmd} database pg_dumpall -c -U docs_user > dump_`date +%d-%m-%Y"_"%H_%M_%S`__`git rev-parse HEAD`.sql', pty=True)
143143

144-
c.run(f'{DOCKER_COMPOSE_COMMAND} {subcmd} web python3 manage.py {command}', pty=True)
144+
c.run(f'{DOCKER_COMPOSE_COMMAND} {subcmd} web uv run python3 manage.py {command}', pty=True)
145145

146146
@task(help={
147147
'container': 'Container to attach',
@@ -196,7 +196,7 @@ def test(c, arguments='', running=True):
196196
def buildassets(c):
197197
"""Build all assets for the application and push them to backend storage"""
198198
c.run(f'docker compose -f {DOCKER_COMPOSE_ASSETS} run --rm assets bash -c "npm ci && node_modules/bower/bin/bower --allow-root update && npm run build"', pty=True)
199-
c.run(f'{DOCKER_COMPOSE_COMMAND} run --rm web python3 manage.py collectstatic --noinput', pty=True)
199+
c.run(f'{DOCKER_COMPOSE_COMMAND} run --rm web uv run python3 manage.py collectstatic --noinput', pty=True)
200200

201201

202202
@task(help={
@@ -221,13 +221,13 @@ def translations(c, action):
221221

222222
if action == 'pull':
223223
c.run(f'{DOCKER_COMPOSE_COMMAND} run --rm web ./tx --token {transifex_token} pull --force', pty=True)
224-
c.run(f'{DOCKER_COMPOSE_COMMAND} run --rm web /bin/bash -c "cd readthedocs/ && python3 ../manage.py makemessages --all"', pty=True)
225-
c.run(f'{DOCKER_COMPOSE_COMMAND} run --rm web /bin/bash -c "cd readthedocs/ && python3 ../manage.py compilemessages"', pty=True)
224+
c.run(f'{DOCKER_COMPOSE_COMMAND} run --rm web /bin/bash -c "cd readthedocs/ && uv run python3 ../manage.py makemessages --all"', pty=True)
225+
c.run(f'{DOCKER_COMPOSE_COMMAND} run --rm web /bin/bash -c "cd readthedocs/ && uv run python3 ../manage.py compilemessages"', pty=True)
226226

227227
elif action == 'push':
228-
c.run(f'{DOCKER_COMPOSE_COMMAND} run --rm web /bin/bash -c "cd readthedocs/ && python3 ../manage.py makemessages --locale en"', pty=True)
228+
c.run(f'{DOCKER_COMPOSE_COMMAND} run --rm web /bin/bash -c "cd readthedocs/ && uv run python3 ../manage.py makemessages --locale en"', pty=True)
229229
c.run(f'{DOCKER_COMPOSE_COMMAND} run --rm web ./tx --token {transifex_token} push --source', pty=True)
230-
c.run(f'{DOCKER_COMPOSE_COMMAND} run --rm web /bin/bash -c "cd readthedocs/ && python3 ../manage.py compilemessages --locale en"', pty=True)
230+
c.run(f'{DOCKER_COMPOSE_COMMAND} run --rm web /bin/bash -c "cd readthedocs/ && uv run python3 ../manage.py compilemessages --locale en"', pty=True)
231231

232232

233233
@task(help={

0 commit comments

Comments
 (0)