Further production updates #99
6 changed files with 42 additions and 143 deletions
4
Makefile
4
Makefile
|
@ -10,8 +10,8 @@ export GID
|
|||
frontend/node_modules:
|
||||
docker run --rm -v ${PWD}/frontend:/app -w /app -u ${UID}:${GID} node:16-bullseye npm i
|
||||
|
||||
backend/right_tree/staticfiles:
|
||||
docker run --rm -v ${PWD}/backend:/app -w /app -u ${UID}:${GID} right-tree python manage.py collectstatic --noinput
|
||||
frontend/build: frontend/node_modules
|
||||
docker run --rm -v ${PWD}/frontend:/app -w /app -u ${UID}:${GID} node:16-bullsye npm build
|
||||
|
||||
ingest:
|
||||
docker-compose up -d backend postgres
|
||||
|
|
|
@ -34,7 +34,7 @@ def generate_pdf(questionnaire_id, export_id):
|
|||
else:
|
||||
if not storage.exists(filename):
|
||||
raise FileNotFoundError(f"There was an error creating file: {filename}")
|
||||
finally:
|
||||
|
||||
if e.completion >= 1:
|
||||
generate_zip.delay(export_id)
|
||||
|
||||
|
|
138
dev
138
dev
|
@ -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" "$@"
|
|
@ -1,6 +1,10 @@
|
|||
version: "3.8"
|
||||
|
||||
volumes:
|
||||
righttree-static:
|
||||
name: righttree-static
|
||||
righttree-media:
|
||||
name: righttree-media
|
||||
righttree-postgres-data:
|
||||
name: righttree-postgres-data
|
||||
|
||||
|
@ -9,8 +13,21 @@ x-django: &django
|
|||
env_file: .env
|
||||
user: "$UID:$GID"
|
||||
restart: always
|
||||
volumes:
|
||||
- righttree-media:/app/right_tree/media
|
||||
- righttree-static:/app/right_tree/staticfiles
|
||||
|
||||
|
||||
services:
|
||||
collectstatic:
|
||||
<<: *django
|
||||
container_name: collectstatic
|
||||
command:
|
||||
- python
|
||||
- manage.py
|
||||
- collectstatic
|
||||
- --noinput
|
||||
|
||||
backend:
|
||||
<<: *django
|
||||
container_name: backend
|
||||
|
@ -27,6 +44,8 @@ services:
|
|||
condition: service_healthy
|
||||
celery:
|
||||
condition: service_healthy
|
||||
collectstatic:
|
||||
condition: service_completed_successfully
|
||||
|
||||
nginx:
|
||||
container_name: nginx
|
||||
|
@ -65,6 +84,11 @@ services:
|
|||
image: redis:7.0.10
|
||||
restart: always
|
||||
container_name: redis
|
||||
volumes:
|
||||
- ./redis.conf:/usr/local/etc/redis/redis.conf:ro
|
||||
command:
|
||||
- redis-server
|
||||
- /usr/local/etc/redis/redis.conf
|
||||
expose:
|
||||
- "6379"
|
||||
healthcheck:
|
||||
|
|
|
@ -13,6 +13,15 @@ x-django: &django
|
|||
restart: unless-stopped
|
||||
|
||||
services:
|
||||
collectstatic:
|
||||
<<: *django
|
||||
container_name: collectstatic
|
||||
command:
|
||||
- python
|
||||
- manage.py
|
||||
- collectstatic
|
||||
- --noinput
|
||||
|
||||
backend:
|
||||
<<: *django
|
||||
container_name: backend
|
||||
|
@ -23,6 +32,8 @@ services:
|
|||
condition: service_healthy
|
||||
celery:
|
||||
condition: service_healthy
|
||||
collectstatic:
|
||||
condition: service_completed_successfully
|
||||
expose:
|
||||
- "8000"
|
||||
command:
|
||||
|
|
|
@ -17,6 +17,8 @@ http {
|
|||
|
||||
location / {
|
||||
root /etc/nginx/html/build;
|
||||
index index.html;
|
||||
try_files $uri /index.html;
|
||||
}
|
||||
|
||||
location /staticfiles {
|
||||
|
|
Loading…
Reference in a new issue