This project uses Docker. The easiest way to get started is to install Docker Desktop which provides the docker
and docker-compose
commands.
After installing Docker, use the dev-setup script to run the project locally:
./scripts/dev-setup
This command will create an .env file with unique keys, build docker images and containers, run database migrations, and load fixture data.
With Docker Desktop running in the background, bring up the services by running:
docker-compose up
As you make changes, remember to run the tests…:
docker-compose exec app python manage.py test
docker-compose exec static npm run test
…and to make and apply database migrations:
docker-compose exec app python manage.py makemigrations
docker-compose exec app python manage.py migrate
The project has support for using Therapist to run pre-commit linting and formatting tools. You don't have to use it, but it makes it life easier.
therapist
is configured to run:
- black for code formatting
- flake8 for syntax checking
- isort for import-order management
- eslint for JavaScript checking
- prettier for JavaScript formatting
At the moment, this project assumes have all of the above installed and available on the $PATH
of your host machine, along with Python 3 and pip
. You can install the dependencies using virtualenv
and nvm
if you want, or not, or globally. As long as they're available, you're good.
(Note: this project is not currently supporting use of therapist
inside Docker containers.)
TIP: It's wise to enable all of the above tooling in your code editor, if possible, so that things are already in order before the pre-commit hook is run.
Install therapist
:
$ pip install therapist
Install the pre-commit hook that will trigger therapist
automatically:
$ therapist install
Installing pre-commit hook... DONE
(Take a look at the pre-commit file added to .git/hooks/
to confirm the path looks right.)
Now, when you git-commit
a change, the staged changes will be checked by one or more of black
, isort
, flake8
, eslint
and/or prettier
. See .therapist.yml
in the project root for the configuration.
Alternatively, if you wanted to run it across the whole codebase, run:
$ therapist run developerportal/
And if, for some reason, you want therapist
to auto-fix everything wrong using those tools, run:
$ therapist run developerportal/ --fix
Finally, therapist
can be passed a list of file paths if you want to just run it on specific things:
$ therapist run developerportal/path/to/file.js developerportal/path/to/another_file.py
GitHub OAuth is supported for admin login. When running in production, the auth pipeline checks to see if the GitHub user is a member of the mdn organization. Additional organizations can be added via the GITHUB_ORGS
env variable.
When running in debug any GitHub user is allowed to log in and is automatically given superuser status. It is possible to log in without using GitHub by creating a Django superuser as normal:
docker-compose exec app python manage.py createsuperuser
After pulling master you may need to install new dependencies…:
docker-compose build
…or run database migrations:
docker-compose exec app python manage.py migrate
If things get messed up, you could (as a last resort) prune ALL Docker images, containers and volumes, and start from scratch:
./setup.sh --prune
Wagtail Bakery can build a static version of the site. In production this runs automatically when pages are published or unpublished from the Wagtail admin.
To manually build the static site, run:
docker-compose exec app python manage.py build --settings=developerportal.settings.production
The result of this will be output to the /build directory.