Skip to content

Commit

Permalink
Add dev container configuration
Browse files Browse the repository at this point in the history
To support this the `flask` wrapper will detech whether `SETTINGS_FILE`
is set, and if so assume we're already running within a container.
  • Loading branch information
jellybob committed Dec 14, 2023
1 parent 6c60a2d commit 789a81a
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
46 changes: 46 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "EMF Web",
// Compose config
"dockerComposeFile": "../docker-compose.yml",
"service": "app",
"workspaceFolder": "/app",
"containerEnv": {
"EDITOR": "code -w"
},
// Replace the standard command with a noop to allow exec-ing
"overrideCommand": true,
// Git complains if user IDs don't match, which they will with a mounted directory
"onCreateCommand": "git config --global --add safe.directory /app",
// Port forwarding
"forwardPorts": [
2342,
"db:5432"
],
"portsAttributes": {
"2342": {
"label": "Web",
"onAutoForward": "silent",
"requireLocalPort": false
},
"db:5432": {
"label": "Postgres",
"onAutoForward": "silent",
"requireLocalPort": false
}
},
// VSCode additions
"features": {},
"customizations": {
"vscode": {
"extensions": [
"dbaeumer.vscode-eslint",
"EditorConfig.EditorConfig",
"github.vscode-github-actions",
"ms-python.python",
"ms-python.black-formatter",
"ms-python.flake8",
"ms-python.mypy-type-checker"
]
}
}
}
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,23 @@ To delete all data and start over fresh you can use `docker compose down`.
Management commands can be listed and run using the `./flask` command, which
forwards them to the flask command line within the container.

### Visual Studio Code

If you use Visual Studio Code it should present you with the option to open the
project in a dev container. If not, run `code .` from your local copy, and ensure
you have the [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) installed.

Reopening in a dev container will start everything via Docker, attach
your VSCode instance to the application container, install relevant extensions,
and ensure everything is configured to fit with our standards.

The first time you start the dev container you will need to tell VSCode where to
find the Poetry virtual environment. You can do this by open the command pallette
(Cmd-P on macOS devices) and searching for "Python: Select interpreter", the list
presented should include `website-${randomHash}-py3.11`, which will be annotated
as "Poetry". Select that, and then any Python tooling and shells will run within
the appropriate virtualenv.

### Errors starting the dev server

e.g. `Error: While importing 'dev_server', an ImportError was raised.`
Expand Down
6 changes: 5 additions & 1 deletion flask
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#!/usr/bin/env bash
# Shim to run the Flask admin command within docker
docker compose exec -e SETTINGS_FILE=./config/development.cfg app poetry run flask "$@"
if [ -z "${SETTINGS_FILE}" ]; then
docker compose exec -e SETTINGS_FILE=./config/development.cfg app poetry run flask "$@"
else
exec poetry run flask "$@"
fi

0 comments on commit 789a81a

Please sign in to comment.