Skip to content

Instantly share code, notes, and snippets.

@alexklibisz
Created December 27, 2015 09:02
Show Gist options
  • Save alexklibisz/940c537b5722a9cbe648 to your computer and use it in GitHub Desktop.
Save alexklibisz/940c537b5722a9cbe648 to your computer and use it in GitHub Desktop.
Elastic Beanstalk Deployment using the dpl ruby gem ( '-' represents a '/' in the file path)
FROM ruby:2.2.4
RUN apt-get update -y
RUN apt-get install ruby-full -y
RUN apt-get install git -y
RUN gem install dpl
RUN gem install aws-sdk
RUN gem install aws-sdk-v1
RUN mkdir /usr/src/app
WORKDIR /usr/src/app
ENTRYPOINT ["dpl"]
#!/bin/bash
set -e
# This script requires:
# - environment variables: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY
# - arguments: [0] app name [1] environment name / branch
# some setup
usage="usage: dpl-ebs.sh app_name env_name\n
ex: dpl-ebs.sh sl-data-proxy deploy-stage"
# get CLI params
if [ "$#" -ne 2 ]; then echo "$usage"; exit; fi
if [ "$2" != "deploy-stage" ] && [ "$2" != "deploy-prod" ]
then
echo "$usage"
exit
fi
app_name="$1"
env_name="$2"
region_name="us-east-1"
# build the dpl docker image
echo 'dpl-ebs: building dpl container'
docker build -t dpl ./tools/dpl
# zip up the deploy contents
echo 'dpl-ebs: zipping up bundle'
now=$(date +"%Y-%m-%d_%H-%M")
mkdir -p ebs-bundles.tmp
zip_name="ebs-bundles.tmp/ebs-bundle-$now.zip"
zip -r "$zip_name" ./* -x "./node_modules*" "dist*" "*.tmp*" ".git*"
# copy over needed env vars
echo 'dpl-ebs: preparing env variables'
touch env.tmp
echo "AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID" >> env.tmp
echo "AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY" >> env.tmp
# run the docker image with args
echo 'dpl-ebs: running dpl container'
docker run --env-file env.tmp \
--volume $(pwd):/usr/src/app \
dpl \
--provider=elasticbeanstalk \
--skip_cleanup \
--access-key-id=$AWS_ACCESS_KEY_ID \
--secret-access-key=$AWS_SECRET_ACCESS_KEY \
--app="$app_name" \
--env="$env_name" \
--region="$region_name" \
--zip_file="$zip_name" \
--bucket_name="elasticbeanstalk-us-east-1-790934774760" \
--bucket_path="$app_name"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment