Skip to main content

CI/CD Pipelines

Rahat uses GitHub Actions for continuous integration and deployment (CI/CD) to automate the build, test, and deployment processes. The project implements two main pipelines: one for production deployment and another for development testing.

Overview

The CI/CD system is designed to:

  • Automatically build and test code changes
  • Deploy documentation to GitHub Pages
  • Build and push Docker images
  • Ensure code quality and consistency
  • Provide fast feedback on pull requests

Pipeline Structure

1. Production Deployment Pipeline (deploy.yml)

This pipeline handles the main branch deployment and is triggered on:

  • Push to main branch
  • Pull requests to main branch

Location: .github/workflows/deploy.yml

Workflow Steps:

  1. Checkout Repository

    • Uses actions/checkout@v4 to clone the repository
  2. Node.js Setup

    • Sets up Node.js version 20.x
    • Configures GitHub token for authentication
  3. Git Configuration

    • Sets up git user credentials for deployment
    • Configures user as "sandab-rumsan" with email "sandab@rumsan.net"
  4. Build Process

    • Installs dependencies using yarn
    • Builds the Docusaurus documentation site using yarn run build
  5. Deployment

    • Uses peaceiris/actions-gh-pages@v3 action
    • Publishes the built documentation to GitHub Pages
    • Deploys from the ./build directory

2. Development CI/CD Pipeline (Dev-CICD.yaml)

This pipeline handles development branch testing and Docker image building, triggered on:

  • Push to dev branch
  • Pull requests to dev branch

Location: .github/workflows/Dev-CICD.yaml

Workflow Steps:

  1. Checkout Repository

    • Uses actions/checkout@v4 to clone the repository
  2. Node.js Setup

    • Sets up Node.js version 20
    • Uses actions/setup-node@v4
  3. Dependency Installation

    • Installs project dependencies using yarn install
  4. Build Testing

    • Builds the React application using yarn build
    • Ensures the build process works correctly
  5. Docker Setup

    • Sets up Docker Buildx for multi-platform builds
    • Uses docker/setup-buildx-action@v3
  6. Docker Authentication

    • Logs into Docker Hub using secrets
    • Uses docker/login-action@v3
  7. Docker Build and Push

    • Builds Docker image using the project's Dockerfile
    • Tags the image as esatya/rahat-docs:dev
    • Pushes to Docker Hub only on push events (not on pull requests)

Configuration Details

Environment Variables

The pipelines use several GitHub secrets:

  • GITHUB_TOKEN: Automatically provided by GitHub Actions
  • DOCKERHUB_USERNAME: Docker Hub username for image publishing
  • DOCKERHUB_TOKEN: Docker Hub access token for authentication

Build Configuration

Node.js Version

  • Production: Node.js 20.x (matrix strategy)
  • Development: Node.js 20

Package Manager

  • Uses yarn for dependency management
  • Builds using yarn build command

Docker Configuration

  • Base image: nginx:1.25.0-alpine3.17
  • Custom nginx configuration in conf.d/
  • Serves static files from /usr/share/nginx/html

Deployment Strategy

GitHub Pages Deployment

  • Trigger: Push to main branch
  • Target: GitHub Pages
  • Method: Uses peaceiris/actions-gh-pages@v3
  • URL: https://docs.rahat.io

Docker Image Deployment

  • Trigger: Push to dev branch
  • Target: Docker Hub
  • Image: esatya/rahat-docs:dev
  • Registry: Docker Hub

Branch Strategy

Main Branch (main)

  • Production-ready code
  • Automatic deployment to GitHub Pages
  • Requires pull request reviews

Development Branch (dev)

  • Development and testing
  • Docker image building and pushing
  • Continuous integration testing

Monitoring and Troubleshooting

Pipeline Status

  • Check pipeline status in the GitHub Actions tab
  • Monitor deployment logs for errors
  • Verify successful builds and deployments

Common Issues

  1. Build Failures

    • Check Node.js version compatibility
    • Verify all dependencies are properly installed
    • Review build logs for specific error messages
  2. Deployment Failures

    • Verify GitHub Pages is enabled for the repository
    • Check GitHub token permissions
    • Ensure build directory exists and contains files
  3. Docker Build Issues

    • Verify Docker Hub credentials
    • Check Dockerfile syntax
    • Ensure Docker context is correct

Debugging Steps

  1. Local Testing

    # Test build locally
    yarn install
    yarn build

    # Test Docker build
    docker build -t rahat-docs:test .
  2. Pipeline Debugging

    • Enable debug logging in GitHub Actions
    • Check workflow run logs
    • Verify secret configurations

Best Practices

Code Quality

  • All changes must pass CI/CD pipeline
  • Pull requests require successful builds
  • Automated testing prevents deployment of broken code

Security

  • Use GitHub secrets for sensitive data
  • Never commit credentials to repository
  • Regularly rotate access tokens

Performance

  • Optimize build times with caching
  • Use multi-stage Docker builds
  • Minimize image sizes

Customization

Adding New Environments

To add a new environment (e.g., staging):

  1. Create a new workflow file in .github/workflows/
  2. Configure branch triggers
  3. Set up environment-specific secrets
  4. Configure deployment targets

Modifying Build Process

To modify the build process:

  1. Update package.json scripts
  2. Modify workflow steps in YAML files
  3. Test changes in development branch first
  4. Update documentation accordingly