Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions bootstrap/development/docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,47 @@ Note that these steps must be run from the root directory of the repo.
user.is_superuser = True
user.save()
```

### Enabling the debugger for the web service

The web service may be augmented to allow a debugger to be attached to it. Below are instructions on this for Visual Studio Code, although the process should be similar for other IDEs that support the Debug Adapter Protocol:

1. In the `.vscode` directory, add or update a file named `launch.json`:

```json
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach to Docker Django",
"type": "python",
"request": "attach",
"connect": {
"host": "localhost",
"port": 5678
},
"pathMappings": [
{
"localRoot": "${workspaceFolder}/coldfront",
"remoteRoot": "/var/www/coldfront_app/coldfront"
}
]
}
]
}
```

This file configures how Visual Studio Code attaches its debugger to the running Django application inside the Docker `web` container, specifying the connection details and mapping local source files to their locations inside the container.

Notes:
- In the above example, `localRoot` assumes that `.vscode` is in the parent directory of the repository. Adjust the key as needed.

2. Set the `DEBUGPY` environment variable to `1` on the host.

```bash
export DEBUGPY=1
```

3. Bring up Docker Compose as specified above in the same session where the environment variable is set.

4. In Visual Studio Code, select "Run and Debug" in the left pane. At the top of the component, select "Attach to Docker Django" and click the play button ("Start debugging" button) to start the debugger. Note: When `DEBUGPY=1`, the web server will not run until the play button is clicked, because it waits for a client to attach first.
16 changes: 12 additions & 4 deletions bootstrap/development/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ services:
- ./config/redis.conf:/usr/local/etc/redis/redis.conf

email-server:
image: coldfront-email-server:${IMAGE_TAG:-latest}
image: coldfront-app-base:${IMAGE_TAG:-latest}
command: ["python3", "-m", "smtpd", "-d", "-n", "-c", "DebuggingServer", "0.0.0.0:1025"]

db-postgres-shell:
image: coldfront-db-postgres-shell:${IMAGE_TAG:-latest}
command: ["sleep", "infinity"]
environment:
POSTGRES_HOST: db-postgres
POSTGRES_DB: ${DB_NAME}
Expand All @@ -42,19 +44,25 @@ services:
- ../../..:/var/www/coldfront_app/coldfront

app-shell:
image: coldfront-app-shell:${IMAGE_TAG:-latest}
image: coldfront-app-base:${IMAGE_TAG:-latest}
command: ["sleep", "infinity"]
volumes:
- ../../..:/var/www/coldfront_app/coldfront

web:
image: coldfront-web:${IMAGE_TAG:-latest}
image: coldfront-app-base:${IMAGE_TAG:-latest}
command: ["/var/www/coldfront_app/coldfront/bootstrap/development/docker/scripts/web_entrypoint.sh"]
environment:
- DEBUGPY=${DEBUGPY:-0}
ports:
- ${WEB_PORT}:80
- 5678:5678
volumes:
- ../../..:/var/www/coldfront_app/coldfront

qcluster:
image: coldfront-qcluster:${IMAGE_TAG:-latest}
image: coldfront-app-base:${IMAGE_TAG:-latest}
command: ["python3", "manage.py", "qcluster"]
volumes:
- ../../..:/var/www/coldfront_app/coldfront

Expand Down
2 changes: 2 additions & 0 deletions bootstrap/development/docker/images/app-base.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ RUN /var/www/coldfront_app/venv/bin/pip install --upgrade pip wheel && \
/var/www/coldfront_app/venv/bin/pip install setuptools==68.2.2 && \
/var/www/coldfront_app/venv/bin/pip install -r requirements.txt

RUN /var/www/coldfront_app/venv/bin/pip install debugpy

ENV PATH="/var/www/coldfront_app/venv/bin:$PATH"
2 changes: 1 addition & 1 deletion bootstrap/development/docker/images/web.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG BASE_IMAGE_TAG=latest
FROM coldfront-app-base:${BASE_IMAGE_TAG}

CMD ["python3", "manage.py", "runserver", "0.0.0.0:80"]
CMD ["python3", "-m", "debugpy", "--listen", "0.0.0.0:5678", "--wait-for-client", "manage.py", "runserver", "0.0.0.0:80"]
20 changes: 0 additions & 20 deletions bootstrap/development/docker/scripts/build_images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,7 @@ docker build \
--build-arg BASE_IMAGE_TAG=$IMAGE_TAG \
-t coldfront-app-base:$IMAGE_TAG .

docker build \
-f bootstrap/development/docker/images/app-shell.Dockerfile \
--build-arg BASE_IMAGE_TAG=$IMAGE_TAG \
-t coldfront-app-shell:$IMAGE_TAG .

docker build \
-f bootstrap/development/docker/images/web.Dockerfile \
--build-arg BASE_IMAGE_TAG=$IMAGE_TAG \
-t coldfront-web:$IMAGE_TAG .

docker build \
-f bootstrap/development/docker/images/email-server.Dockerfile \
--build-arg BASE_IMAGE_TAG=$IMAGE_TAG \
-t coldfront-email-server:$IMAGE_TAG .

docker build \
-f bootstrap/development/docker/images/db-postgres-shell.Dockerfile \
--build-arg BASE_IMAGE_TAG=$IMAGE_TAG \
-t coldfront-db-postgres-shell:$IMAGE_TAG .

docker build \
-f bootstrap/development/docker/images/qcluster.Dockerfile \
--build-arg BASE_IMAGE_TAG=$IMAGE_TAG \
-t coldfront-qcluster:$IMAGE_TAG .
7 changes: 7 additions & 0 deletions bootstrap/development/docker/scripts/web_entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

if [ "$DEBUGPY" = "1" ]; then
exec python3 -m debugpy --listen 0.0.0.0:5678 --wait-for-client manage.py runserver 0.0.0.0:80
else
exec python3 manage.py runserver 0.0.0.0:80
fi