Apply production fixes + docs

- Updates docker-compose database volume name
- Fixes CORS frontend URL issue in django settings
- Adds addtional docs to the production setup
This commit is contained in:
Dana Lambert 2021-12-10 13:17:37 +13:00
parent 23e05ce20e
commit 490d6fba80
3 changed files with 15 additions and 6 deletions

View file

@ -134,19 +134,25 @@ A summary of available commands are outlined below. Note that if the command req
Create an interactive terminal into the postgres container Create an interactive terminal into the postgres container
```bash ```bash
sudo docker-compose -f docker-compose.production.yaml up postgres sudo docker-compose -f docker-compose.production.yaml up -d postgres
sudo docker exec -it postgres bash sudo docker exec -it postgres bash
``` ```
Within the interactive terminal. Connect to the database, add the righttree_admin user and give permissions. Please use the same credentials as defined in .env. Within the interactive terminal. Connect to the database, add the righttree_admin user and give permissions. Please use the same credentials as defined in .env.
```bash ```bash
psql -U postgres psql -U postgres
/c righttree \c righttree
CREATE USER righttree_admin; CREATE USER righttree_admin;
ALTER USER righttree_admin with encrypted password 'YOUR PASSWORD'; ALTER USER righttree_admin with encrypted password 'YOUR PASSWORD';
GRANT ALL PRIVILEGES ON DATABASE righttree TO righttree_admin; GRANT ALL PRIVILEGES ON DATABASE righttree TO righttree_admin;
``` ```
Exit the container and stop postgres service:
```
[CTRL-D] - to exit psql THEN [CTRL-D] to exit container
sudo docker-compose -f docker-compose.production.yaml down
```
6. Populate the database using `sudo ./dev populate_database` 6. Populate the database using `sudo ./dev populate_database`
7. Build optimised frontend build and collect together staticfiles `sudo ./dev create_staticfiles` 7. Build optimised frontend build and collect together staticfiles `sudo ./dev create_staticfiles`
8. Create a django superuser for access to the admin interface. Please use the same credentials as defined in .env `sudo ./dev createsuperuser` 8. Create a django superuser for access to the admin interface. Please use the same credentials as defined in .env `sudo ./dev createsuperuser`

View file

@ -139,8 +139,11 @@ STATIC_ROOT = os.path.join(PROJECT_DIR, 'staticfiles')
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
frontend_url = os.getenv('FRONTEND_BASE_URL', 'localhost:3000')
CORS_ALLOWED_ORIGINS = [ CORS_ALLOWED_ORIGINS = [
os.getenv("FRONTEND_BASE_URL") or 'http://localhost:3000' f"https://{frontend_url}",
f"http://{frontend_url}"
] ]
CORS_ALLOW_HEADERS = [ CORS_ALLOW_HEADERS = [

View file

@ -1,8 +1,8 @@
version: "3.8" version: "3.8"
volumes: volumes:
local-postgres-data: righttree-postgres-data:
name: local-postgres-data name: righttree-postgres-data
services: services:
backend: backend:
@ -35,7 +35,7 @@ services:
restart: unless-stopped restart: unless-stopped
container_name: postgres container_name: postgres
volumes: volumes:
- local-postgres-data:/var/lib/postgresql/data - righttree-postgres-data:/var/lib/postgresql/data
- ./create_database.sql:/docker-entrypoint-initdb.d/create_database.sql - ./create_database.sql:/docker-entrypoint-initdb.d/create_database.sql
ports: ports:
- "5432:5432" - "5432:5432"