Contents

Docker- Continuous Integration and Deployment

Some notes about the Continuous Integration and Deployment with AWS

.travis.yml


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
sudo: required
language: generic

services:
  - docker

before_install:
  - docker build -t <tag> -f Dockerfile.dev .

script:
  - docker run -e CI=true <tag> npm run test

deploy:
  provider: elasticbeanstalk
  region: "us-east-1"
  app: "<app name>"
  env: "docker-env"
  bucket_name: "elasticbeanstalk-us-east-1-xxxxxxxxxxx"
  bucket_path: "docker"
  on:
    branch: master
  access_key_id: $AWS_ACCESS_KEY
  secret_access_key: $AWS_SECRET_KEY

Dockerfile


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
FROM node:alpine
WORKDIR '/app'
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build

FROM nginx
EXPOSE 80
COPY --from=0 /app/build /usr/share/nginx/html


AWS

Initial Setup

  1. Go to AWS Management Console

  2. Search for Elastic Beanstalk in “Find Services”

  3. Click the “Create Application” button

  4. Enter “” for the Application Name

  5. Scroll down to “Platform” and select “Docker” from the dropdown list.

  6. Change “Platform Branch” to Docker running on 64bit Amazon Linux

  7. Click “Create Application”

  8. You should see a green checkmark after some time.

  9. Click the link above the checkmark for your application. This should open the application in your browser and display a Congratulations message.

Add AWS configuration details to .travis.yml file’s deploy script

  1. Set the region. The region code can be found by clicking the region in the toolbar next to your username.

eg: ‘us-east-1’

  1. app should be set to the Application Name (Step #4 in the Initial Setup above)

  2. env should be set to the lower case of your Beanstalk Environment name.

eg: ‘-env’

  1. Set the bucket_name. This can be found by searching for the S3 Storage service. Click the link for the elasticbeanstalk bucket that matches your region code and copy the name.

eg: ‘elasticbeanstalk-us-east-1-xxxxxxxxxx’

  1. Set the bucket_path to ‘’(the “folder” by with this name will be created in the previous bucket_name once deployed)

  2. Set access_key_id to $AWS_ACCESS_KEY

  3. Set secret_access_key to $AWS_SECRET_KEY

Create an IAM User

  1. Search for the “IAM Security, Identity & Compliance Service”

  2. Click “Create Individual IAM Users” and click “Manage Users”

  3. Click “Add User”

  4. Enter any name you’d like in the “User Name” field.

eg: docker-react-travis-ci

  1. Tick the “Programmatic Access” checkbox

  2. Click “Next:Permissions”

  3. Click “Attach Existing Policies Directly”

  4. Search for “beanstalk”

  5. Tick the box next to “AWSElasticBeanstalkFullAccess”

  6. Click “Next:Tags”

  7. Click “Next:Review”

  8. Click “Create user”

  9. Copy and / or download the Access Key ID and Secret Access Key to use in the Travis Variable Setup.

Travis Variable Setup

  1. Go to your Travis Dashboard and find the project repository for the application we are working on.

  2. On the repository page, click “More Options” and then “Settings”

  3. Create an AWS_ACCESS_KEY variable and paste your IAM access key from step #13 above.

  4. Create an AWS_SECRET_KEY variable and paste your IAM secret key from step #13 above.

Deploying App

  1. Make a change to the feature branch.

  2. Merge into master branch.

  3. Go to your Travis Dashboard and check the status of your build.

  4. The status should eventually return with a green checkmark and show “build passing”

  5. Go to your AWS Elasticbeanstalk application

  6. It should say “Elastic Beanstalk is updating your environment”

  7. It should eventually show a green checkmark under “Health”. You will now be able to access your application at the external URL provided under the environment name.