This project is a Node.js backend API for a blog application with authentication and CRUD operations for blog posts. The project includes a comprehensive DevOps pipeline for CI/CD, containerization, and deployment to an Azure server.
- Node.js backend API
- User authentication
- CRUD operations for blog posts
- CI/CD pipeline using GitHub Actions
- Docker containerization
- Deployment to Azure server
- Infrastructure as Code with Terraform
- Monitoring with Prometheus and Grafana
- Node.js and npm
- Docker
- Azure account
- GitHub repository with the following secrets:
DOCKER_USERNAME
DOCKER_PASSWORD
SYNK_TOKEN
-
Clone the repository:
git clone https://github.com/Nmesoma01/summative-DevOps-for-Fullstack.git cd summative-DevOps-for-Fullstack
-
Apply Terraform configuration:
terraform apply
The deployment to the Azure server is handled through the GitHub Actions workflow. Ensure that the necessary secrets are added to your GitHub repository.
The deployment steps are:
- SSH into the Azure server
- Install Docker (if not already installed)
- Pull the latest Docker image
- Stop and remove any existing Docker containers
- Run the new Docker container
The GitHub Actions workflow for this project automates the following tasks:
- Checking out the code
- Setting up Node.js
- Installing dependencies
- Running code linting
- Running tests
- Authenticating Snyk for security scanning
- Building the Docker image
- Logging in to Docker Hub
- Pushing the Docker image to Docker Hub
Here is the GitHub Actions workflow configuration:
name: CI
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '18'
- name: Install dependencies
run: npm install
- name: Install Snyk CLI
run: npm install -g snyk
- name: Lint code
run: npm run lint
- name: Run tests
run: npm test
- name: Authenticate Snyk
run: snyk auth ${{ secrets.SYNK_TOKEN }}
- name: Run security scan
run: npm run security
- name: Build Docker image
run: docker build -t nmesoma01/nodejs-blogging-api .
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Push Docker image
run: docker push nmesoma01/nodejs-blogging-api
We use Prometheus to track application performance and health metrics. The metrics are exposed at the /metrics
endpoint.
- Prometheus: Make sure you configure Prometheus to scrape the
/metrics
endpoint of your application.
- Install Prometheus and Grafana on your server.
- Configure Prometheus to scrape your application’s metrics endpoint.
- Integrate Grafana with Prometheus to visualize the metrics.
Nmesoma - GitHub Profile