diff --git a/.env.example b/.env.example index ceeb18a4..0c931dc2 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,5 @@ +# ENVIRONMENT="development" # or "debug", "debugwait", "production" + DATABASE_USER=postgres DATABASE_PASSWORD=secret DATABASE_NAME=civil_society_vote diff --git a/__vscode__launch.json b/__vscode__launch.json index 67baaa9f..0119ab54 100644 --- a/__vscode__launch.json +++ b/__vscode__launch.json @@ -1,19 +1,34 @@ { - "configurations": [ - { - "name": "Attach (remote debug)", - "type": "debugpy", - "request": "attach", - "pathMappings": [ - { - "localRoot": "${workspaceFolder}", - "remoteRoot": "/var/www/votong/" - } - ], - "connect": { - "port": 5678, - "host": "127.0.0.1" + "configurations": [ + { + "name": "Attach to runserver in Docker", + "type": "debugpy", + "request": "attach", + "pathMappings": [ + { + "localRoot": "${workspaceFolder}", + "remoteRoot": "/var/www/votong/" } + ], + "connect": { + "port": 5678, + "host": "127.0.0.1" + } + }, + { + "name": "Attach to qcluster in Docker", + "type": "debugpy", + "request": "attach", + "pathMappings": [ + { + "localRoot": "${workspaceFolder}", + "remoteRoot": "/var/www/votong/" + } + ], + "connect": { + "port": 5677, + "host": "127.0.0.1" } - ] + } + ] } diff --git a/docker-compose.base.yml b/docker-compose.base.yml index ab70da0e..105682cb 100644 --- a/docker-compose.base.yml +++ b/docker-compose.base.yml @@ -22,7 +22,6 @@ services: env_file: - .env environment: - ENVIRONMENT: "debug" DATABASE_ENGINE: "postgresql" DATABASE_HOST: "votong_db_dev" DATABASE_PORT: "5432" diff --git a/docker-compose.yml b/docker-compose.yml index fc17bfae..6c10ddc6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -20,6 +20,7 @@ services: - db ports: - "5678:5678" + - "5677:5677" volumes: votong_psql: diff --git a/docker/dockerfiles/Dockerfile.backend.dev b/docker/dockerfiles/Dockerfile.backend.dev index 46b1c111..b38697ec 100644 --- a/docker/dockerfiles/Dockerfile.backend.dev +++ b/docker/dockerfiles/Dockerfile.backend.dev @@ -4,7 +4,7 @@ FROM python:${PYTHON_VERSION}-slim-bookworm ENV PYTHONUNBUFFERED=1 -ENV ENVIRONMENT ${ENVIRONMENT:-production} +ENV ENVIRONMENT ${ENVIRONMENT:-development} ENV DEBUG ${DEBUG:-True} ENV RUN_MIGRATIONS=True diff --git a/docker/s6-rc.d/backend/run b/docker/s6-rc.d/backend/run index fac4cf43..8a4d541b 100644 --- a/docker/s6-rc.d/backend/run +++ b/docker/s6-rc.d/backend/run @@ -19,13 +19,21 @@ if [ "${ENVIRONMENT}" = "production" ]; then --workers "${WORKERS}" \ --timeout 60 else - if [ "${ENVIRONMENT}" = "development" ]; then - echo "Running in development mode" - python3 manage.py runserver 0.0.0.0:8000 + if [ "${ENVIRONMENT}" = "debug" ]; then + echo "**********************************************" + echo "*** Web server in development DEBUG mode ***" + echo "**********************************************" + python3 -Xfrozen_modules=off -m debugpy --listen 0.0.0.0:5678 manage.py runserver 0.0.0.0:8000 + elif [ "${ENVIRONMENT}" = "debugwait" ]; then + echo "***********************************************" + echo "*** Web server in development DEBUG mode ***" + echo "*** Waiting for debugger connection... ***" + echo "***********************************************" + python3 -Xfrozen_modules=off -m debugpy --wait-for-client --listen 0.0.0.0:5678 manage.py runserver 0.0.0.0:8000 else - echo "*********************************************" - echo "**** Running in development DEBUG mode ****" - echo "*********************************************" - python -Xfrozen_modules=off -m debugpy --wait-for-client --listen 0.0.0.0:5678 manage.py runserver 0.0.0.0:8000 + echo "****************************************" + echo "*** Web server in development mode ***" + echo "****************************************" + python3 manage.py runserver 0.0.0.0:8000 fi fi diff --git a/docker/s6-rc.d/qcluster/run b/docker/s6-rc.d/qcluster/run index 3b21410c..3de12477 100644 --- a/docker/s6-rc.d/qcluster/run +++ b/docker/s6-rc.d/qcluster/run @@ -1,4 +1,21 @@ #!/command/with-contenv sh cd /var/www/votong/backend/ || exit 1 -python3 manage.py qcluster +if [ "${ENVIRONMENT}" = "debug" ]; then + echo "*********************************************" + echo "*** Starting the qcluster in DEBUG mode ***" + echo "*********************************************" + python3 -Xfrozen_modules=off -m debugpy --listen 0.0.0.0:5677 manage.py qcluster +elif [ "${ENVIRONMENT}" = "debugwait" ]; then + echo "*********************************************" + echo "*** Starting the qcluster in DEBUG mode ***" + echo "*** Waiting for debugger connection... ***" + echo "*********************************************" + python3 -Xfrozen_modules=off -m debugpy --wait-for-client --listen 0.0.0.0:5677 manage.py qcluster +else + echo "*******************************" + echo "*** Starting the qcluster ***" + echo "*******************************" + python3 manage.py qcluster +fi +