Created
November 21, 2017 14:43
-
-
Save giehlman/c8ef2f4b188fdb4573424bd868c728d7 to your computer and use it in GitHub Desktop.
For gradle projects! Convenience script to build, pack and upload code to an AWS ElasticBeanstalk environment, using the AWS CLI 'eb' command. For personal and experimental use only!
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
#!/usr/bin/env bash | |
#title : eb-publish-gradle.sh | |
#description : For gradle projects! Convenience script to build, pack and upload code to an AWS ElasticBeanstalk environment, using the AWS CLI 'eb' command. For personal and experimental use only! | |
#prerequisites : AWS CLI with 'eb' cmd, Procfile, gradle project, .elasticbeanstalk/config.yml | |
#author : Christian-André Giehl <[email protected]> | |
#date : 20170410 | |
#version : 1.1 | |
#usage : sh eb-publish-gradle.sh | |
#============================================================================== | |
echo "### Creating Elastic Beanstalk deployment package..." | |
# Exits in case the supplied state is != 0. State is typically supplied via $? | |
exitOnError() { | |
state=$1 | |
msg=$2 | |
if [ $state -ne 0 ]; then | |
echo "!!! ${msg}" | |
echo "### Exiting." | |
exit $state | |
fi | |
} | |
# Check is AWS CLI and deploy.yaml there | |
command -v aws | |
exitOnError $? "AWS CLI not found or not accessible!" | |
[[ -e ".elasticbeanstalk/config.yml" ]] | |
exitOnError $? "ElasticBeanstalk config.yml not found in ./elasticbeanstalk/*!" | |
[[ -e ".Procfile" ]] | |
exitOnError $? "Procfile not found!" | |
echo "### Starting gradle..." | |
./gradlew clean test fatJarAPI | |
exitOnError $? "Unable to build!" | |
JAR=$(find ./ -iname API-*.jar -type f -print -quit) # Check *.jar name with your project! | |
echo "### Creating deployment zip..." | |
#ZIP=eb-deploy-${JAR##*/}.zip | |
ZIP=eb-deploy.zip | |
rm ${ZIP} | |
sed -i '' "s/web: java -jar.*/web: java -jar ${JAR##*/}/g" ./Procfile | |
cat ./Procfile | |
zip -j ${ZIP} Procfile ${JAR} | |
unzip -l ${ZIP} | |
echo "### Using file '${ZIP}' to deploy to elastic beanstalk..." | |
msg=$(echo $(git log -1 --pretty=%B)) | |
lbl=$(echo $(git log -1 --format='%H')) | |
echo "--- Deploying to EB ---" | |
echo "Message: " $msg | |
echo "Label: " $lbl | |
read -p "-----> DO YOU WANT TO DEPLOY? [Yy]es " -n 1 -r | |
if ! [[ $REPLY =~ ^[Yy]$ ]] | |
then | |
echo "!!! ABORTED !!!" | |
exit 1 | |
fi | |
eb deploy -m "$msg" -l "$lbl" | |
exitOnError $? "Unable to deploy to elastic beanstalk!" | |
echo "### Done!" | |
mv ${ZIP} ./build # Cleanup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment