Skip to content

Commit f7658cc

Browse files
committed
Merge branch 'HEA-752/Dagster-GraphQL-API-is-intermittently-failing-with-a-ProtocolError-when-accessed-via-the-revproxy-Django-view' of github.com-work2:FEWS-NET/HEA-Database-Development into HEA-752/Dagster-GraphQL-API-is-intermittently-failing-with-a-ProtocolError-when-accessed-via-the-revproxy-Django-view
2 parents 466a603 + 899d76c commit f7658cc

15 files changed

Lines changed: 94 additions & 33 deletions

.github/workflows/01-build-then-test.yml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,6 @@ jobs:
271271
docker cp ci-${APP}-${CI_PIPELINE_ID}-${{ github.job }}:/usr/src/app/log ./ || true
272272
docker cp ci-${APP}-${CI_PIPELINE_ID}-${{ github.job }}:/usr/src/app/coverage.txt ./ || true
273273
274-
# Save the database schema as an artifact
275-
docker compose run --no-deps --rm --entrypoint dbtoyaml app --no-owner --no-privileges test_${PGDATABASE} > schema.yml
276-
diff pyrseas/schema.yaml schema.yml > schema.diff || true
277274
- name: "Upload test artifacts"
278275
if: success() || failure()
279276
uses: actions/upload-artifact@v4
@@ -400,9 +397,6 @@ jobs:
400397
# Copy the artifacts out of the Docker container to project directory
401398
docker cp ci-${APP}-${CI_PIPELINE_ID}-${{ github.job }}:/usr/src/app/log ./ || true
402399
docker cp ci-${APP}-${CI_PIPELINE_ID}-${{ github.job }}:/usr/src/app/coverage.txt ./ || true
403-
# Save the database schema as an artifact
404-
docker compose run --no-deps --rm --entrypoint dbtoyaml app --no-owner --no-privileges test_${PGDATABASE} > schema.yml
405-
diff pyrseas/schema.yaml schema.yml > schema.diff || true
406400
- name: "Upload test artifacts"
407401
if: success() || failure()
408402
uses: actions/upload-artifact@v4
@@ -530,9 +524,6 @@ jobs:
530524
# Copy the artifacts out of the Docker container to project directory
531525
docker cp ci-${APP}-${CI_PIPELINE_ID}-${{ github.job }}:/usr/src/app/log ./ || true
532526
docker cp ci-${APP}-${CI_PIPELINE_ID}-${{ github.job }}:/usr/src/app/coverage.txt ./ || true
533-
# Save the database schema as an artifact
534-
docker compose run --no-deps --rm --entrypoint dbtoyaml app --no-owner --no-privileges test_${PGDATABASE} > schema.yml
535-
diff pyrseas/schema.yaml schema.yml > schema.diff || true
536527
- name: "Upload test artifacts"
537528
if: success() || failure()
538529
uses: actions/upload-artifact@v4
@@ -661,11 +652,6 @@ jobs:
661652
# Copy the artifacts out of the Docker container to project directory
662653
docker cp ci-${APP}-${CI_PIPELINE_ID}-${{ github.job }}:/usr/src/app/log ./ || true
663654
docker cp ci-${APP}-${CI_PIPELINE_ID}-${{ github.job }}:/usr/src/app/coverage.txt ./ || true
664-
# The prod image does not include pyrseas/dbtoyaml. Building a test image to include that
665-
docker compose build app
666-
# Save the database schema as an artifact
667-
docker compose run --no-deps --rm --entrypoint dbtoyaml app --no-owner --no-privileges test_${PGDATABASE} > schema.yml
668-
diff pyrseas/schema.yaml schema.yml > schema.diff || true
669655
- name: "Upload test artifacts"
670656
if: success() || failure()
671657
uses: actions/upload-artifact@v4

README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,53 @@ baseline
2323

