Skip to content

Instantly share code, notes, and snippets.

@richardsonlima
Forked from wgrisa/beanstalk deploy script
Created January 26, 2019 02:54
Show Gist options
  • Save richardsonlima/5078e423fa9333aeb33f97d3d9620bdf to your computer and use it in GitHub Desktop.
Save richardsonlima/5078e423fa9333aeb33f97d3d9620bdf to your computer and use it in GitHub Desktop.
beanstalk deploy prepared (but not only) for gitlab ci
#!/bin/bash
# EB_APP_NAME = application name
# EB_APP_ENV = application environment
# S3_BUCKET = S3 bucket for ElasticBeanstalk
# S3_KEY = S3 folder to upload built app
# Zip up everything with the exception of node_modules (including dist), .git and zip files
ts=`date +%s`
fn="$EB_APP_NAME-$ts.zip"
echo "Creating zip file [ $fn ] ..."
# In order to add more files or folders to ignore add a -o parameter after any prune and the path you want to exclude calling prune again
# e.g. removing all CSV files: find ./ -path '*/node_modules/*' -prune -o -path '*/\.git*' -prune -o -path '*.zip' -prune -o -path '*.csv' -prune -o -type f -print
find ./ -path '*/node_modules/*' -prune -o -path '*/\.git*' -prune -o -path '*.zip' -prune -o -type f -print | zip $fn -@
# Copy the app to S3
S3_KEY="$S3_KEY/$fn"
echo "Copying app from [ $fn ] to [ s3://$S3_BUCKET/$S3_KEY ] ..."
echo "aws s3 cp $fn s3://$S3_BUCKET/$S3_KEY"
aws s3 cp $fn "s3://$S3_BUCKET/$S3_KEY"
# Create a new version in eb
echo "Creating ElasticBeanstalk Application Version ..."
echo "aws elasticbeanstalk create-application-version \
--application-name $EB_APP_NAME \
--version-label $EB_APP_NAME-$ts \
--description $EB_APP_NAME-$ts \
--source-bundle S3Bucket=$S3_BUCKET,S3Key=$S3_KEY --auto-create-application"
aws elasticbeanstalk create-application-version \
--application-name $EB_APP_NAME \
--version-label "$EB_APP_NAME-$ts" \
--description "$EB_APP_NAME-$ts" \
--source-bundle S3Bucket="$S3_BUCKET",S3Key="$S3_KEY" --auto-create-application
# Update to that version
echo "Updating ElasticBeanstalk Application Version ..."
echo "aws elasticbeanstalk update-environment \
--application-name $EB_APP_NAME \
--environment-name $EB_APP_ENV \
--version-label $EB_APP_NAME-$ts"
aws elasticbeanstalk update-environment \
--application-name $EB_APP_NAME \
--environment-name $EB_APP_ENV \
--version-label "$EB_APP_NAME-$ts"
echo "Deploy process concluded. Check logs above to see if any error occurred. Version [ $EB_APP_NAME-$ts ]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment