CI/CD Pipeline Setup on Ubuntu 22.04 Using GitHub Actions

Introduction In this guide, we will walk you through the process of setting up a CI/CD pipeline on Ubuntu 22.04 using GitHub Actions. Continuous...


0

Introduction

In this guide, we will walk you through the process of setting up a CI/CD pipeline on Ubuntu 22.04 using GitHub Actions. Continuous Integration and Continuous Deployment (CI/CD) are essential for automating the software development lifecycle. By the end of this guide, you will have a functional pipeline setup on Ubuntu that streamlines your workflow. Our focus will be on leveraging GitHub Actions to create an efficient CI/CD pipeline setup on Ubuntu. We’ll cover each step in detail, ensuring you have a comprehensive understanding of how to implement and manage this system. Let’s dive into the prerequisites needed for this setup.

Prerequisites

Before we begin, ensure you have the following:

  • A machine running Ubuntu 22.04
  • A GitHub account
  • Basic knowledge of Git
  • A sample application repository on GitHub

Having these prerequisites will ensure a smooth pipeline setup process on your Ubuntu machine. With these essentials in place, let’s move on to the initial steps of the setup.

Step 1: Install Required Packages

First, update your system and install necessary packages like Git and Docker. These tools are essential for setting up a CI/CD pipeline on Ubuntu.

sudo apt update && sudo apt install git docker.io -y

This command updates your package list and installs Git and Docker, crucial tools for managing code and containers in your pipeline setup on Ubuntu. With these packages installed, we can proceed to the next step.

Step 2: Set Up Docker Permissions

To avoid using sudo with Docker commands, add your user to the Docker group. This step is important for streamlining operations during the pipeline execution.

sudo usermod -aG docker ${USER}

After running this command, log out and log back in to apply the changes. This modification allows Docker commands to run without superuser privileges, enhancing efficiency in your CI/CD pipeline setup on Ubuntu. Now, let’s configure GitHub Actions.

Step 3: Configure GitHub Actions

Create a .github/workflows directory in your repository to define GitHub Actions workflows. Workflows automate tasks like testing or deploying code changes.

mkdir -p .github/workflows

This directory holds YAML files that describe your CI/CD processes, making it central to your pipeline setup on Ubuntu using GitHub Actions. With the directory ready, we can create a workflow file.

Step 4: Create a Workflow File

Inside the workflows directory, create a file named ci-cd.yml. This file contains the configuration for building and deploying your application.

name: CI/CD Pipeline

on:
  push:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Set up Node.js
        uses: actions/setup-node@v2
        with:
          node-version: '14'
      - run: npm install
      - run: npm test
      - run: npm run build

This sample YAML file triggers a build whenever changes are pushed to the main branch. It is pivotal in automating various stages of the CI/CD pipeline setup on Ubuntu. Next, let’s implement the deployment steps.

Step 5: Implement Deployment Steps

Extend your workflow file to include deployment steps. Deploying updates automatically is a key component of an effective CI/CD pipeline.

deploy:
    runs-on: ubuntu-latest
    needs: build
    steps:
      - run: echo "Deploying application"

These additional steps ensure that after successful builds, your application is deployed, completing the full cycle of CI/CD in your pipeline setup on Ubuntu. Now, it’s time to push your changes.

Step 6: Push Changes to GitHub

Commit and push your changes to GitHub so that GitHub Actions can start executing the defined workflows. Ensure all files are correctly staged before pushing.

git add . 
git commit -m "Add CI/CD workflow"
git push origin main

These commands commit your workflow configuration to version control, allowing automatic execution as part of the pipeline setup on Ubuntu. If you encounter issues, refer to the troubleshooting section.

Troubleshooting.

Common Issue 1

If workflows do not trigger as expected, check branch names in your YAML file. Ensure they match exactly with those used in your repository settings. Correct branch configurations are crucial for activating workflows during the pipeline setup on Ubuntu.


Like it? Share with your friends!

0

What's Your Reaction?

hate hate
0
hate
confused confused
0
confused
fail fail
0
fail
fun fun
0
fun
geeky geeky
0
geeky
love love
0
love
lol lol
0
lol
omg omg
0
omg
win win
0
win
Anoop Patel