|# usage: ./deploy.sh staging f0478bd7c2f584b41a49405c91a439ce9d944657|
|# license: public domain|
|aws configure set default.region us-east-1|
|# Authenticate against our Docker registry|
|eval $(aws ecr get-login)|
|# Build and push the image|
|docker build -t $NAME:$VERSION .|
|docker tag $NAME:$VERSION $AWS_ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com/$NAME:$VERSION|
|docker push $AWS_ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com/$NAME:$VERSION|
|# Replace the <AWS_ACCOUNT_ID> with the real ID|
|sed -i='' "s/<AWS_ACCOUNT_ID>/$AWS_ACCOUNT_ID/" Dockerrun.aws.json|
|# Replace the <NAME> with the real name|
|sed -i='' "s/<NAME>/$NAME/" Dockerrun.aws.json|
|# Replace the <TAG> with the real version number|
|sed -i='' "s/<TAG>/$VERSION/" Dockerrun.aws.json|
|# Zip up the Dockerrun file (feel free to zip up an .ebextensions directory with it)|
|zip -r $ZIP Dockerrun.aws.json|
|aws s3 cp $ZIP s3://$EB_BUCKET/$ZIP|
|# Create a new application version with the zipped up Dockerrun file|
|aws elasticbeanstalk create-application-version --application-name $NAME-application \|
|--version-label $VERSION --source-bundle S3Bucket=$EB_BUCKET,S3Key=$ZIP|
|# Update the environment to use the new application version|
|aws elasticbeanstalk update-environment --environment-name $NAME \|
Looks like our Staffjoy deploy code. I suggest polling to see if the deploy succeeded. I copied and sanitized some code to do this from our deploys below that should match your variables (I haven't tested the modifications though). It looks for the deployed tag to match the anticipated one, it looks for EB to return to a "Ready" state (where another deploy can be initiated), and it times out if these conditions are not met (returning exit code 1).
deploystart=$(date +%s) timeout=3000 # Seconds to wait before error. If it's taking awhile - your boxes probably are too small. threshhold=$((deploystart + timeout)) while true; do # Check for timeout timenow=$(date +%s) if [[ "$timenow" > "$threshhold" ]]; then echo "Timeout - $timeout seconds elapsed" exit 1 fi # See what's deployed current_version=`aws elasticbeanstalk describe-environments --application-name "$NAME-application" --environment-name "$NAME" --query "Environments[*].VersionLabel" --output text` status=`aws elasticbeanstalk describe-environments --application-name "$NAME-application" --environment-name "$NAME" --query "Environments[*].Status" --output text` if [ "$current_version" != "$VERSION" ]; then echo "Tag not updated (currently $version). Waiting." sleep 10 continue fi if [ "$status" != "Ready" ]; then echo "System not Ready -it's $status. Waiting." sleep 10 continue fi break done
I'm new to Docker and came across this gist today while researching deployment strategies with Docker and Elastic Beanstalk. How does your application get built into the image? Are you pulling it from the repo as you build it? This is one thing I'm not super clear on.
@theseanstewart great question! I build the docker image with
The way the Elastic Beanstalk application environment knows how to deploy itself is the
instead of this
you can use
Note: deploy.sh script won't work for the first time. aws elasticbeanstalk update-environment command will work only for existing environment
should contain trailing slash at the end
If you are using
and add the
I'm doing different.
So in config.yml is necessary put the keys bellow:
The archive will be like this:
then is just execute the command 'eb deploy' in main directory os your app.
@javahometech when using elastic beanstalk ,and ecr, you set up an iam role. So then when the following was run:
aws ecr get-login prints out a docker login command with a temporary credential. That output then gets executed with the eval statement and that's how auth is handled.