Skip to content

PAIshanMadusha/node-docker-jenkins-cicd-pipeline

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

22 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Node.js icon

Node.js CRUD API with Docker & Jenkins CI/CD

BUILT WITH NODE.JS & EXPRESS, WITH NEON POSTGRESQL DATABASE

Β Β  Β Β 

CONTAINERIZED WITH DOCKER & AUTOMATED CI/CD PIPELINE WITH JENKINS, EASILY DEPLOYABLE ANYWHERE

Β Β  Β Β 


A full-featured Node.js CRUD API built with Express and PostgreSQL (Neon), which provides seamless Docker-based deployment. The CI/CD pipeline handles automated builds, tests, Docker image creation, and pushes to Docker Hub, making it easily deployable on any platform that supports Docker. Ideal for developers looking for a ready-to-use backend API with robust development, testing, and deployment workflows.

πŸ“ Table of Contents


✨ Features

  • πŸ”„ Full CRUD API for user management
  • 🐘 PostgreSQL database integration (Neon)
  • πŸ“¦ Dockerized for easy deployment
  • βš™οΈ Jenkins for CI/CD pipeline
  • πŸ” Environment variable support with .env or Jenkins Secret Files
  • πŸ§ͺ Automated testing with Jest and Supertest

Pipeline Overview
Pipeline Overview

πŸ›  Tech Stack

The following technologies are used in this project:

  • Backend: Node.js, Express, Joi, CORS, dotenv
  • Database: PostgreSQL (Neon), @neondatabase/serverless
  • Testing: Jest, Supertest
  • Development Tools: Nodemon
  • Containerization: Docker
  • CI/CD: Jenkins
  • Version Control: Git, GitHub

🧠 Getting Started

Follow the steps below to set up and run the project successfully:

1. βœ… Clone the Repository:

https://github.com/PAIshanMadusha/node-docker-jenkins-cicd-pipeline.git

2. βœ… Navigate to the Project Directory:

cd node-docker-jenkins-cicd-pipeline

3. βœ… Install dependencies:

npm install

4. βœ… Create a .env file in the root directory with your database credentials:

Go to Neon and sign in or create an account. Create a new project and copy your ** πŸ” database connection details** from the dashboard.
PORT=3000
PGUSER=your_db_user
PGPASSWORD=your_db_password
PGHOST=your_db_host
PGDATABASE=your_db_name

πŸ›‘ Environment Variables

Information About Environment Variables

Variable Description
PORT Port number for API server
PGUSER PostgreSQL username
PGPASSWORD PostgreSQL password
PGHOST PostgreSQL host URL
PGDATABASE PostgreSQL database name

5. βœ… Running the Application

Run this command in the root directory:
npm run dev
If everything is configured properly, your terminal will show:
Server is running on port: 3000
User Table Created If Not Exists!

πŸ§ͺ Running Tests

Run the following command in the root directory:

npm test

⚑ API Endpoints

Replace :id with the actual user ID. Test endpoints using Postman, Insomnia, or any API client at http://localhost:3000.

Method Endpoint Description
GET /api/users Retrieve all users
GET /api/users/:id Retrieve a user by ID
POST /api/users Create a new user
PUT /api/users/:id Update an existing user
DELETE /api/users/:id Delete a user

🐳 Docker

This project is fully containerized. You can run it directly from Docker Hub without building locally, and Make sure you have Docker Desktop (or Docker Engine) running on your system.
Docker Image: ishanmadusha/node-docker-jenkins-cicd-pipeline:latest

πŸ“₯ Pull the latest image:

docker pull ishanmadusha/node-docker-jenkins-cicd-pipeline:latest

▢️ Run the container with environment variables:

docker run -d --name node-crud-app --env-file .env -p 3000:3000 ishanmadusha/node-docker-jenkins-cicd-pipeline:latest

🌐 Test the App: Visit: http://localhost:3000


βš™ CI/CD Pipeline

This project includes a fully automated CI/CD pipeline defined in the Jenkinsfile for a Node.js application using Docker on Windows. The pipeline handles building, testing, Docker image creation, pushing to Docker Hub, and deploying the container.

Install or open Jenkins and try building your own pipeline on your machine.
You can adapt this pipeline for other projects by replacing the GitHub repository URL and Docker Hub credentials in the Jenkinsfile.

▢️ Pipeline Stages:

1. Checkout Source: Pulls the latest code from your GitHub repository.
2. Install Dependencies: Installs all project dependencies using npm install.
3. Run Tests: Runs automated tests to ensure the project is working correctly without breaking existing functionality.
4. Build Docker Image: Builds a Docker image for the application. Replace the Docker Hub username in the Jenkinsfile with your own credentials.
5. Login to Docker Hub: Logs in securely to Docker Hub using stored Jenkins credentials.
6. Push Docker Image: Pushes the built Docker image to your Docker Hub repository, including a latest tag for convenience.
7. Deploy the Container: Deploys the Docker container using the pushed image. The container runs with environment variables stored securely

▢️ Secret Management:

The .env file is stored in Jenkins as a Secret File (nodeapp-env-file) for secure access.
Docker Hub credentials are stored securely in Jenkins Credentials.

πŸ‘¨β€πŸ’» Created by:

Ishan Madhusha
GitHub: PAIshanMadusha

Feel free to explore my work and get in touch if you'd like to collaborate! πŸš€


πŸ“ License

This project is licensed under the MIT License : See the LICENSE file for details.

About

A Node.js CRUD API with PostgreSQL database integration, containerized using Docker, and automated with a Jenkins CI/CD pipeline.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors