Skip to content

A Dockerized Node.js API with Nginx, Ansible for deployment, and GitHub Actions for CI/CD

Notifications You must be signed in to change notification settings

dev-opus/node-api-cicd-pipeline

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Subnet Calculator

This project is a Subnet Calculator application that provides a REST API for calculating subnet details for IPv4 addresses. It includes a Node.js backend, an Nginx reverse proxy, and deployment automation using Ansible.

Features

  • Calculate subnet details for IPv4 addresses.
  • REST API built with Hono and Zod for schema validation.
  • Reverse proxy setup using Nginx.
  • Deployment automation with Ansible.
  • Dockerized environment for easy deployment.

Node.js API

The Node.js backend provides a REST API for calculating subnet details for IPv4 addresses.

Features

  • Built with Hono for lightweight and fast API development.
  • Schema validation using Zod.
  • Comprehensive logging with Winston.
  • API documentation using OpenAPI, implemented with the @hono/zod-openapi library for schema definitions and @scalar/hono-api-reference for serving the documentation.

Setup

  1. Install dependencies:
    npm install
  2. Run the development server:
    npm run dev
  3. Build the project:
    npm run build
  4. Run tests:
    npm test

API Endpoints

  • POST /api/calculate: Calculate subnet details for a given IPv4 CIDR address.
  • GET /docs: Access the API documentation.

Nginx Reverse Proxy

The Nginx reverse proxy is used for load balancing and forwarding client information.

Features

  • Load balancing between multiple Node.js API instances.
  • Proxy headers for forwarding client information.

Setup

  1. Build the Nginx Docker image:
    docker build -t webserver .
  2. Run the container:
    docker run -p 80:80 webserver

Configuration

  • nginx.conf: Main configuration file for the Nginx server.

Ansible Deployment

Ansible playbooks and roles are used for deploying the Subnet Calculator application.

Features

  • Setup Docker and required dependencies on the target server.
  • Deploy Node.js API and Nginx reverse proxy using Docker Compose.

Setup

  1. Install Ansible:
    pip install ansible
  2. Run the setup playbook to configure the server:
    ansible-playbook -i inventory.ini setup.yaml
  3. Deploy the application:
    ansible-playbook -i inventory.ini deploy.yaml
  4. Alternatively, you can use the main.yaml file to both set up and deploy the application in a single step:
    ansible-playbook -i inventory.ini main.yaml

Directory Structure

  • roles/setup: Configures the server with Docker and required users.
  • roles/deploy: Deploys the application using Docker Compose.

Docker

The project is fully containerized using Docker. Use the compose.yaml file to set up and run the entire application stack with Docker Compose.

About

A Dockerized Node.js API with Nginx, Ansible for deployment, and GitHub Actions for CI/CD

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published