Skip to content

Commit 27f3189

Browse files
authored
Dev containers (#601)
1 parent 3bbf8b6 commit 27f3189

7 files changed

Lines changed: 236 additions & 1 deletion

File tree

.devcontainer/.vscode/launch.json

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
8+
{
9+
"name": "GeoNode",
10+
"type": "debugpy",
11+
"request": "launch",
12+
"args": [
13+
"runserver",
14+
"0.0.0.0:8000"
15+
],
16+
"env": {
17+
"ASYNC_SIGNALS": "True",
18+
},
19+
"django": true,
20+
"autoStartBrowser": false,
21+
"program": "${workspaceFolder}/project/manage.py",
22+
"justMyCode": false
23+
},
24+
{
25+
"name": "Celery Worker",
26+
"type": "debugpy",
27+
"request": "launch",
28+
"args": [
29+
"-A",
30+
"geonode.celery_app:app",
31+
"worker",
32+
"--loglevel=DEBUG",
33+
"--without-mingle",
34+
"--without-gossip",
35+
"-Ofair",
36+
"-E",
37+
"--statedb=worker.state",
38+
"--concurrency=2",
39+
"-n",
40+
"worker@%h",
41+
"-X",
42+
"harvesting"
43+
],
44+
"env": {
45+
"PYTHONPATH": "${workspaceFolder}/project:/usr/src/django-geonode-mapstore-client"
46+
},
47+
"cwd": "${workspaceFolder}",
48+
"autoStartBrowser": false,
49+
"program": "${workspaceFolder}/venv/bin/celery",
50+
"justMyCode": false
51+
},
52+
{
53+
"name": "Celery Beat",
54+
"type": "debugpy",
55+
"request": "launch",
56+
"args": [
57+
"-A",
58+
"geonode.celery_app:app",
59+
"beat",
60+
"--loglevel=DEBUG",
61+
"--scheduler=celery.beat:PersistentScheduler",
62+
"--pidfile=/tmp/celerybeat.pid"
63+
],
64+
"env": {
65+
"PYTHONPATH": "${workspaceFolder}/project:/usr/src/django-geonode-mapstore-client"
66+
},
67+
"cwd": "${workspaceFolder}",
68+
"autoStartBrowser": false,
69+
"program": "${workspaceFolder}/venv/bin/celery",
70+
"justMyCode": false
71+
},
72+
{
73+
"name": "Celery Harvesters",
74+
"type": "debugpy",
75+
"request": "launch",
76+
"args": [
77+
"-A",
78+
"geonode.celery_app:app",
79+
"worker",
80+
"--loglevel=DEBUG",
81+
"--without-mingle",
82+
"--without-gossip",
83+
"-Ofair",
84+
"-E",
85+
"--concurrency=2",
86+
"-n",
87+
"harvesting_worker@%h",
88+
"-Q",
89+
"harvesting"
90+
],
91+
"env": {
92+
"PYTHONPATH": "${workspaceFolder}/project:/usr/src/django-geonode-mapstore-client"
93+
},
94+
"cwd": "${workspaceFolder}",
95+
"autoStartBrowser": false,
96+
"program": "${workspaceFolder}/venv/bin/celery",
97+
"justMyCode": false
98+
}
99+
]
100+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"python.defaultInterpreterPath": "/usr/src/venv/bin/python",
3+
"python.analysis.extraPaths": [
4+
"${workspaceFolder}/project",
5+
"${workspaceFolder}/geonode",
6+
"${workspaceFolder}/geonode_mapstore_client",
7+
]
8+
}

.devcontainer/devcontainer.json

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
2+
// https://github.com/microsoft/vscode-dev-containers/tree/v0.194.0/containers/docker-existing-docker-compose
3+
// If you want to run as a non-root user in the container, see .devcontainer/docker-compose.yml.
4+
{
5+
"name": "Django Container",
6+
7+
// Update the 'dockerComposeFile' list if you have more compose files or use different names.
8+
// The .devcontainer/docker-compose.yml file contains any overrides you need/want to make.
9+
"dockerComposeFile": [
10+
"../docker-compose.yml",
11+
"./docker-compose.yml"
12+
],
13+
14+
// The 'service' property is the name of the service for the container that VS Code should
15+
// use. Update this value and .devcontainer/docker-compose.yml to the real service name.
16+
"service": "django",
17+
18+
// The optional 'workspaceFolder' property is the path VS Code should open by default when
19+
// connected. This is typically a file mount in .devcontainer/docker-compose.yml
20+
"workspaceFolder": "/usr/src",
21+
22+
// Set *default* container specific settings.json values on container create.
23+
"customizations": {
24+
"vscode": {
25+
"settings": {
26+
"terminal.integrated.profiles.linux": {
27+
"/bin/bash": {
28+
"path": "/bin/bash",
29+
"args": [
30+
"-l"
31+
]
32+
}
33+
},
34+
"terminal.integrated.defaultProfile.linux": "bash",
35+
"python.defaultInterpreterPath": "/usr/src/venv/bin/python",
36+
"python.terminal.activateEnvironment": true,
37+
"python.formatting.provider": "black"
38+
},
39+
40+
// Add the IDs of extensions you want installed when the container is created.
41+
"extensions": [
42+
"ms-python.python"
43+
]
44+
}
45+
}
46+
47+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
48+
49+
// Uncomment the next line if you want start specific services in your Docker Compose config.
50+
// "runServices": [],
51+
52+
// Uncomment the next line if you want to keep your containers running after VS Code shuts down.
53+
// "shutdownAction": "none",
54+
55+
// Uncomment the next line to run commands after the container is created - for example installing curl.
56+
// "postCreateCommand": "apt-get update && apt-get install -y curl",
57+
58+
// Uncomment to connect as a non-root user if you've added one. See https://aka.ms/vscode-remote/containers/non-root.
59+
// "remoteUser": "vscode"
60+
}

