#!/usr/bin/env bash usage () { echo "[?] usage: $0 [-h|-f|-p]" echo -e "\t-f run both frontend and backend (default: false)" echo -e "\t-p purge any existing database artifacts (default: false)" echo -e "\t-q only purge old data without building/spawning any new containers (default: false)" } # Default to running the backend only without destroying old data from previous runs RUN_FULLSTACK=false PURGE_ARTIFACTS=false # Optionally only purge the existing data without running any new containers PURGE_ONLY=false BACKEND_COMPOSE_FILE="docker/docker-compose-back.yml" FULL_COMPOSE_FILE="docker/docker-compose-full.yml" # Ensure we're at project root and the compose files exist [ -f ".env" ] || { echo "[!] run the script from project root" && exit 1; } [ -f "$BACKEND_COMPOSE_FILE" ] || { echo "[!] backend compose file missing" && exit 1; } [ -f "$FULL_COMPOSE_FILE" ] || { echo "[!] fullstack compose file missing" && exit 1; } while getopts "hfpq" OPTION; do case "$OPTION" in h) usage exit 0 ;; f) RUN_FULLSTACK=true ;; p) PURGE_ARTIFACTS=true ;; q) PURGE_ARTIFACTS=true PURGE_ONLY=true ;; ?) usage exit 1 ;; esac done if [ "$PURGE_ARTIFACTS" = true ] then echo "[+] purging old database artifacts" docker stop qnote-psql docker rm -f qnote-psql docker volume rm -f qnote-data # Backend mode [ -d "data" ] && sudo rm -rf data # Fullstack mode fi if [ "$PURGE_ONLY" = true ] then exit 0 fi [ "$( docker container inspect -f '{{.State.Status}}' qnote-psql )" = "running" ] || docker compose up qnote-psql -d &>/dev/null # Shutdown, rebuild, and restart relevant containers if [ "$RUN_FULLSTACK" = true ] then echo "[+] running in fullstack mode" docker compose stop qnote-server qnote-web docker compose rm -f qnote-server qnote-web docker compose --env-file .env -f "$FULL_COMPOSE_FILE" build docker compose --env-file .env -f "$FULL_COMPOSE_FILE" up qnote-server qnote-web else echo "[+] running in backend mode" docker compose stop qnote-server docker compose rm -f qnote-server docker compose --env-file .env -f "$BACKEND_COMPOSE_FILE" build docker compose --env-file .env -f "$BACKEND_COMPOSE_FILE" up qnote-server fi