Created
March 2, 2021 16:53
-
-
Save hallindavid/5225d76646f2f7b6fde9da30af140198 to your computer and use it in GitHub Desktop.
A post deployment script for Laravel apps (could work for others) that tries to generate as much information as possible, so the script is re-usable project to project, and user to user.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This function retreives varaibles from your .env file (must be in same directory as this script) | |
read_var() { | |
VAR=$(grep $1 .env | xargs) | |
IFS="=" read -ra VAR <<<"$VAR" | |
echo ${VAR[1]} | |
} | |
######### SET YOUR VARIABLES ######### | |
##-------------------## | |
#### ENVIRONMENT ##### | |
# This determines how we pull in the environment that gets passed to the honeybadger deployment api | |
# options are "overridden", "parameter", "file" | |
ENVIRONMENTSETTER="parameter" | |
### Default environment / Override value #### | |
# Default, or overridden value if using the overridden environment setter | |
DEPLOYENVIRONMENT="dev" | |
#### Parameter option ##### | |
# the parameter option allows you to pass in the environment via command line | |
# eg. ./post_deploy_script.sh production - sets environment to production | |
if [ "$ENVIRONMENTSETTER" = "parameter" ]; then | |
if [ "$#" -ne 1 ]; then | |
echo "Please pass in a paramter (eg. './post_deploy_script.sh production' )" | |
exit | |
else | |
DEPLOYENVIRONMENT="$1" | |
fi | |
fi | |
#### File Option #### | |
# The file option looks in your .env file and retrieves the APP_ENV variable | |
# Note - the .env file must be in the same directory as this script | |
if [ "$ENVIRONMENTSETTER" = "file" ]; then | |
DEPLOYENVIRONMENT=$(read_var APP_ENV) | |
fi | |
#### ENVIRONMENT ##### | |
##-------------------## | |
### CURRENT COMMIT #### | |
# Option 1 - Override it here | |
#CURRENTCOMMIT="asdfasdf" | |
# Option 2 - use the GIT CLI to get the short hash | |
CURRENTCOMMIT=$(git rev-parse --short HEAD) | |
### CURRENT COMMIT #### | |
##-------------------## | |
##### LOCAL USER ###### | |
# Option 1 - Use the Git CLI to get current user | |
USER=$(git config user.name) | |
# Option 2 - Override it here | |
#USER="" | |
# Option 3 - Use the whoami function | |
#USER=$(whoami) | |
##### LOCAL USER ###### | |
##-------------------## | |
# HONEY BADGER API KEY# | |
# Option 1 - retrieve it from your .env file | |
# note - .env file must be in same directory as this folder | |
APIKEY=$(read_var HONEYBADGER_API_KEY) | |
# Option 2 - Override it here | |
#APIKEY="" | |
# HONEY BADGER API KEY# | |
##-------------------## | |
### GITHUB REPO URL ### | |
# Option 1 - Use the git cli to get the current remote origin url | |
REPO=$(git config --get remote.origin.url) | |
# Option 2 - Override it | |
#REPO="" | |
### GITHUB REPO URL ### | |
##-------------------## | |
######### EXECUTE OR PREVIEW ######### | |
# Uncomment the line below to execute the deployment hook | |
curl --data "deploy[environment]=$DEPLOYENVIRONMENT&deploy[local_username]=$USER&deploy[revision]=$CURRENTCOMMIT&deploy[repository]=$REPO&api_key=$APIKEY" "https://api.honeybadger.io/v1/deploys" | |
# Preview Request Code - This will show you the --data element for the deployment request (so you can visually check it) | |
echo "REQUEST: deploy[environment]=$DEPLOYENVIRONMENT&deploy[local_username]=$USER&deploy[revision]=$CURRENTCOMMIT&deploy[repository]=$REPO&api_key=$APIKEY" "https://api.honeybadger.io/v1/deploys" | |
echo "environment: $DEPLOYENVIRONMENT" | |
echo "local_username: $USER" | |
echo "revision: $CURRENTCOMMIT" | |
echo "repository: $REPO" | |
echo "api_key: $APIKEY" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Setup
Open terminal, browse to your project and then run
Once these are done, you need to decide how you want to set the different variables - read through the commented code and uncomment/comment as necessary to make it work the way you want.
Then execute by running the script