envelope/README.md

65 lines
2.1 KiB
Markdown
Raw Normal View History

2022-10-12 06:22:22 +00:00
# Envelope
Template Django app.
## Setting up the environment
Create the virtual environment, enable it, and install the dependencies.
```shell
$ python3 -m venv env
$ source env/bin/activate
2022-10-12 06:22:22 +00:00
(env) $ pip install -r docker/prod/requirements.prod.txt
2022-10-12 06:22:22 +00:00
```
## Local settings
You'll need to copy the `app/local_settings.example.py` file to `app/local_settings.py`. The project won't start otherwise.
```
$ cp app/local_settings.example.py app/local_settings.py
```
2022-10-12 06:22:22 +00:00
## stack.env
The stack.env file referenced is a Portainer special. This is where Portainer would put a file containing all the environment variables set up in its UI.
To run it manually, you will need to copy `stack.env.example` to `stack.env` in the project root.
2022-10-12 06:22:22 +00:00
## Running database migrations
Now we need to run the database migrations in order to get a working database.
```shell
(env) $ python manage.py migrate
```
2022-10-12 06:22:22 +00:00
Note that these are automatically run by a step in the compose file in production.
You won't need to do that manually.
2022-10-12 06:22:22 +00:00
## Creating a superuser
In order to access Django admin, we need a superuser.
```shell
(env) $ python manage.py createsuperuser
Username: t2
Email address: t2@google.com
Password:
Password (again):
Superuser created successfully.
```
2022-10-12 06:22:22 +00:00
## Running
The Docker Compose file is located in `docker/docker-compose.prod.yml`.
There is a shortcut to run it: `make run`.
2022-10-12 06:22:22 +00:00
2022-10-12 06:22:22 +00:00
## Stopping
To stop the containers, run `make stop`.
2022-10-12 06:22:22 +00:00
2022-10-12 06:22:22 +00:00
## Setup
This setup may be different from what you've seen before.
2022-10-12 06:22:22 +00:00
2022-10-12 06:22:22 +00:00
### Uvicorn
There is a Uvicorn worker in the `app` container listening on `/var/run/socks/app.sock`. This is the bit that runs the actual code.
2022-10-12 06:22:22 +00:00
2022-10-12 06:22:22 +00:00
### Nginx
Nginx runs in the `nginx` container and proxies requests to Uvicorn thanks to a mounted and shared directory. No TCP required.
### Pre-start steps
There's a few commands running before start to ensure Django works correctly.
#### Migration
The `migration` container step runs the migrations so you don't need to remember to do it.
#### Collectstatic
The `collectstatic` container step collects all static files from plugins and puts them in the `core/static` folder. This folder is served straight from Nginx without going through Uvicorn.