Rename dev.sh to philomena and add up/down --drop-db commands

This commit is contained in:
MareStare 2025-04-06 16:12:10 +00:00
parent 6351563c6a
commit 9178ad7fdb
3 changed files with 87 additions and 29 deletions

View file

@ -1,29 +0,0 @@
#!/usr/bin/env bash
# Script to start the docker-compose stack for development.
set -euo pipefail
. "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
# Set this env var to `1` if you want to drop your current databases and
# reseed them from scratch again.
DROP_DB=${DROP_DB:-0}
if [[ "$DROP_DB" == "1" ]]; then
info "Dropping databases..."
# It's important to stop all containers to make sure they shut down cleanly.
# Also, `valkey` stores its data in RAM, so to drop its "database" we need
# to stop its container.
#
# We aren't using `--volumes` parameter with the `docker compose down` because
# we don't want to delete the build caches, which are also stored in volumes.
# Instead we remove only DB data volumes separately.
step docker compose down
step docker volume rm \
philomena_postgres_data \
philomena_opensearch_data
fi
step docker compose up --no-log-prefix

View file

@ -20,6 +20,21 @@ function warn {
echo -e "\033[33;1m[WARN]\033[0m \033[0;33m$message\033[0m" >&2
}
# Log a message at the error level
function error {
local message=$1
echo -e "\033[31;1m[ERROR]\033[0m \033[0;31m$message\033[0m" >&2
}
# Log a message at the error level and exit with a non-zero status
function die {
local message=$1
error "$message"
exit 1
}
# Log the command and execute it
function step {
local cmd="$1"

72
scripts/philomena Executable file
View file

@ -0,0 +1,72 @@
#!/usr/bin/env bash
# Script to start the docker-compose stack for development.
set -euo pipefail
. "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
function up {
# Delete the database volumes. This doesn't remove the build caches.
local drop_db=false
while [[ $# -gt 0 ]]; do
case "$1" in
--drop-db) drop_db=true ;;
*) die "Unknown option: $1" ;;
esac
shift
done
if [[ "$drop_db" == "true" ]]; then
drop_db
fi
step exec docker compose up --no-log-prefix
}
function down {
# Delete the database volumes. This doesn't remove the build caches.
local drop_db=false
while [[ $# -gt 0 ]]; do
case "$1" in
--drop-db) drop_db=true ;;
*) die "Unknown option: $1" ;;
esac
shift
done
if [[ "$drop_db" == "true" ]]; then
drop_db
else
step docker compose down
fi
}
function drop_db {
info "Dropping databases..."
# It's important to stop all containers to make sure they shut down cleanly.
# Also, `valkey` stores its data in RAM, so to drop its "database" we need
# to stop its container.
#
# We aren't using `--volumes` parameter with the `docker compose down` because
# we don't want to delete the build caches, which are also stored in volumes.
# Instead we remove only DB data volumes separately.
step docker compose down
step docker volume rm \
philomena_postgres_data \
philomena_opensearch_data
}
subcommand="${1:-}"
shift || true
case "$subcommand" in
up) up "$@" ;;
down) down "$@" ;;
*)
die "See the available sub-commands in ${BASH_SOURCE[0]}"
;;
esac