Home/Server & Website Managed Operations/Implementing CI/CD with Docker, GitHub Flow, CircleCI, AWS Elastic Beanstalk, and Slack
Server & Website Managed Operations

Implementing CI/CD with Docker, GitHub Flow, CircleCI, AWS Elastic Beanstalk, and Slack

DevOps: Continuous Integration & Continuous Delivery (Docker, CircleCI, AWS)

687474703a2f2f332e62702e626c6f6773706f742e636f6d2f2d4b67777732504e5234526f2f5654704f4974746d6452492f41414141414141416b62772f78586c35317a477a6c36512f73313630302f636f7665722e706e6

This article will guide you step-by-step through implementing a Continuous Integration and Continuous Delivery workflow using Docker, GitHub Flow, CircleCI, AWS Elastic Beanstalk, and Slack.

Introduction

What are Continuous Integration & Continuous Delivery?

Continuous Integration & Continuous Delivery (CI & CD). For detailed definitions, please refer to the article “Sam’s Definition of Continuous Integration, Continuous Deployment, and Continuous Delivery“.

In simple terms, it aims to minimize manual effort by automating routine tasks such as environment setup, unit testing, logging, and product deployment.

Tools Used

  • Git – Version Control
  • GitHub – Code Hosting & Review
  • CircleCI – Automated Build, Test, & Deployment
  • Docker – Portable, Lightweight Execution Environment
  • AWS Elastic Beanstalk – Cloud Platform
  • Slack – Team Communication, Logging, & Notifications

What You Will Learn from This Article

  • Understand the GitHub workflow (GitHub Flow), utilizing Pull Requests and branches to facilitate code reviews (Code Review) and environment configuration, such as: development, testing/QA, staging, and production.
  • Use Docker to standardize the execution environment for developers, testers, and production.
  • Use EB CLI to deploy applications to the AWS Elastic Beanstalk platform.
  • Automate all of the above tasks using CircleCI. Detect code updates on GitHub branches; if changes are found, trigger: building the Docker environment, running unit tests, and automatically deploying the new version to AWS EB.
  • Use Slack so that team members can receive real-time notifications for every action taken by GitHub and CircleCI.

687474703a2f2f312e62702e626c6f6773706f742e636f6d2f2d61794d50555969704159492f565470505754456c6a58492f41414141414141416b62382f767077352d77722d426a512f73313630302f73657175656e63652d6469616772616d2e706e6

Table of Contents

Node.js

687474703a2f2f342e62702e626c6f6773706f742e636f6d2f2d47567335784c4a783937632f56547051765544786244492f41414141414141416b63592f4d706c307775326e41366b2f73313630302f6e6f64652e706e6

Installation:

This article uses a Node.js application as an example, but this workflow applies equally to other languages such as Ruby on Rails, Python, and PHP.

Create a New Project

  1. Create a project folder (using hello-ci-workflow as an example here):
$ mkdir hello-ci-workflow
$ cd hello-ci-workflow

Run Node.js Locally

  1. Initialize the Node.js environment by providing some information; this will generate a package.json file in the directory:
$ npm init
  1. Install a Node.js web framework; for example, using Express:
$ npm install express --save

--save: Writes the dependency to package.json.

  1. After completion, your package.json should look something like this:
// package.json
{
  "name": "hello-ci-workflow",
  "main": "index.js",
  "dependencies": {
    "express": "^4.12.3"
  },
  "scripts": {
    "start": "node index.js"
  }
}
  1. Write a simple Hello World! program in index.js:
// index.js
var express = require('express');
var app = express();

app.get('/', function (req, res) {
  res.send('Hello World!');
});

var server = app.listen(3000, function () {

  var host = server.address().address;
  var port = server.address().port;

  console.log('Example app listening at http://%s:%s', host, port);

});
  1. Run npm start or node index.js:
$ npm start
  1. Open your browser to http://localhost:3000 to see the result:

687474703a2f2f312e62702e626c6f6773706f742e636f6d2f2d316f705f565f50574749492f56547055664f50796f67492f41414141414141416b65772f69576453534d2d453648592f73313630302f30312e706e6

Testing Node.js Locally

  1. Install unit testing for Node.js, using Mocha as an example:
$ npm install mocha --save-dev

--save-dev: Writes to the devDependencies in package.json; these will not be installed in the production environment.

// package.json
{
  "name": "hello-ci-workflow",
  "main": "index.js",
  "dependencies": {
    "express": "^4.12.3"
  },
  "devDependencies": {
    "mocha": "^2.2.4"
  },
  "scripts": {
    "start": "node index.js"
  }
}
  1. Create a test folder in the root directory and add a test script named test.js:
$ mkdir test
$ cd test
$ touch test.js
  1. Add an intentionally failing test case: assert.equal(1, [1,2,3].indexOf(0)):
// test/test.js
var assert = require("assert")
describe('Array', function(){
  describe('#indexOf()', function(){
    it('should return -1 when the value is not present', function(){
      assert.equal(1, [1,2,3].indexOf(0));
    })
  })
})
  1. Run the mocha tests:
$ ./node_modules/.bin/mocha


  Array
    #indexOf()
      1) should return -1 when the value is not present


  0 passing (9ms)
  1 failing

The output shows 1 failing, indicating that the test did not pass because the return value of [1,2,3].indexOf(0) does not equal -1.

  1. Fix the test in test.js:
// test/test.js
assert.equal(-1, [1,2,3].indexOf(0));
  1. Run the mocha tests again:
$ ./node_modules/.bin/mocha


  Array
    #indexOf()
      ✓ should return -1 when the value is not present


  1 passing (6ms)

The output shows 1 passing, indicating that the test passed.

GitHub

687474703a2f2f332e62702e626c6f6773706f742e636f6d2f2d736142616235336e3135772f56547051765149376636492f41414141414141416b63552f46703865346161467938452f73313630302f6769746875622e706e6

Installation:

Account:

  1. Initialize the git environment:
$ git init .
  1. Running git status will display which files have been modified:
$ git status
On branch master

Initial commit

Untracked files:
  (use "git add <file>..." to include in what will be committed)

  index.js
  node_modules/
  package.json
  test/
  1. Add node_modules to the .gitignore blacklist, as this folder is automatically generated by npm install and does not need to be pushed to GitHub:
# .gitignore

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules
  1. Commit the changes:
$ git add .
$ git commit -m "first commit"
  1. Go to GitHub and create a new repository:

687474703a2f2f322e62702e626c6f6773706f742e636f6d2f2d2d4a2d36343130534e74342f5654705566423150452d492f41414141414141416b65732f4e5a4476386d436e6661342f73313630302f30322e706e6

  1. Enter the repository name; for example, use hello-ci-workflow:

687474703a2f2f332e62702e626c6f6773706f742e636f6d2f2d4a7973694f3946663435492f56547055664166674532492f41414141414141416b65302f42465947614d5a394d55302f73313630302f30332e706e6

  1. Add the newly created GitHub repository to your remotes using git remote add:
$ git remote add origin https://github.com/<USER_NAME>/hello-ci-workflow.git

Replace <USER_NAME> with your own username.

  1. Push the code to GitHub using git push:
$ git push -u origin master

After the upload is successful, navigate to https://github.com/<USER_NAME>/hello-ci-workflow to view the files you just uploaded:

687474703a2f2f332e62702e626c6f6773706f742e636f6d2f2d4c6642586942516b654e632f56547055666c6e683367492f41414141414141416b65342f634b316c703537725a79632f73313630302f30342e706e6

CircleCI

687474703a2f2f322e62702e626c6f6773706f742e636f6d2f2d555466506b66356b5171302f56547051753441425969492f41414141414141416b634d2f4d6a6577393739315a7a672f73313630302f636972636c6563692e706e6

Account:

Add GitHub repository

  1. Click the Add Projects button in the left sidebar:

687474703a2f2f312e62702e626c6f6773706f742e636f6d2f2d37725766746e676c5f53632f56547055663743494b4c492f41414141414141416b66492f67326264753834777a65632f73313630302f30352e706e6

  1. Select your GitHub account:

687474703a2f2f332e62702e626c6f6773706f742e636f6d2f2d34376b685743594648766b2f56547055663636374249492f41414141414141416b66412f3230614c6d7a484d6f67512f73313630302f30362e706e6

  1. Search for the GitHub repository to add, then click the Build project button. For example, using hello-ci-workflow:

687474703a2f2f332e62702e626c6f6773706f742e636f6d2f2d73444630306c78386361492f565470556e684e6c4739492f41414141414141416b686b2f50425669354952556676452f73313630302f30372e706e6

  1. Once completed, CircleCI will automatically execute the first build. However, since no test scripts have been added yet, the build result will show “no test”:

687474703a2f2f322e62702e626c6f6773706f742e636f6d2f2d34364c78483678636f744d2f56547055677335734a56492f41414141414141416b664d2f396b3056394869476b35412f73313630302f30382e706e6

Testing Node.js on CircleCI

  1. Create a circle.yml file in the project root directory and add the mocha test:
# circle.yml
machine:
  node:
    version: 0.10

test:
  override:
    - ./node_modules/.bin/mocha
  1. After completing the changes, push the files to GitHub:
$ git add circle.yml
$ git commit "add circle.yml"
$ git push
  1. Once the push is successful, CircleCI will automatically trigger the build and tests:

687474703a2f2f322e62702e626c6f6773706f742e636f6d2f2d47674d44483277596f5f672f56547055673877733434492f41414141414141416b66552f7a5431686f346c76546d382f73313630302f30392e706e6

  1. Tests passed, build successful:

687474703a2f2f312e62702e626c6f6773706f742e636f6d2f2d456c4d57747638537534492f565470556845325f4c4d492f41414141414141416b66592f51346b5a6c3544377172672f73313630302f31302e706e6

Code Review with GitHub Flow

Currently, the two most commonly used workflows in development are Git flow and GitHub flow. You can refer to the following articles for more information:

Git flow:

