Automatic Deployment and Continuous Integration with CircleCI and ElasticBeanstalk

The Workflow

Let me describe the workflow we were trying to accomplish.

We wanted to run tests on every merge into 'master'. If the tests pass, we wanted the code to be automatically pushed to a staging server.

Once we verify staging is working properly, we want to merge that code into the 'production' branch. Tests will be run again and if all is well, the code will automatically be pushed to a production server.

The Tech Stack

We saw plenty of options and decided to go with AWS because of how many services they offer, the amount and quality of their documentation, and they have a AWS Pop-up Loft right across the street from us.

We chose CircleCI in part because of this page describing automatic deployment with CircleCI, Docker, and AWS. We initially wanted to use Docker, partly because we saw the benefit in having the same environment throughout our workflow, but mostly because it seems like a really cool technology to work with. But once we started working with AWS, things were just going smoothly without Docker and we decided to put Docker on the back-burner until we saw a stronger use case.

Workflow + Tech Stack

So, to sum up our workflow using the tech stack we decided on:

Any push to the branch 'master' will trigger tests to run in CircleCI. If those tests pass, CircleCI will use the AWS Elastic Beanstalk CLI to deploy to our staging server.

Once we manually verify everything is working properly on staging (this process is to be automated in the future with navigation scripting/testing utility like CasperJS), we merge the code into the branch 'deployment'. When CircleCI sees a merge to deployment, the tests are run once more and if everything passes, CircleCI pushes the changes to our production server.

Our app also requires a node script to be run for each active user. This node script needs to be run on it's own unique public IP address.

To accomplish this task, we used the AWS-SDK for Javascript in Node.js to spin up and spin down Elastic Beanstalk environments whenever we need.

Below is the circle.yml file we are using to automate our tests and deployment.

    version: 3.4.2
    DISPLAY: 8000
    MYSQL_DATABASE: 'circle_test'
    - pip install awsebcli
    - eb init thesis -p Node.js -r us-west-2
    - grunt test
    branch: master
      - eb deploy thesis-staging --timeout 10
    branch: production
      - eb deploy thesis-production --timeout 10

And here is our .ebextensions/config.config which the awsebcli command-line tool uses to configure our Elastic Beanstalk environment.

    git: []
    openssl-devel: []
    expat-devel: []
    gettext-devel: []
    zlib-devel: []
    command: "yum install -y nodejs npm --enablerepo=epel"
    command: "npm install -g bower"
    command: "npm install"
      HOME: "/usr/bin"
      PATH: "/usr/bin"
    command: "bower install --allow-root"
Show Comments