Learn

CircleCI: What it is and why it should be part of your Redis CI-CD

What is CircleCI?

CircleCI is a CI/CD platform built by DevOps professionals to help you fine-tune your entire development process from start to finish. It helps engineering teams build, test, and deploy software while checking code changes in real time with the CircleCI dashboard UI. More control over pipelines is possible with the ability to build in the CI/CD process per project or configure workflows to decide on when and how jobs run, plus data- and image-caching options that optimize continuous delivery. 


CircleCI supports many different languages and a varied amount of cloud-hosted compute types such as Docker, Linux VMs, macOS, Windows, and more for a simplified approach to infrastructure. With the CircleCI dashboard, it's possible to gather insights on build changes to continuously optimize pipelines. 


To deploy, CircleCI takes artifacts from your pipeline and sends them to wherever you need them deployed, whether it's Docker, Heroku, Kubernetes, cloud platforms, and more.


How does CircleCI work?

After GitHub or Bitbucket is authorized and added as a project to cirlceci.com, every code change triggers CircleCI jobs. CircleCI sends an email notification of success or failure after the test is completed. CircleCI finds and runs config.yml, tests the build, runs security scans, goes through approval steps, and then deploys.

What are CircleCI’s capabilities?

As a DevOps engineer or developer, you can:

  • SSH into any job to debug build issues.

  • Set up jobs to run in parallel to reduce time.

  • Configure a Redis cache with two simple keys to reuse data from previous jobs in your workflow.

  • Configure self-hosted runners for unique platform support.

  • Access Arm resources for the machine executor. 

  • Use reusable packages of configuration to integrate with third parties.

  • Use a pre-built Redis Docker image in a variety of languages. 

  • Use the API to retrieve information about jobs and workflows.

  • Use the CLI to access advanced tools locally. 

  • Get flaky test detection with test insights. 

Deploy Redis Rate Limiting application on Heroku using CircleCI

Prerequisites:

  • A CircleCI account

  • A GitHub account

  • A Heroku account


Getting started


In this demo, we will be using the Redis Rate Limiting app built using Python and Redis. 

Rate limiting is a mechanism that many developers may have to deal with at some point in their life. It’s useful for a variety of purposes, such as sharing access to limited resources or limiting the number of requests made to an API endpoint and responding with a 429 status code. The complete source code of the project is hosted over GitHub. In this example, we will configure CircleCI to deploy the Rate Limiting app directly on the Heroku platform.


Step 1. Go to https://circleci.com and log in using your GitHub account

Choose your preferred login method. To make it easier, let us choose “GitHub” for this demonstration.

Step 2. Verify your permission on GitHub

Step 3. Select your project repository and click “Setup Project”


We will be using the Redis rate-limiting project for this demonstration.


Step 4. Create a new CircleCI configuration file


CircleCI believes in configuration as code. As a result, the entire delivery process from build to deployment is orchestrated through a single file called config.yml. The config.yml file is located in a folder called .circleci at the top of your project. CircleCI uses the YAML syntax for config.

As we haven’t yet created a config.yml file, let’s choose the “Fast” option to create a new config.yml based on the available template that is editable.

Once you click “Set Up project,” it will ask you to select sample configs as shown in the following screenshot:
Add the following content under .circleci/config.yml and save the file:

In the configuration above, we pull in the Heroku orb circleci/[email protected], which automatically gives us access to a powerful set of Heroku jobs and commands.

One of those jobs is the heroku/deploy-via-git, which deploys your application straight from your GitHub repo to your Heroku account.

Step 5. Merge the pull request


Once you make the new change, it will ask you to raise a new PR. Go ahead and merge the changes as of now.

Step 6. Set up Heroku account

Follow these steps to set up a Heroku account and create a new app `rate-limit-python`. You will need the Heroku API key for this demo.

Configuring Heroku access on CircleCI

Before you push your project to Heroku from CircleCI, you will need to configure an authenticated handshake between CircleCI and Heroku. Configure the handshake by creating two environment variables in the settings for your CircleCI project:

  • HEROKU_APP_NAME is the name of your Heroku application (in this case, simple-node-api-circleci)

  • HEROKU_API_KEY is your Heroku account API key. This can be found under the Account tab of your Heroku account under Account Settings. Scroll to the API Key section and click Reveal to copy your API key.

Step 7. Set up the environment variables on CircleCI


On the sidebar menu of the settings page, click Environment Variables under Build Settings. On the environment variables page, create two variables named HEROKU_APP_NAME and HEROKU_API_KEY and enter the values for them.

With these in place, our CircleCI configuration will be able to make authenticated deployments to the Heroku platform.

Step 8. Trigger the build

As soon as you merge the pull request, the tool will trigger the build automatically.

By now, you should be able to access your application.