GitHub flow:

  • The workflow used in GitHub
  • Here we use the GitHub flow, whose core principles are:

    • All code on the master branch must be tested and ready for deployment.
    • To develop features, fix bugs, or perform any other task, create a new branch from master.
    • Commit and push your code to GitHub at any time to discuss with others.
    • When a feature is complete, use a pull request to facilitate code review.
    • Only after confirmation that everything is correct can you merge back into master and deploy the new version online.

    Create a Branch

    1. To ensure that the code on the main master line remains stable, it is recommended that developers create separate branches for different features. Here, we use test-github-flow as an example. Use git branch to create the branch and then git checkout to switch to it:
    $ git branch test-github-flow
    $ git checkout test-github-flow

    Add Commits

    1. Add a failing test case assert.equal(3, [1,2,3].indexOf(5)) in test.js:
    // test/test.js
    // ...
    assert.equal(3, [1,2,3].indexOf(5));
    $ git add test/test.js
    $ git commit -m "add a error test case"

    Create a Pull Request

    1. Push to the test-github-flow branch on GitHub:
    $ git push -u origin test-github-flow
    1. After opening GitHub, you will see the pushed commits for the test-github-flow branch. Click the Compare & pull request button next to it:

    687474703a2f2f342e62702e626c6f6773706f742e636f6d2f2d3358664e484e4a485f76382f56547055694f727a456f492f41414141414141416b66302f6a385665765951437944672f73313630302f31332e706e6

    1. Clicking this will take you to the “Open a pull request” form. Select the target branch to merge into, enter a description, and then click the Create pull request button:

    687474703a2f2f332e62702e626c6f6773706f742e636f6d2f2d736645574f6e4f665747592f5654705569515a763571492f41414141414141416b66342f65387772416871544736512f73313630302f31342e706e6

    Review & Discuss Your Code

    1. After submitting a pull request, other users will receive notifications on GitHub:

    687474703a2f2f312e62702e626c6f6773706f742e636f6d2f2d4f393436777849474c696b2f5654705569393557376e492f41414141414141416b67452f454a354543344f677464732f73313630302f31352e706e6

    1. You can view the related commits and comments, but notice the large red “X” below. This is because every new push to GitHub triggers CircleCI’s automated build and test process, displaying the results directly on GitHub:

    687474703a2f2f332e62702e626c6f6773706f742e636f6d2f2d76337677694a59344759342f565470556a44714c6777492f41414141414141416b67492f57627850704769395069342f73313630302f31382e706e6

    1. Click the “X” to go to CircleCI and check the reason for the error:

    687474703a2f2f332e62702e626c6f6773706f742e636f6d2f2d6172664e434532504e6a492f565470556a744b7a7042492f41414141414141416b67512f4a55396f6a63342d5630452f73313630302f31392e706e6

    1. You will notice that the tests pushed to test-github-flow failed:

    687474703a2f2f342e62702e626c6f6773706f742e636f6d2f2d432d71756474766c6a556b2f565470556872504b6d6c492f41414141414141416b666f2f664c52495566694b615a772f73313630302f31322e706e6

    687474703a2f2f312e62702e626c6f6773706f742e636f6d2f2d2d49783939655738646e412f56547055687253714a41492f41414141414141416b666b2f30617048456a33685a30632f73313630302f31312e706e6

    Back on GitHub, because the tests did not pass, the reviewer cannot merge this pull request into master.

    1. Locate the code from the recent commit, leave a comment asking the developer to fix the error, and then re-commit and push:

    687474703a2f2f332e62702e626c6f6773706f742e636f6d2f2d4d466a385073454a2d68672f565470556a3644386c78492f41414141414141416b67592f347a644a76316a417945492f73313630302f32312e706e6

    687474703a2f2f332e62702e626c6f6773706f742e636f6d2f2d7253585f7a6d4c3542386b2f565470556b595f343662492f41414141414141416b67632f6632303541376a445043452f73313630302f32322e706e6

    687474703a2f2f322e62702e626c6f6773706f742e636f6d2f2d7a5154654271794e446d552f565470556b713566424b492f41414141414141416b676b2f36653653435453784474672f73313630302f32332e706e6

    1. Fix the test script in test.js:
    // test/test.js
    // ...
    assert.equal(-1, [1,2,3].indexOf(5));
    1. Commit & push again:
    $ git add test/test.js
    $ git commit -m "fix error test case"
    $ git push
    1. Return to the GitHub pull request page, where you can see that the latest commit has successfully passed the CircleCI tests:

    687474703a2f2f342e62702e626c6f6773706f742e636f6d2f2d773856576934434d51424d2f565470556c5164655878492f41414141414141416b67342f65794f736b3254314e68302f73313630302f32362e706e6

    687474703a2f2f322e62702e626c6f6773706f742e636f6d2f2d4b2d71506431356d7049772f565470556b324b6e7356492f41414141414141416b676f2f33744c6b74485a494778772f73313630302f32342e706e6

    687474703a2f2f312e62702e626c6f6773706f742e636f6d2f2d7874335859616c446d6a512f565470556c4a61797749492f41414141414141416b67302f6c306f44385969454b5a592f73313630302f32352e706e6

    Merge & Deploy

    1. After review, if everything is confirmed to be correct, you can click the Merge pull request button to merge the code from test-github-flow back into the main branch master:

    687474703a2f2f342e62702e626c6f6773706f742e636f6d2f2d695a7353466776494b58772f565470556c796e715877492f41414141414141416b68412f4f73723949657778657a492f73313630302f32372e706e6

    687474703a2f2f312e62702e626c6f6773706f742e636f6d2f2d70326731666a5a66416c492f565470556d5070523652492f41414141414141416b68452f3063642d506b63544c30592f73313630302f32382e706e6

    687474703a2f2f312e62702e626c6f6773706f742e636f6d2f2d726a7a37474a7a665a6c412f565470556d6149617a68492f41414141414141416b684d2f744f655937536f325964732f73313630302f32392e706e6

    Docker

    687474703a2f2f322e62702e626c6f6773706f742e636f6d2f2d7a426a6f4a4c4c6a7255302f56547051753752433841492f41414141414141416b63492f6b324e45733437595f4d492f73313630302f646f636b65722e706e6

    Installation:

    What is Docker? Why use it?

    Since Docker has become very popular, there are plenty of articles online introducing it. Please forgive me for only briefly mentioning it here:

    In the past, developers often faced issues with inconsistent development environments, leading to the frustrating situation where “it works on my machine.” To address such problems, virtual machines (VMs) were typically used along with tools like Vagrant and Chef to help unify the execution environment for developers, testers, and production deployments.

    687474703a2f2f332e62702e626c6f6773706f742e636f6d2f2d3564735356592d492d4e512f5654706263466c47564e492f41414141414141416b6b732f4546596f546a6774786d512f73313630302f766d2d76732d646f636b65722e706e6

    Docker offers a similar solution. Unlike VMs, Docker runs more lightweightly and offers higher portability. Once a configuration is set up, everyone can immediately start developing, reducing unnecessary environment-related issues and improving efficiency.

    Running Node.js in Docker

    1. Create a Dockerfile in the project root directory:
    # Dockerfile
    
    # Install the Node.js image from [Docker Hub](https://hub.docker.com/).
    FROM node:0.10
    
    # Set the default working directory inside the container
    WORKDIR /hello-ci-workflow
    
    # Copy files from the project root into the container
    # Install npm packages
    ADD . /hello-ci-workflow
    RUN npm install
    
    # Expose port 3000 on the container
    EXPOSE 3000
    CMD npm start
    1. Build your image using docker build:
    $ docker build -t hello-ci-workflow .
    

    -t hello-ci-workflow is the image name.

    1. Run your image using docker run:
    $ docker run -p 3000:3000 -d hello-ci-workflow

    -d runs Node in the background. You can check the execution results using docker logs.

    1. Open your browser to http://localhost:3000 to view the result:

    687474703a2f2f312e62702e626c6f6773706f742e636f6d2f2d316f705f565f50574749492f56547055664f50796f67492f41414141414141416b65772f69576453534d2d453648592f73313630302f30312e706e67

    Actually, having to build and run every time is quite cumbersome. We recommend trying Docker Compose, which works somewhat similarly to Vagrant.

    Testing Docker on CircleCI

    1. Modify circle.yml:
    # circle.yml
    machine:
      # Change environment to docker
      services:
        - docker
    
    dependencies:
      override:
        # Use docker build for construction
        - docker build -t hello-ci-workflow .
    
    test:
      override:
        - ./node_modules/.bin/mocha
        # Use curl to test if Node is running successfully in Docker
        - docker run -d -p 3000:3000 hello-ci-workflow; sleep 10
        - curl --retry 10 --retry-delay 5 -v http://localhost:3000
    
    1. Push updates to GitHub:
    $ git add Dockerfile circle.yml
    $ git commit -m "add Docker"
    $ git push
    1. Check CircleCI build and test results:

    687474703a2f2f342e62702e626c6f6773706f742e636f6d2f2d694264624c33546b4d624d2f565470556d6d4e4a6d31492f41414141414141416b68552f7473514d642d696b61776f2f73313630302f33302e706e6

    AWS Elastic Beanstalk

    687474703a2f2f342e62702e626c6f6773706f742e636f6d2f2d784375514a6233395a32732f56547054317871345a5a492f41414141414141416b656b2f7452452d545f306d7950452f73313630302f6265616e7374616c6b2e706e6

    Account:

    Installation:

    It’s time to deploy the application! There are many PaaS cloud platform options available now (Heroku, Google App Engine, Azure, OpenShift, Linode). Here, I will use Amazon’s Elastic Beanstalk as an example. Its features include:

    • Supports a wide range of development environments (Java, .NET, PHP, Node.js, Python, Ruby, GO), and notably includes support for Docker!
    • Simply upload your code, and Elastic Beanstalk will handle the deployment process, including capacity provisioning, load balancing, auto-scaling, and application health monitoring.

    687474703a2f2f322e62702e626c6f6773706f742e636f6d2f2d455658386f4c4c753958772f565470634c776f385776492f41414141414141416b6b302f487a7555433277365562592f73313630302f6177732d65622e706e6

    1. Initialize the EB environment:
    $ eb init -p docker

    -p allows you to specify the EB application platform, such as PHP; here we use Docker.

    The command will prompt you to configure various settings. Press Enter to accept the default values.

    If you already have a set of AWS EB credentials configured, the command will automatically use them. Otherwise, it will prompt you to enter your Access key ID and Secret access key, which must be created in AWS IAM.

    1. After successful initialization, you can use eb create to quickly provision different environments, such as development, staging, or production. Here, we use env-development as an example:
    $ eb create env-development

    Wait for Elastic Beanstalk to finish creating the environment. Once complete, your application will be equipped with load balancing and auto-scaling capabilities.

    687474703a2f2f312e62702e626c6f6773706f742e636f6d2f2d555743795f7342635776342f565470556d3276355946492f41414141414141416b68632f727362472d4d5f4958466f2f73313630302f33312e706e6

    1. Use eb open to view the running result of the current version:
    $ eb open env-development

    687474703a2f2f322e62702e626c6f6773706f742e636f6d2f2d334631586d454e575230732f565470556e587a4e5835492f41414141414141416b68672f4b745671356a6e546c31512f73313630302f33322e706e6

    Deploy AWS on Local Machine

    1. Slightly modify index.js:
    // index.js
    // ...
    app.get('/', function (req, res) {
      res.send('Hello env-development!');
    });
    // ...
    1. Run eb deploy to deploy the new version to AWS Elastic Beanstalk:
    $ eb deploy env-development

    687474703a2f2f332e62702e626c6f6773706f742e636f6d2f2d4f42364d644d6b6c7072672f5654705576712d597963492f41414141414141416b6b4d2f52426973343739336274632f73313630302f33342e706e6

    1. After deployment is complete, run eb open to open the webpage:
    $ eb open env-development

    687474703a2f2f342e62702e626c6f6773706f742e636f6d2f2d69636e30397167564961512f565470556e7a696a7364492f41414141414141416b68732f664b5541305048435a7a672f73313630302f33332e706e6

    The application update on env-development is complete.

    Deploy AWS on CircleCI

    1. git checkout switches the branch back to the main master line:
    $ git checkout master
    1. eb create creates a new environment for production deployment, named env-production:
    $ eb create env-production
    $ eb open env-production

    687474703a2f2f322e62702e626c6f6773706f742e636f6d2f2d636e4f4e667977414d54512f565470556f664a36656a492f41414141414141416b68772f6d304173684841356e524d2f73313630302f33352e706e6

    This successfully launches the second set of instances. We now have two environments: env-development and env-production.

    Navigate to AWS IAM to create an account for CircleCI:

    1. Dashboard > Users
    2. Create New Users
    3. Enter User Names: CircleCI > Create
    4. Download Credentials
    5. Dashboard > Users > CircleCI
    6. Attach Policy
    7. AWSElasticBeanstalkFullAccess > Attach Policy

    Go to CircleCI to configure your AWS permissions:

    1. Project Settings
    2. Permissions > AWS Permissions
    3. Open the previously downloaded credentials.csv file and enter the Access Key ID & Secret Access Key
    4. Save AWS keys
    5. Under the .elasticbeanstalk directory, create config.global.yml:
    # .elasticbeanstalk/config.global.yml
    global:
      application_name: hello-ci-workflow
      default_region: us-west-2 # The region where EB is located; default is us-west-2
    
    1. Modify circle.yml:
    # circle.yml
    machine:
      # Python is required to install EB
      python:
        version: 2.7
      services:
        - docker
    
    dependencies:
      pre:
        # Install EB CLI
        - sudo pip install awsebcli
      override:
        - docker build -t hello-ci-workflow .
    
    test:
      override:
        - npm test
        - docker run -d -p 3000:3000 hello-ci-workflow; sleep 10
        - curl --retry 10 --retry-delay 5 -v http://localhost:3000
    
    # Add a deployment script
    deployment:
      production:
        branch: master
        commands:
          - eb deploy env-production

    This allows CircleCI to automatically trigger builds, tests, and deployments whenever there are updates on the GitHub master branch.

    1. Next, let’s try out the workflow by modifying index.js:
    // index.js
    // ...
    app.get('/', function (req, res) {
      res.send('Hello env-production!');
    });
    // ...
    1. Commit & Push:
    $ git add .
    $ git commit "test deploy production"
    $ git push
    
    1. Go to CircleCI to check the results:

    687474703a2f2f332e62702e626c6f6773706f742e636f6d2f2d333156596e4b726e5a5f672f565470556f6879575442492f41414141414141416b68342f70696f43374162314765732f73313630302f33362e706e6

    1. Deployment successful. Use eb open to open your browser and view the result:
    $ eb open env-production

    687474703a2f2f322e62702e626c6f6773706f742e636f6d2f2d456f705179646e757872552f565470556f2d72597873492f41414141414141416b68382f584137736b506b744151412f73313630302f33372e706e6

    Slack

    687474703a2f2f342e62702e626c6f6773706f742e636f6d2f2d61367938543547665330492f5654705176365370615f492f41414141414141416b63672f567242693661527a366a632f73313630302f736c61636b2e706e6

    Account:

    We are almost done here. Let’s talk about Slack.

    Slack is a real-time communication tool designed for teams. Similar products include Gitter and HipChat.

    So, what sets it apart from software like Skype or Lync?

    It integrates with many development tools (such as GitHub and CircleCI). For example, notifications regarding new pushes, pull requests, or issues on GitHub, or failed unit tests in CircleCI, appear instantly in your team’s Slack channel. Since we have automated most of our workflow, it is essential to keep relevant stakeholders informed about activities within these tools. Therefore, using Slack is necessary.

    1. Log in to the Slack page
    2. Select Configure Integrations > CircleCI

    687474703a2f2f312e62702e626c6f6773706f742e636f6d2f2d64555f5549556e757231412f56547055705245614c4c492f41414141414141416b69492f67613447547853786b36512f73313630302f33382e706e6

    687474703a2f2f312e62702e626c6f6773706f742e636f6d2f2d3148714b4a69353056514d2f565470557056335f504d492f41414141414141416b694d2f665a706d35567a48396f4d2f73313630302f33392e706e6

    1. Select the channel to receive CircleCI notifications
    2. Click the Add CircleCI Integration button
    3. Copy the webhook URL displayed on the screen

    687474703a2f2f322e62702e626c6f6773706f742e636f6d2f2d764f74756f31593048346b2f5654705571466e7a5177492f41414141414141416b69552f7478366739686f4a6778732f73313630302f34302e706e6

    687474703a2f2f322e62702e626c6f6773706f742e636f6d2f2d63567852614c2d76434f672f5654705572666e4a3354492f41414141414141416b69772f5a796f324762307a79306f2f73313630302f34342e706e6

    1. Return to CircleCI
    2. Select Project settings > Chat Notifications
    3. Paste the copied Webhook URL > Save

    687474703a2f2f322e62702e626c6f6773706f742e636f6d2f2d4d34304773505f696b39512f56547055714f41516c67492f41414141414141416b69592f31556f54417573534279342f73313630302f34312e706e6

    687474703a2f2f342e62702e626c6f6773706f742e636f6d2f2d70416e74524e30694252632f565470557171504a6479492f41414141414141416b69732f496e517278586c4a436d302f73313630302f34322e706e6

    687474703a2f2f322e62702e626c6f6773706f742e636f6d2f2d76337161332d786b3341512f565470557139364f6952492f41414141414141416b696b2f635139436759396c3058772f73313630302f34332e706e6

    1. Follow similar steps to add GitHub notifications to Slack:

    687474703a2f2f342e62702e626c6f6773706f742e636f6d2f2d5a426d55686a595535586f2f565470557277546e3758492f41414141414141416b6a452f6b617837544264465668412f73313630302f34352e706e6

    687474703a2f2f332e62702e626c6f6773706f742e636f6d2f2d6f79475a51765442484c382f56547055723879697935492f41414141414141416b69382f6d595f525561547266706b2f73313630302f34362e706e6

    687474703a2f2f342e62702e626c6f6773706f742e636f6d2f2d706a6d686a6347656268512f5654705573556f547877492f41414141414141416b6a492f30516f6671664e6b5566342f73313630302f34372e706e6

    <img class="attachment-medium" src="https://1.bp.blogspot.com/-1TQ2EXVEVvM/VTpUs2T2uvI/AAAAAAAAkjQ/Rn5aVsYfUSA/s1600/48.png" alt="687474703a2f2f312e62702e626c6f6773706f742e636f6d2f2d31545132455856

    1. Modify index.js:
    // index.js
    // ...
    app.get('/', function (req, res) {
      res.send('Hello Slack!');
    });
    // ...
    1. Commit & Push:
    $ git add index.js
    $ git commit -m "index.js: update to test slack"
    $ git push -u origin test-slack
    1. Once CircleCI passes the tests, open a Pull Request.
    2. Merge test-slack back into master to trigger an automatic deployment via CircleCI.

    687474703a2f2f342e62702e626c6f6773706f742e636f6d2f2d795a376f566f6854426f452f56547055745a6936506e492f41414141414141416b6a672f47345f4464567465444b672f73313630302f35302e706e6

    687474703a2f2f312e62702e626c6f6773706f742e636f6d2f2d43376b5051362d5a376b6f2f56547055743855494d46492f41414141414141416b6a6f2f4a66724a4232554c45486f2f73313630302f35312e706e6

    That’s it! On your next build, you’ll start seeing CircleCI build notifications in your Slack chatroom.

    Done! You can see the notification process for each step displayed in the Slack channel:

    687474703a2f2f332e62702e626c6f6773706f742e636f6d2f2d4e71796a57466f317245452f56547055744578583343492f41414141414141416b6a592f47537943665037777735732f73313630302f34392e706e6

    Use eb open to open the browser and view the results; the new version has been successfully deployed automatically:

    $ eb open env-production
    

    687474703a2f2f312e62702e626c6f6773706f742e636f6d2f2d654a7367563843654430342f565470557544466c7237492f41414141414141416b6a732f666131785759656b7849732f73313630302f35322e706e6

    Conclusion

    “There is no road to the mountain of books; diligence is the only path. The sea of learning is boundless; hardship is the boat.” — Han Yu

    DevOps development processes and tools are constantly evolving every day. Stand on the shoulders of giants and maintain a mindset of lifelong learning.

    I have placed the source code for this example on GitHub. Feel free to check it out if you’re interested.

    If there are any areas in this article that need improvement, please do not hesitate to provide your feedback. I would greatly appreciate it.

    References

    FREE CHECKUP

    Free server checkup

    We will send a problem checklist and remediation advice within one business day — no obligation to engage.

    135 410 16684
    Weekdays Mon – Fri 10:00 – 22:00 (UTC+8) · 7×24 emergency response
    Call now
    CONTACT

    Contact Us

    How can we help?

    * Required