.devcontainer/docker-compose.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
services:
2+
3+
django:
4+
volumes:
5+
- './src:/usr/src/project'
6+
- './.devcontainer/.vscode:/usr/src/.vscode'
7+
- statics:/mnt/volumes/statics
8+
- geoserver-data-dir:/geoserver_data/data
9+
- backup-restore:/backup_restore
10+
- data:/data
11+
- tmp:/tmp
12+
healthcheck:
13+
test: "echo 'Alive'"
14+
entrypoint: ["/usr/src/project/entrypoint.sh"]
15+
command: sleep infinity
16+
celery:
17+
entrypoint: ["/usr/src/project/entrypoint.sh"]
18+
command: sleep infinity

.devcontainer/docker.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
set -o allexport
3+
source ../.env
4+
set +o allexport
5+
docker compose -f ../docker-compose.yml -f ./docker-compose.yml "$@"

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ development.db-journal
6666
local_settings.py
6767

6868
.idea/
69-
.vscode/
69+
/.vscode/
7070
.vagrant/
7171
Vagrantfile
7272
/.env

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,47 @@ POSTGRESQL_MAX_CONNECTIONS=200
215215
```
216216

217217
In this case PostgreSQL will run accepting 200 maximum connections.
218+
219+
## Developing with Dev Containers in VS Code
220+
221+
This repo includes a .devcontainer folder with the condigurations to run Django and Celery inside a VS Code Dev Container.
222+
A `docker.sh` script aliases the `docker compose` command with the pre-configured arguments to use the customized compose files.
223+
224+
You can run the Dev Container with the following commands:
225+
226+
```bash
227+
cd .devcontainer
228+
chmod +x docker.sh
229+
./docker.sh build
230+
.docker.sh up -d
231+
```
232+
233+
The Django and the Celery containers will be started **without** running the Django and Celery processes. They can be started manually inside the dev container. The container is autopopulated with VS Code development extensions for Python and a list of pre-configured luanch configurations (for Django and Celery).
234+
235+
Within VS Code open the command palette with `Ctrl+P` and run `Dev Container: Reopen in Container`. VS Code will recognize the presence of the two dev container, and will allow to reopen the current window inside the container's workspace.
236+
Wait a few seconds to let VS Code setup the dev extensions, then you should see the launch configurations.
237+
238+
To simplify the debugging of GeoNode and the GeoNode client, these modules can be installed as editable (PEP-660) with the following commands:
239+
240+
```bash
241+
pip install -e git+https://github.com/GeoNode/geonode.git@master#egg=geonode --src=/usr/src
242+
pip install -e git+https://github.com/GeoNode/geonode-mapstore-client.git@master#egg=django_geonode_mapstore_client --src=/usr/src
243+
```
244+
245+
The modules will be isntalled under `/usr/src` and so at te root of the VS Code workspace.
246+
Notice that at the time of writing Pylance can't resolve PEP-660 editable installs. For this reason the `.vscode/settings.py` contain extrPaths for the modules.
247+
248+
### Running Django
249+
The `GeoNode` launch configuration for Django sets the `ASYNC_SIGNALS` env variable to False. This way GeoNode can be developed and debugged in sync mode, without Celery.
250+
If you want to test Django in async mode, you can switch this variable to `True` and tun Celery (see below).
251+
252+
Running the Debug sessions for Django will start Django with its internal development server.
253+
254+
### Running Celery
255+
Celery exectutions requires luanching three Debug processes:
256+
257+
- `Celery Worker`: the generic worker process
258+
- `Celery Beat`: the scheduler
259+
- `Celery Harvesters`: The worker dedicated to the harvesters
260+
261+
You can also remove the `-X harvesting` argument inside the Celery Worker launch configuration to have also the harvesters running in the same worker. this way you don't need to run the Beat and the Celery Harvesters processes.

0 commit comments

Comments
 (0)