Skip to content
This repository has been archived by the owner on Feb 8, 2023. It is now read-only.

Commit

Permalink
Merge pull request #32 from redbadger/deploy
Browse files Browse the repository at this point in the history
Pull over deploy script changes from react.london
  • Loading branch information
asavin authored Jul 8, 2016
2 parents 6c5f9fa + b445ffd commit 18206c0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 25 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ node_modules
.elasticbeanstalk/*
!.elasticbeanstalk/*.cfg.yml
!.elasticbeanstalk/*.global.yml
Dockerrun.aws.json
*.zip


# Built assets
dist

Expand Down
File renamed without changes.
55 changes: 30 additions & 25 deletions bin/deploy.sh
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

# 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

# Apply docker image path to Dockerrun.aws.json template
cp Dockerrun.aws.json.template Dockerrun.aws.json
perl -pi -e "s,<ECR_REPO>,$ECR_REPO,g" "Dockerrun.aws.json"
perl -pi -e "s,<TAG>,$VERSION,g" "Dockerrun.aws.json"

Expand All @@ -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.

0 comments on commit 18206c0

Please sign in to comment.