mirror of
https://github.com/Xevion/linkpulse.git
synced 2025-12-05 23:15:26 -06:00
Overhaul run.sh scripts
- Default environment variables through this, instead of .env - Added some basic checks to ensure developers don't stub their toe - Use `railway link`, injecting environment variables without insecure dotenv files
This commit is contained in:
@@ -1,3 +1,62 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
poetry run hypercorn linkpulse.app:app --reload
|
||||
# Check whether CWD is 'backend'
|
||||
if [ "$(basename "$(pwd)")" != "backend" ]; then
|
||||
echo "error: This script must be run from the 'backend' directory."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Default to development mode if not defined
|
||||
export ENVIRONMENT=${ENVIRONMENT:-development}
|
||||
COMMAND='poetry run hypercorn linkpulse.app:app --reload'
|
||||
|
||||
# Check if Railway CLI is available
|
||||
RAILWAY_AVAILABLE=false
|
||||
if command -v railway &> /dev/null; then
|
||||
RAILWAY_AVAILABLE=true
|
||||
fi
|
||||
|
||||
# Check if .env file exists
|
||||
ENV_FILE_EXISTS=false
|
||||
if [ -f .env ]; then
|
||||
ENV_FILE_EXISTS=true
|
||||
fi
|
||||
|
||||
# Check if DATABASE_URL is defined
|
||||
DATABASE_DEFINED=false
|
||||
if [ -n "$DATABASE_URL" ]; then
|
||||
DATABASE_DEFINED=true
|
||||
else
|
||||
if $ENV_FILE_EXISTS; then
|
||||
if grep -E '^DATABASE_URL=.+' .env &> /dev/null; then
|
||||
DATABASE_DEFINED=true
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# Check if Railway project is linked
|
||||
PROJECT_LINKED=false
|
||||
if $RAILWAY_AVAILABLE; then
|
||||
if railway status &> /dev/null; then
|
||||
PROJECT_LINKED=true
|
||||
fi
|
||||
fi
|
||||
|
||||
if $DATABASE_DEFINED; then
|
||||
$COMMAND
|
||||
else
|
||||
if $RAILWAY_AVAILABLE; then
|
||||
if $PROJECT_LINKED; then
|
||||
DATABASE_URL="$(railway variables -s Postgres --json | jq .DATABASE_PUBLIC_URL -cMr)" $COMMAND
|
||||
else
|
||||
echo "error: Railway project not linked."
|
||||
echo "Run 'railway link' to link the project."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
else
|
||||
echo "error: Could not find DATABASE_URL environment variable."
|
||||
echo "Install the Railway CLI and link the project, or create a .env file with a DATABASE_URL variable."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
@@ -1,3 +1,10 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Check whether CWD is 'frontend'
|
||||
if [ "$(basename "$(pwd)")" != "frontend" ]; then
|
||||
echo "error: This script must be run from the 'frontend' directory."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
export VITE_BACKEND_TARGET=${VITE_BACKEND_TARGET:-localhost:8000}
|
||||
pnpm run dev
|
||||
Reference in New Issue
Block a user