Skip to content

Commit dea4087

Browse files
authored
fix: Make Linux work (#30)
* fix: Make Linux work Make the dev compose work with linux and rootless podman Update docs
1 parent 9152a31 commit dea4087

File tree

4 files changed

+45
-11
lines changed

4 files changed

+45
-11
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,4 @@ test.bmp
166166
# Photoshop files
167167
image-source/
168168
docs/.obsidian/
169+
/.python_history

README.md

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,22 @@ Follow this guide to set up the api locally for development.
2222
### Prerequisites
2323

2424
> [!note]
25-
> By default, we are using Docker for the sake of simplicity. If you want to run the API natively, you can check out the section [Native Guide](#native-guide).
25+
> By default, we are containerizing for the sake of simplicity.
26+
> If you want to run the API natively, you can check out the section [Native Guide](#native-guide).
2627
27-
- Docker
28-
- An IDE (PyCharm strongly recommended)
28+
- Docker (or colima, or podman)
29+
- An IDE — PyCharm is what the docs will usually use.
2930

3031
### Set up environment variables
3132

3233
You can copy `example.env` to `.env` and fill in the required values.
3334

34-
- Set `POSTGRES_PASSWORD` to a secure password.
35-
- Set `SECRET_KEY` to a secure secret key. You can use `from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())` in a python shell to generate it.
36-
- Optionally you can set `DEBUG` to `1` if needed
35+
- Set `POSTGRES_PASSWORD` to a secure password. It will just be for your local machine.
36+
- Set `SECRET_KEY` to a secure secret key.
37+
You can use `from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())` in a
38+
python shell to generate it, or you can let a cat walk on your keyboard.
39+
- Optionally you can set `DEBUG` to `1` if needed. See the
40+
[django docs](https://docs.djangoproject.com/en/5.2/ref/settings/#debug) for why you would.
3741
- Set `RUN_ENVIRONMENT=dev` if you want to see the developer endpoints.
3842

3943
### Running the API
@@ -52,11 +56,33 @@ Once the api is started you can run the tests using the following command.
5256

5357
Run tests
5458
```
55-
docker exec -it mapdb-django-dev pytest
59+
docker compose exec django pytest
60+
```
61+
62+
If it's not running already then use `docker compose run` instead.
63+
64+
### Committing code
65+
66+
We use [pre-commit](https://pre-commit.com/) to run checks prior to committing code. Pre-commit's settings are in the
67+
file [.pre-commit-config.yaml](/CnCNet/cncnet-map-api/blob/main/.pre-commit-config.yaml)
68+
69+
If you have python installed natively, you can just do the following in the `cncnet-map-api` project directory.
70+
71+
```shell
72+
pip install pre-commit
73+
pre-commit install
74+
```
75+
76+
If you use [UV](https://github.com/astral-sh/uv) then you can use the following command to install `pre-commit`[^1].
77+
78+
```shell
79+
uv tool install pre-commit
80+
pre-commit install
5681
```
5782

5883
## Production
5984

85+
> [!warning]
6086
> This section is still a WIP...
6187
6288
Follow this guide to set up the app for production.
@@ -130,9 +156,9 @@ natively on Windows is a... less-than-pleasant effort. So use docker instead.
130156

131157
1. Install docker for windows. I have had success with [Rancher Desktop](https://rancherdesktop.io/)
132158
or [Docker Desktop](https://docs.docker.com/desktop/setup/install/windows-install/)
133-
2. After docker is running, switch to your local git repo and run `docker compose up windows-dev -d`.
159+
2. After docker is running, switch to your local git repo and run `docker compose -f docker-compose.debugger.yml up debugger-django -d`.
134160
Make sure the build succeeds.
135-
3. Set `windows-dev` as your python interpreter for whichever editor you use.
161+
3. Set `debugger-django` as your python interpreter for whichever editor you use.
136162

137163
> [!TIP]
138164
> In Pycharm you go to `Settings > Project > Python Interpreter > Add Interpreter > Docker Compose`
@@ -146,11 +172,15 @@ All you need to do is run the database from `docker-compose`, then launch the te
146172
**If you want to run the tests via CLI:**
147173

148174
- Make sure your database is running from the docker compose file. `docker-compose start db`
149-
- Make sure your environment variables are setup and loaded to your shell. See [backend dev setup](#load-shell-env)
175+
- Make sure your environment variables are set up and loaded to your shell. See [backend dev setup](#load-shell-env)
150176
- Run `DJANGO_SETTINGS_MODULE="kirovy.settings.testing" pytest tests`
151177

152178
Django should automatically run migrations as part of the test startup.
153179

154180
**Run tests with docker compose:**
155181

156182
- `docker-compose up --build test`
183+
184+
# Footnotes
185+
186+
[^1]: Thank you to [Adam Johnson](https://adamj.eu/tech/2025/05/07/pre-commit-install-uv/) for the UV guide.

docker-compose.debugger.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ services:
1212
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
1313
env_file:
1414
- .env
15+
# necessary for rootless containers because postgres makes a new user if running as uid=0, and subuid will make the
16+
# container uid 0 by default. The `postgres` user won't have the necessary permissions for the volume path.
17+
userns_mode: keep-id
1518
ports:
1619
- "127.0.0.1:${POSTGRES_PORT}:${POSTGRES_PORT}"
1720
command: -p ${POSTGRES_PORT}

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ line-length = 120 # GitHub's line length. Black will help prevent you from need
33
target-version = ['py312']
44

55
[project]
6-
requires-python = "3.12.4"
6+
requires-python = ">=3.12.4"
77
name = "cncnet-map-api"
88
dynamic = ["version"]

0 commit comments

Comments
 (0)