szabadpalya/scripts/dev.sh

36 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# Run the Go side in development, reading .env so nothing has to be exported by
# hand. Uses the containerised toolchain (scripts/go.sh), on the host network so
# that DATABASE_URL can say localhost:5433 exactly as it does everywhere else.
#
# ./scripts/dev.sh migrate apply migrations
# ./scripts/dev.sh seed load the fixture (wipes campaigns first)
# ./scripts/dev.sh server serve the API on :3000
#
# The frontend runs separately: cd web && pnpm dev (http://localhost:5173)
set -euo pipefail
cd "$(dirname "$0")/.."
[ -f .env ] || { echo "no .env — copy .env.example and fill it in"; exit 1; }
docker volume create szp-gocache >/dev/null
# -t only when there is a terminal to attach to, so this also works from a hook
# or a pipeline.
TTY=(); [ -t 0 ] && TTY=(-it)
run_go() {
docker run --rm "${TTY[@]}" --network host \
-v "$PWD/api:/src" -v szp-gocache:/gocache \
-e GOMODCACHE=/gocache/mod -e GOCACHE=/gocache/build \
--env-file .env -e WEB_DIR=/src/../web/dist -e APP_ENV=development \
-w /src golang:1.25-alpine go run "$@"
}
case "${1:-server}" in
migrate) run_go ./cmd/server -migrate ;;
seed) run_go ./test/seed ;;
server) run_go ./cmd/server ;;
*) echo "usage: $0 {server|migrate|seed}"; exit 2 ;;
esac