2424
This produces a .puml file that can be rendered using a PlantUML
2525
server, either within your IDE or using a service like http://www.plantuml.com/.
26+
27+
## Debugging inside Docker Containers
28+
29+
The `LAUNCHER` environment sets a wrapper program around the Python process
30+
(`gunicorn`, `dagster-daemon`, `dagster-webserver`). This can be used to
31+
enable a debugger inside Docker Containers:
32+
33+
1. Set `LAUNCHER="python3 -m debugpy --listen 0.0.0.0:5678"` in `.env`
34+
2. Create Launch Configurations in Visual Studio Code like:
35+
36+
```json
37+
{
38+
"name": "Python: Attach to app (Docker Container)",
39+
"type": "debugpy",
40+
"request": "attach",
41+
"connect": {
42+
"host": "localhost",
43+
"port": 5678
44+
},
45+
"pathMappings": [
46+
{
47+
"localRoot": "${workspaceFolder:hea}",
48+
"remoteRoot": "/usr/src/app"
49+
}
50+
],
51+
"django": true,
52+
"justMyCode": false
53+
},
54+
{
55+
"name": "Python: Attach to dagster-daemon (Docker Container)",
56+
"type": "debugpy",
57+
"request": "attach",
58+
"connect": {
59+
"host": "localhost",
60+
"port": 5680
61+
},
62+
"pathMappings": [
63+
{
64+
"localRoot": "${workspaceFolder:hea}",
65+
"remoteRoot": "/usr/src/app"
66+
}
67+
],
68+
"django": true,
69+
"justMyCode": false
70+
}
71+
```
72+
73+
3. Start the Docker containers as normal, and then use the Run and Debug
74+
pane in Visual Studio code to launch the configuration that attaches to
75+
the desired server.

docker-compose.override.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ services:
1515
build:
1616
target: dev
1717
ports:
18+
- "5678:5678"
1819
- "8000:8000"
1920
- "8888:8888"
2021
volumes:
@@ -30,6 +31,9 @@ services:
3031
- ./env.example:/usr/src/app/.env
3132
environment:
3233
DJANGO_SETTINGS_MODULE: hea.settings.local
34+
LAUNCHER: ${LAUNCHER} # e.g. "debugpy" or "ddtrace"
35+
# Disable frozen modules warning
36+
PYDEVD_DISABLE_FILE_VALIDATION: 1
3337
# Put .coverage in a writable directory
3438
COVERAGE_FILE: log/.coverage
3539
command:
@@ -41,6 +45,7 @@ services:
4145
restart: no
4246
ports:
4347
- "3000:3000"
48+
- "5679:5678"
4449
volumes:
4550
- ./:/usr/src/app
4651
# Separate volumes for writable directories inside the container
@@ -54,9 +59,14 @@ services:
5459
- ./env.example:/usr/src/app/.env
5560
environment:
5661
DJANGO_SETTINGS_MODULE: hea.settings.local
62+
LAUNCHER: ${LAUNCHER} # e.g. "debugpy" or "ddtrace"
63+
# Disable frozen modules warning
64+
PYDEVD_DISABLE_FILE_VALIDATION: 1
5765

5866
dagster_daemon:
5967
restart: no
68+
ports:
69+
- "5680:5678"
6070
volumes:
6171
- ./:/usr/src/app
6272
# Separate volumes for writable directories inside the container
@@ -70,4 +80,7 @@ services:
7080
- ./env.example:/usr/src/app/.env
7181
environment:
7282
DJANGO_SETTINGS_MODULE: hea.settings.local
83+
LAUNCHER: ${LAUNCHER} # e.g. "debugpy" or "ddtrace"
84+
# Disable frozen modules warning
85+
PYDEVD_DISABLE_FILE_VALIDATION: 1
7386

docker-compose.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,7 @@ services:
110110
MINIO_ENDPOINT_URL: http://minio:9000
111111
SUPPORT_EMAIL_ADDRESS: ${SUPPORT_EMAIL_ADDRESS}
112112
DJANGO_MIGRATE: 1
113-
KILUIGI_INTERMEDIATETARGET_BACKEND_CLASS: ${KILUIGI_INTERMEDIATETARGET_BACKEND_CLASS}
114-
KILUIGI_INTERMEDIATETARGET_ROOT_PATH: ${KILUIGI_INTERMEDIATETARGET_ROOT_PATH}
115-
KILUIGI_FINALTARGET_BACKEND_CLASS: ${KILUIGI_FINALTARGET_BACKEND_CLASS}
116-
KILUIGI_FINALTARGET_ROOT_PATH: ${KILUIGI_FINALTARGET_ROOT_PATH}
117-
KILUIGI_REPORTTARGET_BACKEND_CLASS: ${KILUIGI_REPORTTARGET_BACKEND_CLASS}
118-
KILUIGI_REPORTTARGET_ROOT_PATH: ${KILUIGI_REPORTTARGET_ROOT_PATH}
119113
GOOGLE_APPLICATION_CREDENTIALS: ${GOOGLE_APPLICATION_CREDENTIALS}
120-
GOOGLE_ADMIN_EMAIL: ${GOOGLE_ADMIN_EMAIL}
121114
command:
122115
- --timeout=3600
123116
- --workers=12

