DEV Community

Cover image for Automate CI/CD with CircleCI and Github
Olawale Adepoju for AWS Community Builders

Posted on • Originally published at dev.classmethod.jp

Automate CI/CD with CircleCI and Github

Introduction

CircleCI is a service that detects changes in your codebase and executes tasks defined on it.

With the need for DevOps in the automation of our applications, I have been doing a few studies and I stumbled on CircleCI as a CI/CD tool and decided to look a bit deeper.

In this post, I will be explaining with a simple demo an introduction to CircleCI.

What is CI/CD?

This is a common term that everyone uses, it explains the continuous integration and continuous deployment

Continuous Integration (CI) - When you push a code update, you want to know if the code is still okay. For example, does the code compile (build), and do all of the tests pass?

Continuous Deployment (CD) - After making a code update, deploy that code to wherever it is supposed to be. For example, deploy a server to AWS. CI/CD is extremely valuable because automation saves time and optimizes workflows, which is especially important when working with others.

Setting up CI with CircleCI

From the GitHub repository, activate CI on it by configuring CircleCI.

First, generate a configuration file in order for CircleCI to understand what we want it to accomplish. Create a folder called ".circleci" and a file called "config.yml" inside it.

In the config.yml add this code:

version: 2.1
jobs:
build:
working_directory: ~/circleci-python
docker:
- image: "circleci/python:3.6.4"
steps:
- checkout
- run: python3 main.py
test:
working_directory: ~/circleci-python
docker:
- image: "circleci/python:3.6.4"
steps:
- checkout
- run: python3 main-test.py
workflows:
build_and_test:
jobs:
- build
- test:
requires:
- build
Enter fullscreen mode Exit fullscreen mode

NOTE: make sure your config.yml is indented correctly

Image description

Now let's push our new config file to GitHub.

CircleCI should detect the code changes and run our build_and_test workflow for our branch. Also, the jobs run on CircleCI must be visible.

Image description

Testing the CircleCI

In the main-test.py file, I added a new line of code

assert Add(6,6) ==11

that is false, to check how the build output will act.

Image description

Conclusion

CI/CD is important, and I have shown how it can be integrated with a simple project.I will be setting up more complicated projects in the future.Look out for more on this post.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more

Top comments (0)

Best Practices for Running  Container WordPress on AWS (ECS, EFS, RDS, ELB) using CDK cover image

Best Practices for Running Container WordPress on AWS (ECS, EFS, RDS, ELB) using CDK

This post discusses the process of migrating a growing WordPress eShop business to AWS using AWS CDK for an easily scalable, high availability architecture. The detailed structure encompasses several pillars: Compute, Storage, Database, Cache, CDN, DNS, Security, and Backup.

Read full post