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:
-
Checkout Repository
- Uses
actions/checkout@v4
to clone the repository
- Uses
-
Node.js Setup
- Sets up Node.js version 20.x
- Configures GitHub token for authentication
-
Git Configuration
- Sets up git user credentials for deployment
- Configures user as "sandab-rumsan" with email "sandab@rumsan.net"
-
Build Process
- Installs dependencies using
yarn
- Builds the Docusaurus documentation site using
yarn run build
- Installs dependencies using
-
Deployment
- Uses
peaceiris/actions-gh-pages@v3
action - Publishes the built documentation to GitHub Pages
- Deploys from the
./build
directory
- Uses
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:
-
Checkout Repository
- Uses
actions/checkout@v4
to clone the repository
- Uses
-
Node.js Setup
- Sets up Node.js version 20
- Uses
actions/setup-node@v4
-
Dependency Installation
- Installs project dependencies using
yarn install
- Installs project dependencies using
-
Build Testing
- Builds the React application using
yarn build
- Ensures the build process works correctly
- Builds the React application using
-
Docker Setup
- Sets up Docker Buildx for multi-platform builds
- Uses
docker/setup-buildx-action@v3
-
Docker Authentication
- Logs into Docker Hub using secrets
- Uses
docker/login-action@v3
-
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 ActionsDOCKERHUB_USERNAME
: Docker Hub username for image publishingDOCKERHUB_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
-
Build Failures
- Check Node.js version compatibility
- Verify all dependencies are properly installed
- Review build logs for specific error messages
-
Deployment Failures
- Verify GitHub Pages is enabled for the repository
- Check GitHub token permissions
- Ensure build directory exists and contains files
-
Docker Build Issues
- Verify Docker Hub credentials
- Check Dockerfile syntax
- Ensure Docker context is correct
Debugging Steps
-
Local Testing
# Test build locally
yarn install
yarn build
# Test Docker build
docker build -t rahat-docs:test . -
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):
- Create a new workflow file in
.github/workflows/
- Configure branch triggers
- Set up environment-specific secrets
- Configure deployment targets
Modifying Build Process
To modify the build process:
- Update
package.json
scripts - Modify workflow steps in YAML files
- Test changes in development branch first
- Update documentation accordingly