Type something to search...
Complete CI/CD pipeline automation starting with GitHub Actions

Complete CI/CD pipeline automation starting with GitHub Actions

Escape the nightmare of manual deployment

“Okay, now the coding is done! Let’s connect to the server, get git pull, reinstall dependencies, build, kill the existing process, and launch a new process.”

In the early stages of a project, this manual deployment process may not be too much of a hassle. But what if code needs to be integrated and deployed dozens of times a day as your service grows and your team members grow? The process of a person manually testing every time, connecting to the server, and running a script inevitably causes human error (mistakes) and prevents developers from fully focusing on development.

The practical methodology that solves these problems and automates the development cycle to maximize productivity is CI/CD (Continuous Integration / Continuous Deployment). And one of the easiest and most powerful tools to build this CI/CD is GitHub Actions.

What is CI/CD?

CI (Continuous Integration)

It means regularly and frequently consolidating code written by multiple developers into a central repository (e.g. the main branch on GitHub). The key to successful CI is that automated builds and tests are run whenever code is merged to immediately verify that the new code does not break (regress) the existing system.

CD (Continuous Delivery/Deployment)

This is the process of automatically releasing (distributing) code that has passed CI, that is, verification, to the actual production environment (server) or staging environment. Users will be able to experience the latest features pushed by developers in near real-time without any long waiting times.

Why GitHub Actions?

In the past, to build CI/CD, you had to link separate external services such as Jenkins, Travis CI, and CircleCI and go through complicated server settings. However, the ecosystem has changed significantly with the advent of GitHub Actions.

  1. Perfect integration: It operates directly within the GitHub repository where the code is stored, so there is no need for a separate service subscription or integration process.
  2. Event-based operation: Workflows can be executed according to almost all event triggers in GitHub, such as push, pull request opening, merging a specific branch, and periodic execution (Cron).
  3. Various open source actions: Even if you don't write your own script, numerous actions such as AWS connection, Docker build, Slack notification, etc. are created as 'action' units in the GitHub Marketplace, so you can just use them as if assembling blocks.
  4. Generous free quota: It is unlimited free in public repositories, and private repositories also provide a generous amount of execution time (2,000 minutes) for free each month.

GitHub Actions Capturing key concepts

These are the four main components you need to know before writing a configuration file.

  • Workflow: refers to the entire automated process. It is written as a YAML file (.yml) in the .github/workflows/ directory.
  • Event: This is a trigger that executes the workflow. (e.g. when code is pushed to the main branch)
  • Job: An independent unit of work executed within a workflow. One workflow can have multiple Jobs, and by default, they are executed in parallel. (e.g. test-job, deploy-job)
  • Step: A unit of individual commands executed sequentially within a Job. You can run a shell script (run) or use an action created by someone else (uses).

Example: Node.js project test automation (CI) workflow

This is a ci.yml example that automatically installs npm packages and runs test code whenever code is pushed in a simple React or Node.js project.

# .github/workflows/ci.yml
name: Node.js CI

# When will it run? (Event)
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build-and-test:
# What environment (OS) will it run in?
runs-on: ubuntu-latest

steps:
# 1. Import the code from the current repository into the virtual environment. (Checkout)
- name: Checkout repository
uses: actions/checkout@v3

# 2. Set up the Node.js environment.
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18.x'
cache: 'npm' # Speed ​​up the next build through npm caching.

# 3. Install dependency packages
- name: Install dependencies
run: npm ci

# 4. Run Lint check and test
- name: Run lint and tests
run: |
npm run lint
npm run test

finish

Save the above YAML code in .github/workflows/ in the top-level folder of the project, commit it, and push it. If you go to the 'Actions' tab of your GitHub repository, you'll see the magic of your workflow whirring away, furiously testing your code in an Ubuntu virtual environment.

Once your CI is fully established, the next step is to add a deployment (CD) pipeline to transfer this code to a server such as AWS EC2 or Vercel. With GitHub Actions, you can free yourself from tedious, repetitive manual tasks and spend more time writing creative code!

Related Post

The Complete Guide to Docker: Introduction to and Use of Container Technology for Beginners

