-
Notifications
You must be signed in to change notification settings - Fork 15
Run OpenCodelists in Dokku in Codespaces #2487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
With this commit, you should get a working OpenCodelists in Dokku in Codespaces, with the web server viewable, and the minimal set of test data available. This would need some refining and polishing before merging. It also does not yet restart the server for a stopped codespace; we'd need a `postAttachCommand` providing in the `devcontainer.json` and an appropriate script that might only need to do something like: ```sh cd /workspaces/opencodelists docker-compose up -d docker exec -t dokku sh -c "dokku ps:rebuild opencodelists opencodelists:latest" ```
- "3022:22" | ||
- "8080:80" | ||
- "8443:443" | ||
- "7000:7000" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: Are all these ports necessary? It might only be 7000
— the port for the production OpenCodelists image — with 22
useful if you want to SSH in (though you can run docker exec
and docker cp
which should cover most needs).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: We don't specify a Docker image. Do we want to use a different image than the default? And do we want to do some of the setup currently in dokku.sh
in a Dockerfile
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought: Some of the setup here could probably go in Dockerfile
and be built as part of the image.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought: This file could probably go somewhere other than the root directory.
cd /tmp && wget https://github.com/casey/just/releases/download/1.40.0/just-1.40.0-x86_64-unknown-linux-musl.tar.gz && tar -xzf just-1.40.0-x86_64-unknown-linux-musl.tar.gz && chmod 555 just | ||
sudo mv /tmp/just /usr/bin/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought: While downloading this way is OK, although it would be better to specify a version somewhere as a variable, this is necessary because the default dev container image is currently based on Ubuntu 22.04, which doesn't have just
in its repositories. (Ubuntu 24.04 does, albeit the version is probably older than the current release.)
cd /workspaces/opencodelists | ||
cp dotenv-sample .env | ||
touch db.sqlite3 # workaround because build-dbs-for-local-development expects a db.sqlite3 | ||
yes Y | just build-dbs-for-local-development nuclear |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: yes
is necessary because build-dbs-for-local-development
has an interactive user confirmation; not sure if the capitalised Y
is necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: The use of yes
results in failure if you use set -o pipefail
because there's a broken pipe when the command on the right-hand side completes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought: We need Python to run the initial setup in build-dbs-for-local-development
.
We're currently on Python 3.12 for OpenCodelists.
The default dev container image currently has Python 3.12 available, which is convenient, but more luck than anything else.
To be more confident of always having the correct Python version in future, we'd need to retrieve the required version of Python ourselves.
"features": { | ||
"ghcr.io/devcontainers/features/docker-in-docker:2": {} | ||
}, | ||
"postCreateCommand": "/bin/bash /workspaces/opencodelists/dokku.sh" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought: We could provide ${containerWorkspaceFolder}
as an argument to dokku.sh
here, which then avoids hardcoding the directory in dokku.sh
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought: We could provide a postAttachCommand
script which should restart the installed server correctly when a codespace is started after stopping.
Seeing the following in the Dokku logs:
Possibly due to not configuring any OpenTelemetry settings? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought: This file could probably go somewhere other than the root directory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: This file is taken directly from Dokku's documentation with only the addition of port 7000.
|
||
cd /workspaces/opencodelists | ||
cp dotenv-sample .env | ||
touch db.sqlite3 # workaround because build-dbs-for-local-development expects a db.sqlite3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought: See #2482 for more information.
touch db.sqlite3 # workaround because build-dbs-for-local-development expects a db.sqlite3 | ||
yes Y | just build-dbs-for-local-development nuclear | ||
|
||
docker-compose up -d |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought: This should probably be the v2 usage:
docker compose up -d
The devcontainer Docker feature makes this work automatically, but we should use the more modern form.
docker exec -t dokku sh -c "dokku apps:create opencodelists" | ||
docker exec -t dokku sh -c 'dokku config:set opencodelists BASE_URLS="http://localhost:7000,http://127.0.0.1:7000" DATABASE_DIR="/storage" DATABASE_URL="sqlite:////storage/db.sqlite3" DJANGO_SETTINGS_MODULE="opencodelists.settings" SECRET_KEY="thisisatestsecretkeyfortestingonly" TRUD_API_KEY="thisisatesttrudkeyfortestingonly"' | ||
|
||
sudo mkdir -p /var/lib/dokku/data/storage/opencodelists |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought: I got very, very confused with permissions because I overlooked the docker-compose.yaml
volumes configuration.
With the Docker Compose set up, this directory is on the host running Dokku in a container, not inside the Dokku container! (Inside the OpenCodelists container, I was seeing an empty directory owned by root.)
See #2483.
This PR is currently a sketch of adding a configuration for running OpenCodelists in Dokku in a dev container/Codespaces. It is not complete enough to be merged, but functional enough to try out. If it's useful, it may warrant some tidying before merging.
It adds a minimal
devcontainer.json
configuration and a script that:just
, necessary to build the test databases and Docker imageYou can see the Django logs by running: