Skip to content

Commit

Permalink
more scripts env dependent
Browse files Browse the repository at this point in the history
  • Loading branch information
goodeats committed May 22, 2024
1 parent 4f0a301 commit 0f35cc5
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 0 deletions.
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,14 @@
"typecheck": "tsc",
"typecheck:watch": "tsc -w",
"validate": "run-p \"test -- --run\" lint typecheck test:e2e:run",
"fly:status:prod": "npm run fly:status -- --env=production",
"fly:status:staging": "npm run fly:status -- --env=staging",
"fly:status": "./scripts/fly.io/app-status.sh",
"fly:console:prisma:studio:prod": "npm run fly:console:prisma:studio -- --env=production",
"fly:console:prisma:studio:staging": "npm run fly:console:prisma:studio -- --env=staging",
"fly:console:prisma:studio": "./scripts/fly.io/app-console-prisma-studio.sh",
"fly:console:prisma:studio:proxy:prod": "npm run fly:console:prisma:studio:proxy -- --env=production",
"fly:console:prisma:studio:proxy:staging": "npm run fly:console:prisma:studio:proxy -- --env=staging",
"fly:console:prisma:studio:proxy": "./scripts/fly.io/app-console-prisma-studio-proxy.sh",
"prepare": "husky install"
},
Expand Down
44 changes: 44 additions & 0 deletions scripts/fly.io/app-console-prisma-studio-proxy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,50 @@
# run proxy to prisma studio on fly app to local port (separate terminal)
# npm run fly:app:console:prisma:studio:proxy

# Check if the script is running in production environment
if [ "$NODE_ENV" = "production" ]; then
echo "This script should not run in production."
exit 1
fi

# Default environment
ENV="development"

# Parse arguments
for ARG in "$@"
do
case $ARG in
--env=*)
ENV="${ARG#*=}"
shift
;;
esac
done

# Source environment variables
source .env

# Check if the environment variable is set
if [ -z "$FLY_APP_NAME" ]; then
echo "Error: FLY_APP_NAME environment variable is not set."
exit 1
fi

# Modify the app name for staging environment
if [ "$ENV" = "staging" ]; then
FLY_APP_NAME="${FLY_APP_NAME}-staging"
elif [ "$ENV" != "production" ]; then
echo "Unknown environment: $ENV"
exit 1
fi

# Run the Fly.io proxy command
fly proxy 5556:5555 --app $FLY_APP_NAME

# FYI closing the proxy will display a warning:
# "Error: ssh shell: session forcibly closed; the remote process may still be running"
# don't worry :D
# https://community.fly.io/t/does-fly-know-when-my-app-decides-to-gracefully-shutdown/19132
# the comments from this post seem to suggest the healthcheck fail will close the connection
# https://fly.io/docs/reference/configuration/#services-tcp_checks
# here is the doc to confirm :D
36 changes: 36 additions & 0 deletions scripts/fly.io/app-console-prisma-studio.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,42 @@
# run proxy to prisma studio on fly app to local port (separate terminal)
# npm run fly:app:console:prisma:studio:proxy

# Check if the script is running in production environment
if [ "$NODE_ENV" = "production" ]; then
echo "This script should not run in production."
exit 1
fi

# Default environment
ENV="development"

# Parse arguments
for ARG in "$@"
do
case $ARG in
--env=*)
ENV="${ARG#*=}"
shift
;;
esac
done

# Source environment variables
source .env

# Check if the environment variable is set
if [ -z "$FLY_APP_NAME" ]; then
echo "Error: FLY_APP_NAME environment variable is not set."
exit 1
fi

# Modify the app name for staging environment
if [ "$ENV" = "staging" ]; then
FLY_APP_NAME="${FLY_APP_NAME}-staging"
elif [ "$ENV" != "production" ]; then
echo "Unknown environment: $ENV"
exit 1
fi

# Run the Fly.io ssh console command
fly ssh console -C "npm run prisma:studio" --app $FLY_APP_NAME
36 changes: 36 additions & 0 deletions scripts/fly.io/app-status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,42 @@
# to give permission to execute the file locally run:
# chmod +x scripts/fly.io/app-status.sh

# Check if the script is running in production environment
if [ "$NODE_ENV" = "production" ]; then
echo "This script should not run in production."
exit 1
fi

# Default environment
ENV="development"

# Parse arguments
for ARG in "$@"
do
case $ARG in
--env=*)
ENV="${ARG#*=}"
shift
;;
esac
done

# Source environment variables
source .env

# Check if the environment variable is set
if [ -z "$FLY_APP_NAME" ]; then
echo "Error: FLY_APP_NAME environment variable is not set."
exit 1
fi

# Modify the app name for staging environment
if [ "$ENV" = "staging" ]; then
FLY_APP_NAME="${FLY_APP_NAME}-staging"
elif [ "$ENV" != "production" ]; then
echo "Unknown environment: $ENV"
exit 1
fi

# Run the Fly.io status command
fly status --app $FLY_APP_NAME

0 comments on commit 0f35cc5

Please sign in to comment.