|
1 | 1 | #!/bin/bash |
2 | 2 | set -e |
3 | 3 |
|
4 | | -source .venv/bin/activate |
5 | | - |
6 | | -# Function to check if migrations are needed |
7 | | -check_migrations_needed() { |
8 | | - python3 manage.py showmigrations --plan | grep -q '\[ \]' |
9 | | -} |
10 | | - |
11 | | -# Function to check if core app tables exist |
12 | | -check_core_tables_exist() { |
13 | | - python3 -c " |
14 | | -import os |
15 | | -import django |
16 | | -from django.db import connections |
17 | | -
|
18 | | -# Check that django settings module is set |
19 | | -if 'DJANGO_SETTINGS_MODULE' not in os.environ: |
20 | | - raise EnvironmentError('DJANGO_SETTINGS_MODULE environment variable is not set; set before running container') |
21 | | -
|
22 | | -django.setup() |
23 | | -
|
24 | | -try: |
25 | | - with connections['core'].cursor() as cursor: |
26 | | - cursor.execute(\"SELECT COUNT(*) FROM core_datasubmission\") |
27 | | - count = cursor.fetchone()[0] |
28 | | - exit(0 if count > 0 else 1) |
29 | | -except Exception: |
30 | | - exit(1) |
31 | | -" |
32 | | -} |
33 | | - |
34 | | -# Check if core tables exist and migrations are up to date |
35 | | -if check_core_tables_exist && ! check_migrations_needed; then |
36 | | - echo "Database already initialized and up to date" |
37 | | -else |
38 | | - echo "Running database migrations..." |
39 | | - python3 manage.py migrate |
40 | | - python3 manage.py migrate --database=core |
41 | | - |
42 | | - # Only load dataset if it's a fresh database |
43 | | - if ! check_core_tables_exist; then |
44 | | - echo "Loading initial dataset..." |
45 | | - python3 scripts/load_dataset.py /data |
46 | | - fi |
47 | | -fi |
| 4 | +# First run migrations and load data if needed |
| 5 | +/opt/colocus/bin/entrypoint-migrate-and-load.sh |
48 | 6 |
|
49 | 7 | # Now run uvicorn |
50 | 8 | HOST=${UVICORN_HOST:-127.0.0.1} |
51 | 9 | PORT=${UVICORN_PORT:-8000} |
52 | 10 | WORKERS=${WEB_CONCURRENCY:-1} |
53 | | -/opt/colocus/.venv/bin/uvicorn config.asgi:application --host $HOST --port $PORT --workers $WORKERS "$@" |
| 11 | + |
| 12 | +uv run uvicorn config.asgi:application --host $HOST --port $PORT --workers $WORKERS "$@" |
0 commit comments