The Complete Guide to Docker: Introduction to and Use of Container Technology for Beginners

What is Docker? One of the technologies that has brought about the most innovative changes in the software development and distribution environment in recent years is Docker. Docker is a software

Mastering Kubernetes: Container Orchestration Beyond Docker

Mastering Kubernetes: Container Orchestration Beyond Docker

What is Kubernetes? While Docker revolutionized the creation and management of single containers, Kubernetes (k8s for short) is a 'Container Orchestration' tool that automates the process of depl

The Complete Guide to Git Branching Strategy: From Git Flow to GitHub Flow

The Complete Guide to Git Branching Strategy: From Git Flow to GitHub Flow

A necessity for collaboration, Git branch strategy In software development projects, when multiple developers write code simultaneously, conflicts and confusion inevitably arise. “Who modified th

React vs Vue.js: Guide to Choosing a Front-End Framework in 2024

React vs Vue.js: Guide to Choosing a Front-End Framework in 2024

Front-end war, what is your choice? If you are at all interested in web development, you have probably heard the names 'React' and 'Vue.js' at least once. As the jQuery era comes to an end and th

Website Performance Optimization Strategies: How Loading Speed ​​​​Affects Your Business

Website Performance Optimization Strategies: How Loading Speed ​​​​Affects Your Business

Butterfly effect with 1 second loading speed The patience of not only Koreans, a “fast, quick” people, but also internet users around the world, is getting shorter and shorter. An Amazon study fo

Python Data Analysis Basics: Mastering Pandas Core Functions

Python Data Analysis Basics: Mastering Pandas Core Functions

Excel in the Python data ecosystem, Pandas Why was Python able to become the overwhelming number one language in the fields of data science and machine learning? This is thanks to an excellent ec

Introduction to AWS EC2: Building Your First Cloud Server

Introduction to AWS EC2: Building Your First Cloud Server

I need my own server! The joy I felt when I studied programming and created my first web application is indescribable. However, if it only works on my computer's local host (localhost:3000), it w

TypeScript 101: Putting ‘seatbelts’ on JavaScript

TypeScript 101: Putting ‘seatbelts’ on JavaScript

Betrayal of JavaScript JavaScript is the most widely used language in the world, and is a very flexible and easy to write language. However, as the project size grows and becomes more complex, 'f

Summary of essential Linux terminal commands for backend developers

Summary of essential Linux terminal commands for backend developers

Throw away the mouse and become familiar with the keyboard If you are used to the fancy GUI (graphical user interface) environment of Windows or Mac OS, when you first connect to a remote server

Practical guide to developer-prompted engineering in the era of generative AI

Practical guide to developer-prompted engineering in the era of generative AI

Introduction: Why do developers need prompt engineering? In an era where generative AI writes code and fixes bugs, the role of developers is rapidly evolving from simply ‘typing’ code to ‘designi

Front-end ecosystem trends in 2024: What should we learn and prepare for?

Front-end ecosystem trends in 2024: What should we learn and prepare for?

Introduction: The ever-changing front-end ecosystem Among the web development fields, the front-end ecosystem is one where the speed of change is dazzlingly fast. New frameworks and tools are con

Platform Engineering: The Next Evolutionary Step in DevOps

Platform Engineering: The Next Evolutionary Step in DevOps

Introduction: The Paradox of "You build it, you run it" The DevOps culture, epitomized by Amazon CTO Werner Vogels' famous quote "You build it, you run it," has contributed greatly to increasing

Cloud Native Architecture Essential Guide: From MSA to Kubernetes

Cloud Native Architecture Essential Guide: From MSA to Kubernetes

Introduction: Why is everyone shouting ‘cloud native’? In the past IT environment, server equipment was purchased directly (On-Premise) and an entire huge application (Monolithic) was installed a

AI-Assisted Software Engineering: How AI is Rewriting the Rules of Coding

AI-Assisted Software Engineering: How AI is Rewriting the Rules of Coding

Introduction: The End of the "Human Typewriter" Era For decades, the core image of a software engineer was someone hunched over a keyboard, manually typing thousands of lines of syntax, hunting d