[Circle CI] Auto deploying web apps on Heroku

Tram Ho

The previous article has a guide on how to build projects with CircleCI. However, CircleCI has another advantage: automating the application deployment after building and running tests. This section we see the configuration so it automatically deploying offline. It is also simple 😄

Let’s practice !!!!!

1. Deploy the application to Heroku

Of course, to deploy 1 automatically, you have to deploy manually, right? Basically, you only need to remote into heroku remote and push to the master branch

Details refer to the article

2. Configure the CI for the application

My previous article showed how to configure on CircleCI 2.0. This part I do not repeat that focus on auto deploy configuration section on Heroku

2.1. Add environment variables

First you need to add variables from the Heroku application as environment variables. We need to add 2 variables HEROKU_APP_NAME and HEROKU_API_KEY to be able to automatically deploy Refs: https://circleci.com/docs/2.0/env-vars/#setting-an-environment-variable-in-a-project

  • Step 1: Go to the Circle application, select the project (Click JOBS ) you want to deploy automatically. Click the Setting icon to the right of the project
  • Step 2: In the Build Setting section, click Environment Variables
  • Step 3: Import variables from another project by clicking the Import Variable (s) button or adding new variables by clicking the button ** Add Variable ** (Note that Import Variables (s) is not available on CircleCI installed. set private)
  • Step 4: Use these variables in the file .circleci/config.yml only.

2.2. Edit config

File .circleci/config.yml :

I only tested deploying automatically, not building and testing, so it would be as simple as:

It’s good, so from now on every time you commit code to the master branch, the project will automatically be built, check the things you have configured (in build jobs) and automatically deploy to Heroku via the command

This is the Deploy detailed result

Simple as that. However, this is just the simplest level (hello world) for automatically deploying the application, other sections you can learn more on the CircleCI homepage to configure


Share the news now

Source : Viblo