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
- What is CI/CD?
- Benefits of CI/CD in DevOps
2. Jenkins
- Overview of Jenkins
- Setting Up Jenkins
- Creating a CI/CD Pipeline with Jenkins
3. GitLab CI/CD
- Overview of GitLab CI/CD
- Setting Up GitLab CI/CD
- Creating a CI/CD Pipeline with GitLab CI/CD
4. GitHub Actions
- Overview of GitHub Actions
- Setting Up GitHub Actions
- Creating a CI/CD Workflow with GitHub Actions
5. AWS CodePipeline
- Overview of AWS CodePipeline
- Setting Up AWS CodePipeline
- Creating a CI/CD Pipeline with 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
- Faster Releases: Automated processes enable frequent and reliable releases.
- Improved Quality: Automated testing catches errors early in the development cycle.
- Increased Collaboration: Teams can work independently and integrate changes smoothly.
- Reduced Risk: Incremental updates and automated rollback mechanisms reduce deployment risks.
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
- Install Jenkins: Download and install Jenkins from jenkins.io.
- Configure Jenkins: Set up the initial admin user and configure necessary plugins.
Creating a CI/CD Pipeline with Jenkins
- Create a New Job: Navigate to the Jenkins dashboard and create a new freestyle project or pipeline.
- Configure the Job: Define the source code repository, build triggers, and build steps.
- 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' } } } }
- 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
- Create a GitLab Repository: If you don’t already have one, create a new repository on GitLab.
- 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
- 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
- Commit and Push: Commit the
.gitlab-ci.yml
file and push it to the GitLab repository. - 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
- Create a GitHub Repository: If you don’t already have one, create a new repository on GitHub.
- 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
- 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
- Commit and Push: Commit the workflow file and push it to the GitHub repository.
- 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
- Create a Pipeline: Navigate to the AWS CodePipeline console and create a new pipeline.
- 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
- Example Pipeline Configuration:
- Source: GitHub repository.
- Build: AWS CodeBuild project with a
buildspec.yml
file. - Deploy: AWS Elastic Beanstalk or another deployment target.
- 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: - '**/*'
- 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!