right-tree/dev

129 lines
3.1 KiB
Text
Raw Normal View History

2021-10-15 15:20:14 +13:00
#!/bin/bash
# Load .env file if it exists
if [ -f .env ]
then
export $(cat .env | sed 's/#.*//g' | xargs)
fi
2021-10-15 15:20:14 +13:00
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..."
2021-11-16 17:30:40 +13:00
docker-compose exec backend python manage.py makemigrations --no-input
2021-10-15 15:20:14 +13:00
}
cmd_migrate() {
echo "Running database migrations..."
2021-11-16 17:30:40 +13:00
docker-compose exec backend python manage.py migrate
2021-10-15 15:20:14 +13:00
}
cmd_createsuperuser() {
2021-11-16 17:30:40 +13:00
echo "Creating django superuser..."
docker-compose run backend python manage.py createsuperuser
2021-10-15 15:20:14 +13:00
}
cmd_load_fixtures() {
echo "Loading fixtures..."
2021-11-16 17:30:40 +13:00
docker-compose exec backend bash -c "python manage.py loaddata right_tree/api/data/fixtures/*.json"
2021-10-15 15:20:14 +13:00
}
cmd_load_shapefiles() {
echo "Loading shapefiles into the database..."
2021-11-16 17:30:40 +13:00
docker-compose exec backend python manage.py loadshapefiles
2021-10-15 15:20:14 +13:00
}
cmd_create_plant_fixtures() {
echo "Creates fixtures for plants using spreadsheet."
docker-compose exec backend python manage.py createplantfixtures
2021-10-15 15:20:14 +13:00
}
cmd_reset_plants() {
echo "Resetting plants..."
2021-11-16 17:30:40 +13:00
docker-compose exec backend python manage.py resetplants
2021-10-15 15:20:14 +13:00
}
cmd_load_plant_fixtures() {
echo "Loading plants..."
2021-11-16 17:30:40 +13:00
docker-compose exec backend python manage.py loaddata right_tree/api/data/fixtures/plants.json
2021-10-15 15:20:14 +13:00
}
cmd_load_plants() {
cmd_create_plant_fixtures
cmd_reset_plants
cmd_load_plant_fixtures
}
cmd_load_sites_from_spreadsheet() {
echo "Loading habitats and zones..."
2021-11-16 17:30:40 +13:00
docker-compose exec backend python manage.py loadsitedata
}
2021-10-15 15:20:14 +13:00
cmd_populate_database() {
echo "Populating the database..."
2021-11-16 17:30:40 +13:00
docker-compose up -d backend postgres
2021-10-15 15:20:14 +13:00
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
2021-10-15 15:20:14 +13:00
}
cmd_collectstatic() {
2021-11-16 17:30:40 +13:00
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
2021-11-16 17:30:40 +13:00
}
cmd_build_production() {
docker-compose -f docker-compose.production.yaml build
}
cmd_start_production() {
docker-compose -f docker-compose.production.yaml up --remove-orphans
}
2021-11-16 17:30:40 +13:00
cmd_stop_production() {
docker-compose -f docker-compose.production.yaml stop --remove-orphans
}
2021-10-15 15:20:14 +13:00
# Run the command
cmd="$1"
"cmd_$cmd" "$@"