Skip to content

Instantly share code, notes, and snippets.

@azendal
Created January 23, 2023 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azendal/4327b3e1e21774edb74cad1f84bdc9bd to your computer and use it in GitHub Desktop.
Save azendal/4327b3e1e21774edb74cad1f84bdc9bd to your computer and use it in GitHub Desktop.
bootstrap deploy to a heroku container
#!/bin/bash
# Check if Heroku CLI is installed
if ! command -v heroku &> /dev/null; then
echo "Heroku CLI is not installed, please install it before running this script"
exit 1
fi
# Check if user is logged in
if ! heroku auth:whoami &> /dev/null; then
echo "You are not logged in to Heroku, please log in before running this script"
exit 1
fi
# Prompt for input
read -p "Enter Heroku app name: " app_name
# Check if the app already exists
if heroku apps:info --app $app_name &> /dev/null; then
echo "App $app_name already exists, skipping app creation"
else
# Create the Heroku app
heroku create $app_name
fi
# Check if the database add-on already exists
if heroku addons --app $app_name | grep "heroku-postgresql" &> /dev/null; then
echo "Database add-on already exists, skipping add-on creation"
else
# Create the database
heroku addons:create heroku-postgresql:hobby-dev --app $app_name
fi
# Set environment variables
while IFS= read -r line; do
heroku config:set --app $app_name "$line"
done < variables.txt
# Login to container registry
heroku container:login
# Build and release the container
heroku container:push web --app $app_name
heroku container:release web --app $app_name
# Run migrations
heroku run rake db:migrate --app $app_name
# Open the app in a browser
heroku open --app $app_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment