Further production updates #99

Merged
mattn merged 1 commit from matt/prod into main 2023-03-30 14:31:52 +13:00
6 changed files with 42 additions and 143 deletions
Showing only changes of commit 00afd05abb - Show all commits

View file

@ -10,8 +10,8 @@ export GID
frontend/node_modules: frontend/node_modules:
docker run --rm -v ${PWD}/frontend:/app -w /app -u ${UID}:${GID} node:16-bullseye npm i docker run --rm -v ${PWD}/frontend:/app -w /app -u ${UID}:${GID} node:16-bullseye npm i
backend/right_tree/staticfiles: frontend/build: frontend/node_modules
docker run --rm -v ${PWD}/backend:/app -w /app -u ${UID}:${GID} right-tree python manage.py collectstatic --noinput docker run --rm -v ${PWD}/frontend:/app -w /app -u ${UID}:${GID} node:16-bullsye npm build
ingest: ingest:
docker-compose up -d backend postgres docker-compose up -d backend postgres

View file

@ -34,9 +34,9 @@ def generate_pdf(questionnaire_id, export_id):
else: else:
if not storage.exists(filename): if not storage.exists(filename):
raise FileNotFoundError(f"There was an error creating file: {filename}") raise FileNotFoundError(f"There was an error creating file: {filename}")
finally:
if e.completion >= 1: if e.completion >= 1:
generate_zip.delay(export_id) generate_zip.delay(export_id)
@shared_task @shared_task

138
dev
View file

@ -1,138 +0,0 @@
#!/bin/bash
# Load .env file if it exists
if [ -f .env ]
then
export $(cat .env | sed 's/#.*//g' | xargs)
fi
cmd_create_database() {
echo "Creating right_tree database..."
docker-compose down --remove-orphans --volumes
docker-compose -f docker-compose.yaml up postgres | sed '/PostgreSQL init process complete; ready for start up./q'
docker-compose down
}
cmd_makemigrations() {
echo "Creating database migrations..."
docker-compose exec backend python manage.py makemigrations --no-input
}
cmd_migrate() {
echo "Running database migrations..."
docker-compose exec backend python manage.py migrate
}
cmd_createsuperuser() {
echo "Creating django superuser..."
docker-compose run backend python manage.py createsuperuser
}
cmd_load_fixtures() {
echo "Loading fixtures..."
docker-compose exec backend bash -c "python manage.py loaddata right_tree/api/data/fixtures/*.json"
}
cmd_load_shapefiles() {
echo "Loading shapefiles into the database..."
docker-compose exec backend python manage.py loadshapefiles
}
cmd_create_plant_fixtures() {
echo "Creates fixtures for plants using spreadsheet."
docker-compose exec backend python manage.py createplantfixtures
}
cmd_reset_plants() {
echo "Resetting plants..."
docker-compose exec backend python manage.py resetplants
}
cmd_load_plant_fixtures() {
echo "Loading plants..."
docker-compose exec backend python manage.py loaddata right_tree/api/data/fixtures/plants.json
}
cmd_load_plants() {
cmd_create_plant_fixtures
cmd_reset_plants
cmd_load_plant_fixtures
}
cmd_load_sites_from_spreadsheet() {
echo "Loading habitats and zones..."
docker-compose exec backend python manage.py loadsitedata
}
cmd_populate_database() {
echo "Populating the database..."
docker-compose up -d backend postgres
cmd_makemigrations
cmd_migrate
cmd_load_fixtures
cmd_load_shapefiles
cmd_load_plants
docker-compose down
}
cmd_init_database() {
cmd_create_database
cmd_populate_database
}
cmd_reset_database() {
cmd_init_database
}
cmd_build() {
docker-compose build
}
cmd_start() {
docker-compose up --remove-orphans
}
cmd_collectstatic() {
docker-compose -f docker-compose.production.yaml build
docker-compose -f docker-compose.production.yaml run backend python manage.py collectstatic --no-input
}
cmd_build_frontend() {
docker run -v $PWD/frontend:/app -w /app node:16-alpine3.11 npm install
docker run -v $PWD/frontend:/app -w /app node:16-alpine3.11 mkdir -p node_modules/.cache
docker run -v $PWD/frontend:/app -w /app node:16-alpine3.11 chmod -R 777 node_modules/.cache
docker run -v $PWD/frontend:/app -w /app node:16-alpine3.11 npm run build
}
cmd_create_staticfiles() {
cmd_collectstatic
cmd_build_frontend
}
cmd_build_production() {
docker-compose -f docker-compose.production.yaml build
}
cmd_start_production() {
docker-compose -f docker-compose.production.yaml up -d --remove-orphans
}
cmd_stop_production() {
docker-compose -f docker-compose.production.yaml stop --remove-orphans
}
cmd_renew_certifcate() {
cmd_stop_production
sudo docker run -i --rm --name certbot -p 443:443 -p 80:80 -v /etc/letsencrypt:/etc/letsencrypt/ certbot/certbot renew --dry-run -d $BASE_URL --logs-dir /etc/letsencrypt/logs
cmd_start_production
}
cmd_process_svg_files() {
docker run -v $PWD/frontend/src/assets/:/app/assets -v $PWD/process_svg.py:/app/process_svg.py -w /app python:3.8-slim-bullseye python process_svg.py
}
# Run the command
cmd="$1"
"cmd_$cmd" "$@"

View file

@ -1,6 +1,10 @@
version: "3.8" version: "3.8"
volumes: volumes:
righttree-static:
name: righttree-static
righttree-media:
name: righttree-media
righttree-postgres-data: righttree-postgres-data:
name: righttree-postgres-data name: righttree-postgres-data
@ -9,8 +13,21 @@ x-django: &django
env_file: .env env_file: .env
user: "$UID:$GID" user: "$UID:$GID"
restart: always restart: always
volumes:
- righttree-media:/app/right_tree/media
- righttree-static:/app/right_tree/staticfiles
services: services:
collectstatic:
<<: *django
container_name: collectstatic
command:
- python
- manage.py
- collectstatic
- --noinput
backend: backend:
<<: *django <<: *django
container_name: backend container_name: backend
@ -27,6 +44,8 @@ services:
condition: service_healthy condition: service_healthy
celery: celery:
condition: service_healthy condition: service_healthy
collectstatic:
condition: service_completed_successfully
nginx: nginx:
container_name: nginx container_name: nginx
@ -65,6 +84,11 @@ services:
image: redis:7.0.10 image: redis:7.0.10
restart: always restart: always
container_name: redis container_name: redis
volumes:
- ./redis.conf:/usr/local/etc/redis/redis.conf:ro
command:
- redis-server
- /usr/local/etc/redis/redis.conf
expose: expose:
- "6379" - "6379"
healthcheck: healthcheck:

View file

@ -13,6 +13,15 @@ x-django: &django
restart: unless-stopped restart: unless-stopped
services: services:
collectstatic:
<<: *django
container_name: collectstatic
command:
- python
- manage.py
- collectstatic
- --noinput
backend: backend:
<<: *django <<: *django
container_name: backend container_name: backend
@ -23,6 +32,8 @@ services:
condition: service_healthy condition: service_healthy
celery: celery:
condition: service_healthy condition: service_healthy
collectstatic:
condition: service_completed_successfully
expose: expose:
- "8000" - "8000"
command: command:

View file

@ -17,6 +17,8 @@ http {
location / { location / {
root /etc/nginx/html/build; root /etc/nginx/html/build;
index index.html;
try_files $uri /index.html;
} }
location /staticfiles { location /staticfiles {