DevOps CI/CD Pipeline Behind APIs Service of xyzuan v2
Published onNovember 06, 2024
141Views
10min read
1Comment
1Comment
Automating deployments with a powerful CI/CD pipeline to ensure seamless and efficient API service updates on xyzuan v2. By integrating GitHub Actions with a self-hosted runner, we streamline the process of building and deploying Docker images. Images are pushed securely to GitHub Container Registry (GHCR) and then deployed to an Azure VM, ensuring high scalability and reliable service delivery from code to cloud.
Pipeline Overview
This CI/CD pipeline enables continuous delivery, allowing code changes to go from development to production with minimal manual intervention. With each update, we automate the following stages:
- Build and Test: Code is built, tested, and verified for quality assurance using GitHub Actions.
- Image Creation: A Docker image is generated, containing all necessary components to run the API service.
- Image Storage: The image is pushed to the GitHub Container Registry (GHCR) for secure, centralized storage.
- Deployment: The Docker image is pulled from GHCR and deployed to an Azure Virtual Machine for immediate service updates.
Tools and Components
Here's a breakdown of the tools used to power this CI/CD pipeline:
1. GitHub Actions
GitHub Actions is a CI/CD tool that automates workflows directly within GitHub. It handles various tasks, from testing and building to deploying code changes, all triggered by events (such as pushing code or creating pull requests). This tool ensures code quality and expedites the deployment process.
2. GitHub Self-Hosted Runner
A self-hosted runner is a custom runner that you host yourself, enabling you to execute GitHub Actions workflows on your own infrastructure. This allows for more control over the environment and is ideal for cases where access to specific resources or configurations is needed.
3. GitHub Container Registry (GHCR)
The GitHub Container Registry (GHCR) is a Docker container storage service from GitHub. GHCR securely stores and manages Docker images, making them easily accessible for deployments. Using GHCR enables seamless integration with GitHub Actions, providing a secure and efficient workflow for managing containers.
4. Docker Image
A Docker image is a portable, self-sufficient package containing everything needed to run an application. This image includes the application code, runtime, libraries, and dependencies, ensuring consistency across different environments.
5. Azure Virtual Machine (VM)
An Azure VM is a scalable virtual machine hosted on Microsoft Azure’s cloud platform. This VM provides a robust environment to run our Dockerized API service, offering flexibility and on-demand resources to handle varying levels of traffic.
CI/CD Architecture
This architecture illustrates a CI/CD pipeline designed for automating production builds and deployments. Using GitHub Actions with a self-hosted runner, code changes are built into Docker images, securely pushed to the GitHub Container Registry (GHCR), and deployed to an Azure Virtual Machine (VM). This setup streamlines the process from code commits to production, ensuring efficient updates, high scalability, and consistent service delivery.
Build Production Github Action Workflow
Below is a sample GitHub Actions YAML configuration for automating production builds and deployments:
Preview of Github Action
#ci/cd
#devops
#docker
Comments