Skip to content

Commit

Permalink
Configure startup scripts for runserver and qcluster debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
danniel committed Jul 17, 2024
1 parent b15696d commit 8b72172
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 25 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# ENVIRONMENT="development" # or "debug", "debugwait", "production"

DATABASE_USER=postgres
DATABASE_PASSWORD=secret
DATABASE_NAME=civil_society_vote
Expand Down
45 changes: 30 additions & 15 deletions __vscode__launch.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
]
}
1 change: 0 additions & 1 deletion docker-compose.base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ services:
env_file:
- .env
environment:
ENVIRONMENT: "debug"
DATABASE_ENGINE: "postgresql"
DATABASE_HOST: "votong_db_dev"
DATABASE_PORT: "5432"
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ services:
- db
ports:
- "5678:5678"
- "5677:5677"

volumes:
votong_psql:
2 changes: 1 addition & 1 deletion docker/dockerfiles/Dockerfile.backend.dev
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 15 additions & 7 deletions docker/s6-rc.d/backend/run
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 18 additions & 1 deletion docker/s6-rc.d/qcluster/run
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8b72172

Please sign in to comment.