DevOps Sessions - Week 8 - CI/CD

devops integration delivery deployment jenkins gitlab ci github actions 19-09-2024 ​​

DevOps Sessions - Week 8 - CI/CD

Welcome to Week 8 of our “Becoming a DevOps Engineer” series! This week, we will explore Continuous Integration and Continuous Deployment (CI/CD), key practices in modern software development that enable faster and more reliable delivery of applications. We’ll dive into some of the most popular CI/CD tools: Jenkins, GitLab CI/CD, GitHub Actions, and AWS CodePipeline. Let’s get started!

Session Overview

1. Introduction to CI/CD

2. Jenkins

3. GitLab CI/CD

4. GitHub Actions

5. AWS CodePipeline

1. Introduction to CI/CD

What is CI/CD?

CI/CD stands for Continuous Integration and Continuous Deployment (or Continuous Delivery). Continuous Integration involves regularly merging code changes into a central repository, followed by automated builds and tests. Continuous Deployment extends this by automatically deploying code changes to production.

Benefits of CI/CD in DevOps

2. Jenkins

Overview of Jenkins

Jenkins is an open-source automation server that facilitates CI/CD. It supports various plugins for building, deploying, and automating any project.

Setting Up Jenkins

  1. Install Jenkins: Download and install Jenkins from jenkins.io.
  2. Configure Jenkins: Set up the initial admin user and configure necessary plugins.

Creating a CI/CD Pipeline with Jenkins

  1. Create a New Job: Navigate to the Jenkins dashboard and create a new freestyle project or pipeline.
  2. Configure the Job: Define the source code repository, build triggers, and build steps.
  3. Example Pipeline Script:
    pipeline {
        agent any
        stages {
            stage('Build') {
                steps {
                    sh 'make build'
                }
            }
            stage('Test') {
                steps {
                    sh 'make test'
                }
            }
            stage('Deploy') {
                steps {
                    sh 'make deploy'
                }
            }
        }
    }
  4. Run the Job: Save the configuration and run the job to see the CI/CD pipeline in action.

3. GitLab CI/CD

Overview of GitLab CI/CD

GitLab CI/CD is integrated into GitLab, providing a comprehensive platform for managing your repositories and CI/CD pipelines.

Setting Up GitLab CI/CD

  1. Create a GitLab Repository: If you don’t already have one, create a new repository on GitLab.
  2. Configure the CI/CD Pipeline: Add a .gitlab-ci.yml file to the root of your repository.

Creating a CI/CD Pipeline with GitLab CI/CD

  1. Example .gitlab-ci.yml:
    stages:
      - build
      - test
      - deploy
    
    build_job:
      stage: build
      script:
        - echo "Building the application"
        - make build
    
    test_job:
      stage: test
      script:
        - echo "Testing the application"
        - make test
    
    deploy_job:
      stage: deploy
      script:
        - echo "Deploying the application"
        - make deploy
  2. Commit and Push: Commit the .gitlab-ci.yml file and push it to the GitLab repository.
  3. View Pipeline: Navigate to the CI/CD section in your GitLab project to view the pipeline status.

4. GitHub Actions

Overview of GitHub Actions

GitHub Actions enables automation of workflows directly from your GitHub repository. It supports CI/CD, and many other types of automation.

Setting Up GitHub Actions

  1. Create a GitHub Repository: If you don’t already have one, create a new repository on GitHub.
  2. Add a Workflow File: Create a .github/workflows directory in your repository and add a workflow file, e.g., ci.yml.

Creating a CI/CD Workflow with GitHub Actions

  1. Example Workflow File (ci.yml):
    name: CI/CD Pipeline
    
    on: [push]
    
    jobs:
      build:
        runs-on: ubuntu-latest
        steps:
        - name: Checkout code
          uses: actions/checkout@v2
        - name: Build
          run: make build
      test:
        runs-on: ubuntu-latest
        steps:
        - name: Checkout code
          uses: actions/checkout@v2
        - name: Test
          run: make test
      deploy:
        runs-on: ubuntu-latest
        steps:
        - name: Checkout code
          uses: actions/checkout@v2
        - name: Deploy
          run: make deploy
  2. Commit and Push: Commit the workflow file and push it to the GitHub repository.
  3. View Actions: Navigate to the Actions tab in your GitHub repository to view the workflow status.

5. AWS CodePipeline

Overview of AWS CodePipeline

AWS CodePipeline is a fully managed CI/CD service that automates the build, test, and deploy phases of your release process.

Setting Up AWS CodePipeline

  1. Create a Pipeline: Navigate to the AWS CodePipeline console and create a new pipeline.
  2. Configure Source, Build, and Deploy Stages:
    • Source Stage: Connect your source repository (e.g., GitHub, S3).
    • Build Stage: Use AWS CodeBuild or another build provider.
    • Deploy Stage: Deploy to services like AWS Elastic Beanstalk, ECS, or Lambda.

Creating a CI/CD Pipeline with AWS CodePipeline

  1. Example Pipeline Configuration:
    • Source: GitHub repository.
    • Build: AWS CodeBuild project with a buildspec.yml file.
    • Deploy: AWS Elastic Beanstalk or another deployment target.
  2. Example buildspec.yml:
    version: 0.2
    
    phases:
      install:
        commands:
          - echo Installing dependencies
          - npm install
      build:
        commands:
          - echo Building the application
          - npm run build
      post_build:
        commands:
          - echo Post-build phase
          - npm test
    
    artifacts:
      files:
        - '**/*'
  3. Trigger Pipeline: Push changes to your source repository to trigger the pipeline.

By mastering these CI/CD tools and practices, you are well-equipped to automate your software delivery process, ensuring faster and more reliable releases. Stay tuned for next week’s session, where we will explore infrastructure as code. Happy deploying!

Author's photo

Nihit Jain

Architecting DevOps 🏗️ with Data, AI, Security, & IoT on Cloud ☁️




See other articles:

Sessions