docker/app/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM --platform=linux/amd64 python:3.12-bookworm as base
1+
FROM python:3.12-bookworm as base
22

33
# set up apt repositories for postgres installation
44
RUN curl -s https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | tee /usr/share/keyrings/pgdg.gpg >/dev/null && \

docker/app/run_dagster_daemon.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,8 @@ echo Setting up logs
1313
touch log/django.log
1414
chown -R django:django log/*
1515

16-
echo Starting Dagster
17-
gosu django dagster-daemon run $*
16+
echo Starting Dagster Daemon
17+
if [ x"$LAUNCHER" != x"" ]; then
18+
echo using ${LAUNCHER}
19+
fi
20+
gosu django ${LAUNCHER} /usr/local/bin/dagster-daemon run $*

docker/app/run_dagster_webserver.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,8 @@ echo Setting up logs
1313
touch log/django.log
1414
chown -R django:django log/*
1515

16-
echo Starting Dagster
17-
gosu django dagster-webserver -h 0.0.0.0 -p 3000 -m pipelines --path-prefix /${DAGSTER_WEBSERVER_PREFIX} $*
16+
echo Starting Dagster Webserver
17+
if [ x"$LAUNCHER" != x"" ]; then
18+
echo using ${LAUNCHER}
19+
fi
20+
gosu django ${LAUNCHER} /usr/local/bin/dagster-webserver -h 0.0.0.0 -p 3000 -m pipelines --path-prefix /${DAGSTER_WEBSERVER_PREFIX} $*

docker/app/run_django.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ touch log/django_sql.log
4040
chown -R django:django log/*
4141

4242
echo Starting Gunicorn with DJANGO_SETTINGS_MODULE=${DJANGO_SETTINGS_MODULE}
43-
gosu django gunicorn ${APP}.asgi:application \
43+
if [ x"$LAUNCHER" != x"" ]; then
44+
echo using ${LAUNCHER}
45+
fi
46+
gosu django ${LAUNCHER} /usr/local/bin/gunicorn ${APP}.asgi:application \
4447
--name ${APP}${ENV} \
4548
--worker-class uvicorn.workers.UvicornWorker \
4649
--config $(dirname $(readlink -f "$0"))/gunicorn_config.py \

docker/db/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
FROM --platform=linux/amd64 postgis/postgis:17-3.5
1+
# Use a third party multicarch base image for compatibility with both ARM and AMD architectures
2+
# until PostGIS fix https://github.com/postgis/docker-postgis/issues/216
3+
FROM ghcr.io/baosystems/postgis:17-3.5
24

35
COPY create_db.sh /docker-entrypoint-initdb.d/create_db.sh

docker/db/create_db.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/sh
2-
psql --set=CLIENT=$CLIENT --set=APP=$APP --set=ENV=$ENV --set=POSTGRES_PASSWORD=$POSTGRES_PASSWORD --set=DAGSTER_PASSWORD=$DAGSTER_PASSWORD --set=CREATE_TEMPLATE=${CREATE_TEMPLATE:-false} -d postgres --echo-all << EOF
2+
psql --set=CLIENT=$CLIENT --set=APP=$APP --set=ENV=$ENV --set=POSTGRES_PASSWORD=$POSTGRES_PASSWORD --set=CREATE_TEMPLATE=${CREATE_TEMPLATE:-false} -d postgres --echo-all << EOF
33
44
\set DATABASE :CLIENT :APP :ENV
55
\set OWNER :CLIENT :APP :ENV
@@ -74,7 +74,7 @@ ALTER DEFAULT PRIVILEGES IN SCHEMA :SCHEMA
7474
GRANT SELECT ON TABLES TO :OWNER;
7575
7676
\set DAGSTER :CLIENT :APP :ENV
77-
CREATE ROLE :DAGSTER PASSWORD :'DAGSTER_PASSWORD' NOLOGIN CREATEDB NOCREATEROLE NOSUPERUSER;
77+
CREATE ROLE :DAGSTER PASSWORD :'POSTGRES_PASSWORD' NOLOGIN CREATEDB NOCREATEROLE NOSUPERUSER;
7878
COMMENT ON ROLE :DAGSTER IS 'Main Dagster pipeline user for :CLIENT :PRJ :ENV';
7979
GRANT :DAGSTER TO :OWNER;
8080
GRANT CONNECT, TEMPORARY, CREATE ON DATABASE :DATABASE TO :DAGSTER;

0 commit comments

Comments
 (0)