|
2 | 2 |
|
3 | 3 | Mataroa Collection list of blogs. |
4 | 4 |
|
5 | | -## Contributing |
6 | | - |
7 | | -Feel free to open a PR on [GitHub](https://github.com/sirodoht/illich) or |
8 | | -send an email patch to [~sirodoht/public- [email protected]](mailto:~sirodoht/[email protected]). |
9 | | - |
10 | | -On how to contribute using email patches see [git-send-email.io](https://git-send-email.io/). |
11 | | - |
12 | 5 | ## Development |
13 | 6 |
|
14 | | -This is a [Django](https://www.djangoproject.com/) codebase. Check out the |
15 | | -[Django docs](https://docs.djangoproject.com/) for general technical documentation. |
16 | | - |
17 | | -### Structure |
18 | | - |
19 | | -The Django project is `illich`. There is one Django app, `main`, with all business logic. |
20 | | -Application CLI commands are generally divided into two categories, those under `python manage.py` |
21 | | -and those under `make`. |
22 | | - |
23 | | -### Dependencies |
24 | | - |
25 | | -Using [venv](https://docs.python.org/3/library/venv.html): |
26 | | - |
27 | | -```sh |
28 | | -python3 -m venv venv |
29 | | -source venv/bin/activate |
30 | | -pip install -r requirements.txt |
31 | | -pip install -r requirements_dev.txt |
32 | | -``` |
33 | | - |
34 | | -This project also uses [pip-tools](https://github.com/jazzband/pip-tools) for dependency |
35 | | -management. |
36 | | - |
37 | | -### Environment variables |
38 | | - |
39 | | -A file named `.envrc` is used to define the environment variables required for this project to |
40 | | -function. One can either export it directly or use [direnv](https://github.com/direnv/direnv). |
41 | | -There is an example environment file one can copy as base: |
42 | | - |
43 | | -```sh |
44 | | -cp .envrc.example .envrc |
45 | | -``` |
46 | | - |
47 | | -`.envrc` should contain the following variables: |
48 | | - |
49 | | -```sh |
50 | | -export SECRET_KEY=some-secret-key |
51 | | -export DATABASE_URL=postgres://illich:db-password@db:5432/illich |
52 | | -export EMAIL_HOST_USER=smtp-user |
53 | | -export EMAIL_HOST_PASSWORD=smtp-password |
54 | | -``` |
55 | | - |
56 | | -When on production, also include the following variables (see [Deployment](#Deployment) and |
57 | | -[Backup](#Backup)): |
58 | | - |
59 | | -```sh |
60 | | -export NODEBUG=1 |
61 | | -export PGPASSWORD=db-password |
62 | | -``` |
63 | | - |
64 | | -### Database |
65 | | - |
66 | | -This project uses PostgreSQL. Assuming one has set the `DATABASE_URL` (see above), to create the |
67 | | -database schema: |
| 7 | +This is a standard [Django](https://docs.djangoproject.com/) application with |
| 8 | +[uv](https://github.com/astral-sh/uv). |
68 | 9 |
|
69 | | -```sh |
70 | | -python manage.py migrate |
71 | | -``` |
72 | | - |
73 | | -### Serve |
74 | | - |
75 | | -To run the Django development server: |
76 | | - |
77 | | -```sh |
78 | | -python manage.py runserver |
79 | | -``` |
80 | | - |
81 | | -### Docker |
82 | | - |
83 | | -If Docker and docker-compose are preferred, then: |
84 | | - |
85 | | -1. Set `DATABASE_URL` in `.envrc` to `postgres://postgres:postgres@db:5432/postgres` |
86 | | -1. Run `docker-compose up -d`. |
87 | | - |
88 | | -The database data will be saved in the git-ignored directory / Docker volume `db_data`, |
89 | | -located in the root of the project. |
90 | | - |
91 | | -## Testing |
92 | | - |
93 | | -Using the Django test runner: |
| 10 | +1. Create database tables with: |
94 | 11 |
|
95 | 12 | ```sh |
96 | | -python manage.py test |
| 13 | +uv run manage.py migrate |
97 | 14 | ``` |
98 | 15 |
|
99 | | -For coverage, run: |
| 16 | +2. Run development server with: |
100 | 17 |
|
101 | 18 | ```sh |
102 | | -make cov |
| 19 | +uv run manage.py runserver |
103 | 20 | ``` |
104 | 21 |
|
105 | | -## Code linting & formatting |
106 | | - |
107 | | -The following tools are used for code linting and formatting: |
| 22 | +## Format and lint |
108 | 23 |
|
109 | | -* [black](https://github.com/psf/black) for code formatting. |
110 | | -* [isort](https://github.com/pycqa/isort) for imports order consistency. |
111 | | -* [flake8](https://gitlab.com/pycqa/flake8) for code linting. |
112 | | - |
113 | | -To use: |
| 24 | +Run Python formatting with: |
114 | 25 |
|
115 | 26 | ```sh |
116 | | -make format |
117 | | -make lint |
| 27 | +uv run ruff format |
118 | 28 | ``` |
119 | 29 |
|
120 | | -## Deployment |
121 | | - |
122 | | -Deployment is configured using [uWSGI](https://uwsgi.readthedocs.io/en/latest/) |
123 | | -and [nginx](https://nginx.org/). |
124 | | - |
125 | | -Remember to set the environment variables before starting `uwsgi`. Depending on the deployment |
126 | | -environment, this could mean directly exporting the variables or just sourcing `.envrc` (with all |
127 | | -production variables — including `NODEBUG`): |
| 30 | +Run Python linting with: |
128 | 31 |
|
129 | 32 | ```sh |
130 | | -source .envrc |
131 | | -uwsgi illich.ini |
| 33 | +uv run ruff check --fix |
132 | 34 | ``` |
133 | 35 |
|
134 | | -Note that the value of the `NODEBUG` variable is ignored. What matters is merely its existence |
135 | | -in the environment. |
136 | | - |
137 | | -## Backup |
| 36 | +## Deploy |
138 | 37 |
|
139 | | -To automate backup, there is [a script](backup-database.sh) which dumps the database and uploads |
140 | | -it into AWS S3. The script also needs the database password as an environment variable. The |
141 | | -key needs to be `PGPASSWORD`. The backup script assumes the variable lives in `.envrc` like so: |
| 38 | +Every commit on branch `main` auto-deploys using GitHub Actions. To deploy manually: |
142 | 39 |
|
143 | 40 | ```sh |
144 | | -export PGPASSWORD=db-password |
145 | | -``` |
146 | | - |
147 | | -To restore a dump: |
148 | | - |
149 | | -```sh |
150 | | -pg_restore -v -h localhost -cO --if-exists -d illich -U illich -W illich.dump |
151 | | -``` |
152 | | - |
153 | | -To add on cron: |
154 | | - |
155 | | -```sh |
156 | | -0 */6 * * * /opt/apps/illich/backup-database.sh |
| 41 | +cd ansible/ |
| 42 | +cp .envrc.example .envrc |
| 43 | +uv run ansible-playbook playbook.yaml -v |
157 | 44 | ``` |
158 | 45 |
|
159 | 46 | ## License |
|
0 commit comments