server/entrypoint.sh

38 lines
951 B
Bash
Raw Normal View History

#!/bin/bash
# This script is a wrapper for the main server, CLI and Prisma binaries.
# Commands:
# - `start`: Starts the server
# - `cli`: Starts the CLI, sends all arguments to it
# - `prisma`: Execute a Prisma command, sends
# Exit immediately if a command exits with a non-zero status.
2024-04-07 13:29:32 +02:00
set -euo pipefail
2024-04-07 13:38:17 +02:00
cd /app/dist
2024-04-07 10:56:15 +02:00
# Parse first argument
case "$1" in
"start")
2024-04-07 13:37:00 +02:00
# Migrate the database and run
/bin/bash /app/entrypoint.sh prisma migrate deploy && bun run ./index.js --prod
;;
"cli")
# Start the CLI
shift 1
2024-04-07 13:34:21 +02:00
bun run ./cli.js "$@"
;;
"prisma")
# Proxy all Prisma commands
# Use output of dist/prisma.js to get the env variable
shift 1
# Set DATABASE_URL env variable to the output of bun run ./dist/prisma.js
2024-04-07 10:56:15 +02:00
export DATABASE_URL=$(bun run ./prisma.js)
# Execute the Prisma binary
2024-04-07 13:34:21 +02:00
bun run ./node_modules/.bin/prisma "$@"
;;
*)
# Run custom commands
exec "$@"
;;
2024-04-07 13:37:00 +02:00
esac