-
Notifications
You must be signed in to change notification settings - Fork 0
Pull over deploy script changes from react.london #32
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,34 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
#!/usr/bin/env bash | ||
|
||
ENV=$1 | ||
RELEASE_TAG=$2 | ||
RELEASE_TAG=$(git rev-parse HEAD) | ||
APP_NAME=badger-brain | ||
AWS_ACCOUNT=578418881509 | ||
AWS_REGION=eu-west-1 | ||
ECR_REPO=$AWS_ACCOUNT.dkr.ecr.$AWS_REGION.amazonaws.com/$APP_NAME | ||
EB_BUCKET=elasticbeanstalk-$AWS_REGION-$AWS_ACCOUNT | ||
|
||
if [ -z "$ENV" ] || [ -z "$RELEASE_TAG" ] | ||
then | ||
echo Usage: | ||
echo " deploy.sh ENVIRONMENT" | ||
exit 1 | ||
fi | ||
|
||
set -eu | ||
set -o pipefail | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Safer bash options. Set after the variable checking as otherwise we get an ugly error message when the user forgets to pass the argument rather than the friendlier one above. |
||
|
||
# Authenticate | ||
eval $(aws ecr get-login --region=$AWS_REGION) | ||
|
||
# Build Docker image | ||
if [ "$ENV" == "live" ] | ||
then | ||
VERSION=$RELEASE_TAG | ||
docker build -t $APP_NAME:$RELEASE_TAG . | ||
docker tag $APP_NAME:$RELEASE_TAG $ECR_REPO:$RELEASE_TAG | ||
docker push $ECR_REPO:$RELEASE_TAG | ||
else | ||
VERSION=$ENV | ||
docker build -t $APP_NAME:$ENV . | ||
docker tag $APP_NAME:$ENV $ECR_REPO:$ENV | ||
docker push $ECR_REPO:$ENV | ||
fi | ||
VERSION=$RELEASE_TAG | ||
docker build -t $APP_NAME:$RELEASE_TAG . | ||
docker tag $APP_NAME:$RELEASE_TAG $ECR_REPO:$RELEASE_TAG | ||
docker push $ECR_REPO:$RELEASE_TAG | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed the different path for production and staging for a few reasons.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TBH I feel like the production deploy should always be moving an existing image from staging (or storage) to production rather than compiling a fresh version. Could build on CI. |
||
|
||
# Apply docker image path to Dockerrun.aws.json template | ||
cp Dockerrun.aws.json.template Dockerrun.aws.json | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moving the compiled Dockerrun.aws.json out of the repo so the deployer doesn't need to undo the changes to the file after each deploy. Removes risk of accidentally committing the compiled version. |
||
perl -pi -e "s,<ECR_REPO>,$ECR_REPO,g" "Dockerrun.aws.json" | ||
perl -pi -e "s,<TAG>,$VERSION,g" "Dockerrun.aws.json" | ||
|
||
|
@@ -36,14 +37,18 @@ ZIP_FILE=$VERSION.zip | |
zip -r $ZIP_FILE Dockerrun.aws.json | ||
aws s3 cp $ZIP_FILE s3://$EB_BUCKET/$APP_NAME/$ZIP_FILE | ||
|
||
# In production, create a new app version | ||
if [ "$ENV" == "live" ] | ||
then | ||
# Create a new application version with the zipped up Dockerrun file | ||
aws elasticbeanstalk create-application-version --application-name $APP_NAME \ | ||
--version-label $VERSION --source-bundle S3Bucket=$EB_BUCKET,S3Key=$APP_NAME/$ZIP_FILE --region $AWS_REGION | ||
fi | ||
# Create a new application version with the zipped up Dockerrun file | ||
aws elasticbeanstalk create-application-version \ | ||
--application-name $APP_NAME \ | ||
--version-label $VERSION \ | ||
--source-bundle S3Bucket=$EB_BUCKET,S3Key=$APP_NAME/$ZIP_FILE \ | ||
--region $AWS_REGION | ||
|
||
# Update the environment to use the new application version | ||
aws elasticbeanstalk update-environment --environment-name $APP_NAME-$ENV \ | ||
--version-label $VERSION --region $AWS_REGION | ||
aws elasticbeanstalk update-environment \ | ||
--environment-name $APP_NAME-$ENV \ | ||
--version-label $VERSION \ | ||
--region $AWS_REGION | ||
|
||
echo | ||
echo Done! AWS EB deployment rollout in progress. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just formatting for readability and a friendly success message since the previous version just dumped a load of json to the terminal which is not obviously a success. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removes the need for manual setting of a version. The AWS EB version GUI has dates and what env a version is deployed to so I've found that and a SHA to identify commits is sufficient.
This is a matter of taste though!