Skip to content

Commit f344585

Browse files
authored
Added nix for developer setup (#1379) (#1602)
Tested on brand new machines, made a few minor docs tweaks and adjustments for findings, but generally went well so I'm merging this.
1 parent 287832b commit f344585

15 files changed

+450
-169
lines changed

.envrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# we have checks to account for first time setup
2+
if [ -f ".env" ]; then
3+
dotenv
4+
fi
5+
if [ -f "$HOME/.config/nix/nix.conf" ] || [ -f "/etc/nix/nix.conf" ]; then
6+
echo "Loading nix shell environment."
7+
use flake
8+
fi

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ media
147147
python.log
148148

149149
# direnv
150-
.envrc
150+
.direnv
151151
.local_env
152152

153153
.DS_Store

README.md

Lines changed: 54 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ A Django based website that will power a new Boost website. See the [documentati
66

77
Links:
88

9-
- https://www.stage.boost.cppalliance.org/ - staging
9+
- https://stage.boost.org/ - staging
1010
- https://www.boost.org/ - production
1111

1212
---
@@ -15,54 +15,66 @@ Links:
1515

1616
This project will use Python 3.13, Docker, and Docker Compose.
1717

18-
Instructions to install those packages are included in [development_setup_notes.md](docs/development_setup_notes.md).
19-
20-
**NOTE**: All of these various `docker compose` commands, along with other helpful
21-
developer utility commands, are codified in our `justfile` and can be ran with
22-
less typing.
23-
24-
You will need to install `just`, by [following the documentation](https://just.systems/man/en/)
25-
26-
**Environment Variables**: Copy file `env.template` to `.env` and adjust values to match your local environment. See [Environment Variables](docs/env_vars.md) for more information.
27-
28-
```shell
29-
$ cp env.template .env
30-
```
31-
32-
**NOTE**: Double check that the exposed port assigned to the PostgreSQL
33-
container does not clash with a database or other server you have running
34-
locally.
35-
36-
Then run:
18+
There are two options for development setups, nix and native. The native setup doesn't require nix to be installed. The nix-based setup works in a similar way to a python venv, with everything encapsulated for the project. Note: it is not a vm. It handles installation of all of the application and development environment's dependencies automatically:
19+
20+
- The python version relevant to the project
21+
- awscli
22+
- gdk
23+
- just
24+
- opentofu
25+
- nodejs
26+
- yarn
27+
- asciidoctor
28+
- asciidoctor-boost gem
29+
- pre-commit
30+
- black
31+
- isort
32+
- pip-tools
33+
34+
35+
1. Development System setup
36+
1. Give your ssh key to Sam so he can add it to the boost.cpp.al server.
37+
1. Basic Setup Options:
38+
1. [Nix-based](docs/development_setup_notes_nix.md)
39+
1. [Native](docs/development_setup_notes_native.md)
40+
1. [Initial Data Setup](docs/first_time_data_import.md)
41+
1. [Allauth Social Login Setup](docs/allauth_setup.md)
42+
1. System Concepts
43+
1. [GitHub Data Syncing](docs/syncing_data_with_github.md)
44+
1. [Rendered Content Caching](docs/caching_rendered_content.md)
45+
1. [Static Content from S3](docs/static_content.md)
46+
1. ['manage' Commands](docs/commands.md)
47+
1. [API](docs/api.md)
48+
1. [RSS Feeds](docs/rss_feeds.md)
49+
1. [Env Vars](docs/env_vars.md)
50+
1. [Calendar](docs/calendar.md)
51+
1. [News](docs/news.md)
52+
1. Instructional
53+
1. [Dependency Updates](docs/dependencies.md)
54+
1. [Release Reports](docs/release_reports.md)
55+
1. [User Management](docs/user_management.md)
56+
1. [Non-Dev Server Allauth Setup](docs/non-dev-server-allauth-setup.md)
57+
1. [Admin Features](docs/admin.md)
58+
1. [Mailing List Setup](docs/mailing_list.md)
59+
60+
After going through the "Development System setup" steps above to create the Docker image, install dependencies, and start the services in `docker-compose.yml`, run:
3761

3862
```shell
3963
# start our services (and build them if necessary)
4064
$ docker compose up
4165

4266
# to create database migrations
43-
$ docker compose run --rm web python manage.py makemigrations
67+
$ just makemigrations
4468

4569
# to run database migrations
46-
$ docker compose run --rm web python manage.py migrate
70+
$ just migrate
4771

4872
# to create a superuser
49-
$ docker compose run --rm web python manage.py createsuperuser
73+
$ just manage createsuperuser
5074
```
5175

52-
This will create the Docker image, install dependencies, start the services
53-
defined in `docker-compose.yml`, and start the webserver.
54-
5576
styles.css is still missing in a local docker-compose environment. Steps to add it:
5677

57-
```
58-
# One-time setup
59-
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
60-
. ~/.bashrc
61-
nvm install 20
62-
nvm use 20
63-
npm install -g yarn
64-
```
65-
6678
```
6779
# Each time - rebuild styles.css
6880
yarn
@@ -90,13 +102,13 @@ $ docker compose down
90102
To run the tests, execute:
91103

92104
```shell
93-
$ docker compose run --rm web pytest
105+
$ just test
94106
```
95107

96108
or run:
97109

98110
```shell
99-
$ just test
111+
$ docker compose run --rm web pytest
100112
```
101113

102114
## Yarn and Tailwind
@@ -125,23 +137,10 @@ currently generated by `docker compose build` and is included in the Docker imag
125137

126138
---
127139

128-
## Generating Local Data
129-
130-
To **add real Boost libraries and sync all the data from GitHub and S3**, set appropriate values in your new .env file according to [Environment Variables](docs/env_vars.md) for `GITHUB_TOKEN`, `STATIC_CONTENT_AWS_ACCESS_KEY_ID`, `STATIC_CONTENT_AWS_SECRET_ACCESS_KEY`, `STATIC_CONTENT_BUCKET_NAME`, `STATIC_CONTENT_REGION`, `STATIC_CONTENT_AWS_S3_ENDPOINT_URL` then run:
131-
132-
```bash
133-
docker compose run --rm web python manage.py update_libraries --local
134-
```
135-
136-
Those values can be gotten from another developer in the `#boost-website` Slack channel.
137-
138-
The `--local` flag speeds up the command a lot by excluding the retrieval of data you generally don't need. For more information, see `update_libraries` in [Management Commands](docs/commands.md).
139-
140-
Then as a superuser log into the admin interface, go to "Versions" and click on the "import new releases" button in the top right.
140+
## Setting up Mailman/Hyperkitty locally
141141

142-
---
142+
Note: This is optional - not required for the website to function, here for reference in case a need arises.
143143

144-
## Setting up Mailman/Hyperkitty locally
145144
``shell
146145
sudo apt-get install sassc
147146
git clone git@gitlab.com:mailman/hyperkitty.git
@@ -152,7 +151,7 @@ pip install psycopg2-binary
152151
``
153152
change settings.py to use postgres database:
154153
'ENGINE': 'django.db.backends.postgresql_psycopg2',
155-
Update database values in settings to use the same host, user, password, and the database name as in the .env file value for `HYPERKITTY_DATABASE_NAME`.
154+
Update database values in settings to use the same host, user, password, and the database name as in the .env file value for `HYPERKITTY_DATABASE_NAME` (`lists_production_web` by default).
156155

157156
run `django-admin migrate --pythonpath example_project --settings settings`
158157

@@ -172,7 +171,7 @@ psql -U postgres -W hyperkitty_db < /lists_stage_web.staging-db1-2.2025-02-06-08
172171

173172
To work with mailinglist data locally, the django application expects to be
174173
able to query a copy of the hyperkitty database from HYPERKITTY_DATABASE_NAME.
175-
Then, the `sync_mailinglist_stats` management command can be run.
174+
Then, `just manage sync_mailinglist_stats` management command can be run.
176175

177176
## Deploying
178177

@@ -186,25 +185,14 @@ TDB
186185

187186
## Pre-commit Hooks
188187

189-
We use [pre-commit hooks](https://pre-commit.com/) to check code for style, syntax, and other issues. They help to maintain consistent code quality and style across the project, and prevent issues from being introduced into the codebase..
188+
We use [pre-commit hooks](https://pre-commit.com/) to check code for style, syntax, and other issues. They help to maintain consistent code quality and style across the project, and prevent issues from being introduced into the codebase.
190189

191190
| Pre-commit Hook | Description |
192191
| --------------- | ----------- |
193192
| [Black](https://github.com/psf/black) | Formats Python code using the `black` code formatter |
194193
| [Ruff](https://github.com/charliermarsh/ruff) | Wrapper around `flake8` and `isort`, among other linters |
195194
| [Djhtml](https://github.com/rtts/djhtml) | Auto-formats Django templates |
196195

197-
### Setup and Usage
198-
199-
| Description | Command |
200-
| ---- | ------- |
201-
| 1. Install the `pre-commit` package using `pip` | `pip install pre-commit` |
202-
| 2. Install our list of pre-commit hooks locally | `pre-commit install` |
203-
| 3. Run all hooks for changed files before commit | `pre-commit run` |
204-
| 4. Run specific hook before commit | `pre-commit run {hook}` |
205-
| 5. Run hooks for all files, even unchanged ones | `pre-commit run --all-files` |
206-
| 6. Commit without running pre-commit hooks | `git commit -m "Your commit message" --no-verify` |
207-
208196
Example commands for running specific hooks:
209197

210198
| Hook | Example |

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
- [Boost Mailing List](./mailing_list.md) -Includes OAuth instructions
55
- [Caching and the `RenderedContent` model](./caching_rendered_content.md)
66
- [Dependency Management](./dependencies.md)
7-
- [Development Setup Notes](./development_setup_notes.md)
7+
- [Development Setup Notes](development_setup_notes_native.md)
88
- [Environment Variables](./env_vars.md)
99
- [Events Calendar](./calendar.md)
1010
- [Example Files](./examples/README.md) - Contains samples of `libraries.json`. `.gitmodules`, and other files that Boost data depends on

docs/allauth_setup.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
### Social Login with django-allauth
2+
3+
Follow these instructions to use the social logins through django-allauth on your local machine.
4+
5+
See https://testdriven.io/blog/django-social-auth/ for more information.
6+
7+
#### Github
8+
- Go to https://github.com/settings/applications/new and add a new OAuth application
9+
- Set `http://localhost:8000` as the Homepage URL
10+
- Set `http://localhost:8000/accounts/github/login/callback/` as the Callback URL
11+
- Click whether you want to enable the device flow
12+
- <img src="https://user-images.githubusercontent.com/2286304/252841283-9a846c68-46bb-4dac-8d1e-d35270c09f1b.png" alt="The GitHub screen that registers a new OAuth app" width="400">
13+
- On completion copy the Client ID and Client Secret to the `.env` file as values of `GITHUB_OAUTH_CLIENT_ID` and `GITHUB_OAUTH_CLIENT_SECRET`.
14+
- Run `direnv allow` and restart your docker containers.
15+
16+
Setup should be complete and you should be able to see an option to "Use Github" on the sign up page.
17+
18+
To test the flow including authorizing Github for the Boost account, log into your GitHub account settings and click **Applications** in the left menu. Find the "Boost" authorization and delete it. The next time you log into Boost with this GitHub account, you will have to re-authorize it.
19+
20+
<img src="https://user-images.githubusercontent.com/2286304/204642346-8b269aaf-4693-4351-9474-0a998b97689c.png" alt="The 'Authorized OAuth Apps' tab in your GitHub Applications" width="400">
21+
22+
This setup process is not something that can currently be automated through terraform because of a lack of relevant Github API endpoints to create Oauth credentials.
23+
24+
#### Google
25+
26+
More detailed instructions at:
27+
28+
https://docs.allauth.org/en/latest/socialaccount/providers/google.html
29+
30+
1. Update the `.env` file with values for:
31+
1. `TF_VAR_google_cloud_email` (the email address of your Google Cloud account)
32+
2. `TF_VAR_google_organization_domain` (usually the domain of your Google Cloud account, e.g. "boost.org" if you will be using a @boost.org email address)
33+
3. `TF_VAR_google_cloud_project_name` (optional, default: localboostdev) - needs to change if destroyed and a setup is needed within 30 days
34+
2. Run `just development-tofu-init` to initialize tofu.
35+
3. Run `just development-tofu-plan` to confirm the planned changes.
36+
4. Run `just development-tofu-apply` to apply the changes.
37+
5. Go to https://console.developers.google.com/
38+
1. Search for the newly created project, named "Boost Development" (ID: localboostdev by default).
39+
2. Type "credentials" in the search input at the top of the page.
40+
3. Select "Credentials" under "APIs & Services".
41+
1. Click "+ CREATE CREDENTIALS"
42+
2. Select "OAuth Client ID"
43+
3. Select Application Type: "Web application"
44+
4. Name: "Boost Development" (arbitrary)
45+
5. For "Authorized Javascript Origins" use:`http://localhost:8000`
46+
6. For "Authorized Redirect URIs" use:
47+
* `http://localhost:8000/accounts/google/login/callback/`
48+
* `http://localhost:8000/accounts/google/login/callback/?flowName=GeneralOAuthFlow`
49+
7. Save
50+
6. From the page that's displayed, update the `.env` file with values for the following:
51+
- `GOOGLE_OAUTH_CLIENT_ID` should be similar to "k235bn2b1l1(...)asdsk.apps.googleusercontent.com"
52+
- `GOOGLE_OAUTH_CLIENT_SECRET` should be similar to "LAJACO(...)KLAI612ANAD"
53+
54+
Point 5 above can not be automated through terraform because of a lack of relevant Google Cloud API endpoints to create Oauth credentials.
55+
56+
Setup should be complete and you should be able to see an option to "Use Google" on the sign up page.
57+
58+
#### Additional Notes on allauth login flows:
59+
**Working locally**: If you need to run through the login flows multiple times, create a superuser so you can log into the admin. Then, log into the admin and delete your "Social Account" from the admin. This will test a fresh connection to GitHub for your logged-in GitHub user.
Lines changed: 14 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -271,72 +271,24 @@ cd website-v2
271271
cp env.template .env
272272
```
273273

274-
Edit the .env, adding AWS keys.
275-
276-
Continue to the instructions in the top-level README.md file.
277-
278-
## Local Development
279-
280-
### Social Login with django-allauth
281-
282-
Follow these instructions to use the social logins through django-allauth on your local machine.
283-
284-
See https://testdriven.io/blog/django-social-auth/ for more information.
285-
286-
#### Github
287-
- Go to https://github.com/settings/applications/new and add a new OAuth application
288-
- Set `http://localhost:8000` as the Homepage URL
289-
- Set `http://localhost:8000/accounts/github/login/callback/` as the Callback URL
290-
- Click whether you want to enable the device flow
291-
- <img src="https://user-images.githubusercontent.com/2286304/252841283-9a846c68-46bb-4dac-8d1e-d35270c09f1b.png" alt="The GitHub screen that registers a new OAuth app" width="400">
292-
- On completion copy the Client ID and Client Secret to the `.env` file as values of `GITHUB_OAUTH_CLIENT_ID` and `GITHUB_OAUTH_CLIENT_SECRET`.
293-
- Run `direnv allow` and restart your docker containers.
274+
Edit the .env, adding AWS keys, and adjust values to match your local environment. See [Environment Variables](docs/env_vars.md) for more information.
294275

295-
Setup should be complete and you should be able to see an option to "Use Github" on the sign up page.
276+
**NOTE**: Double check that the exposed port assigned to the PostgreSQL
277+
container does not clash with a database or other server you have running
278+
locally.
296279

297-
To test the flow including authorizing Github for the Boost account, log into your GitHub account settings and click **Applications** in the left menu. Find the "Boost" authorization and delete it. The next time you log into Boost with this GitHub account, you will have to re-authorize it.
280+
### Pre-commit Hooks Setup
298281

299-
<img src="https://user-images.githubusercontent.com/2286304/204642346-8b269aaf-4693-4351-9474-0a998b97689c.png" alt="The 'Authorized OAuth Apps' tab in your GitHub Applications" width="400">
282+
| Description | Command |
283+
| ---- | ------- |
284+
| 1. Install the `pre-commit` package using `pip` | `pip install pre-commit` |
285+
| 2. Install our list of pre-commit hooks locally | `pre-commit install` |
286+
| 3. Run all hooks for changed files before commit | `pre-commit run` |
287+
| 4. Run specific hook before commit | `pre-commit run {hook}` |
288+
| 5. Run hooks for all files, even unchanged ones | `pre-commit run --all-files` |
289+
| 6. Commit without running pre-commit hooks | `git commit -m "Your commit message" --no-verify` |
300290

301-
This setup process is not something that can currently be automated through terraform because of a lack of relevant Github API endpoints to create Oauth credentials.
302-
303-
#### Google
304-
305-
More detailed instructions at:
306-
307-
https://docs.allauth.org/en/latest/socialaccount/providers/google.html
308-
309-
1. Update the `.env` file with values for:
310-
1. `TF_VAR_google_cloud_email` (the email address of your Google Cloud account)
311-
2. `TF_VAR_google_organization_domain` (usually the domain of your Google Cloud account, e.g. "boost.org" if you will be using an @boost.org email address)
312-
3. `TF_VAR_google_cloud_project_name` (optional, default: localboostdev) - needs to change if destroyed and a setup is needed within 30 days
313-
2. Run `just development-tofu-init` to initialize tofu.
314-
3. Run `just development-tofu-plan` to confirm the planned changes.
315-
4. Run `just development-tofu-apply` to apply the changes.
316-
5. Go to https://console.developers.google.com/
317-
1. Search for the newly created project, named "Boost Development" (ID: localboostdev by default).
318-
2. Type "credentials" in the search input at the top of the page.
319-
3. Select "Credentials" under "APIs & Services".
320-
1. Click "+ CREATE CREDENTIALS"
321-
2. Select "OAuth Client ID"
322-
3. Select Application Type: "Web application"
323-
4. Name: "Boost Development" (arbitrary)
324-
5. For "Authorized Javascript Origins" use:`http://localhost:8000`
325-
6. For "Authorized Redirect URIs" use:
326-
* `http://localhost:8000/accounts/google/login/callback/`
327-
* `http://localhost:8000/accounts/google/login/callback/?flowName=GeneralOAuthFlow`
328-
7. Save
329-
6. From the page that's displayed, update the `.env` file with values for the following:
330-
- `GOOGLE_OAUTH_CLIENT_ID` should be similar to "k235bn2b1l1(...)asdsk.apps.googleusercontent.com"
331-
- `GOOGLE_OAUTH_CLIENT_SECRET` should be similar to "LAJACO(...)KLAI612ANAD"
332-
7. Run `direnv allow` and restart your docker containers.
333-
334-
Point 5 above can not be automated through terraform because of a lack of relevant Google Cloud API endpoints to create Oauth credentials.
335-
336-
Setup should be complete and you should be able to see an option to "Use Google" on the sign up page.
337-
338-
#### Additional Notes:
339-
**Working locally**: If you need to run through the login flows multiple times, create a superuser so you can log into the admin. Then, log into the admin and delete your "Social Account" from the admin. This will test a fresh connection to GitHub for your logged-in GitHub user.
291+
Continue to the instructions in the top-level README.md file.
340292

341293
### Debugging
342294
For local development there is Django Debug Toolbar, and the option to set a debugger.

0 commit comments

Comments
 (0)