Skip to content

Latest commit

 

History

History
117 lines (89 loc) · 5.46 KB

File metadata and controls

117 lines (89 loc) · 5.46 KB

Standard Jenkins CI/CD Pipeline with Telegram Notifications

This plan outlines the implementation of a standard, production-ready CI/CD pipeline using Jenkins for a multi-service web application. The application stack consists of:

  • Frontend: Vite + React (TypeScript)
  • Backend: Node.js + Express (connecting to MongoDB and PostgreSQL)
  • Database: MongoDB & PostgreSQL
  • Orchestration & Deploy: Docker & Docker Compose
  • Notifications: Telegram Bot API integration for pipeline status alerts.

User Review Required

Please review the proposed structure and flow of the pipeline. In particular, check:

  1. Telegram Credentials: The Jenkins environment will require two credentials/variables configured:
    • TELEGRAM_BOT_TOKEN: The bot token obtained from BotFather.
    • TELEGRAM_CHAT_ID: The target group chat or user ID to receive notifications.
  2. Docker Registry: If you want to push built images to a remote registry (like Docker Hub, AWS ECR, or GitLab Registry), you will need to add credentials in Jenkins (e.g. docker-registry-credentials). For this local/template setup, we will configure docker build and deployment using local images or placeholders for pushing.
  3. Deployment Strategy: We will implement a Docker Compose-based deployment stage. This is standard for single-node setups. If Kubernetes or SSH deployment to another server is desired, we can extend it later.

Proposed Changes

We will create a full repository layout since the workspace is currently empty. This will provide a fully functional template that compiles, tests, builds Docker images, and deploys, while notifying a Telegram chat.

Project Structure

/home/namnk/ws/jenkins/
├── backend/
│   ├── src/
│   │   ├── config/       # DB configurations (Mongo/Postgres)
│   │   └── index.js      # Express server entrypoint
│   ├── Dockerfile
│   ├── package.json
│   └── README.md
├── frontend/
│   ├── src/
│   │   ├── App.tsx       # Main page showing DB connection statuses
│   │   └── main.tsx
│   ├── Dockerfile
│   ├── package.json
│   └── README.md
├── jenkins/
│   └── scripts/
│       └── telegram-notify.sh  # Script for Telegram notifications
├── docker-compose.yml          # Local environment & production orchestrator
├── docker-compose.jenkins.yml  # Deployment template for Jenkins Pipeline
├── Jenkinsfile                 # Jenkins Declarative Pipeline
└── README.md

[Component: Frontend]

We will create a simple, clean, and responsive Vite application that displays connection statuses to the backend services.

[NEW] frontend/package.json

Vite, React, TypeScript, and dependencies.

[NEW] frontend/Dockerfile

Multi-stage Dockerfile:

  • Stage 1: Build static assets using Node.
  • Stage 2: Serve using Nginx (lightweight, production-grade).

[Component: Backend]

We will create a Node.js Express application that connects to MongoDB and PostgreSQL and exposes health-check endpoints.

[NEW] backend/package.json

Express, Mongoose (MongoDB), pg (PostgreSQL), dotenv, and cors.

[NEW] backend/Dockerfile

Optimized Node.js runtime Dockerfile (using Node Alpine, clean dependencies, and proper environment injection).

[NEW] backend/src/index.js

Server setup, MongoDB connection, PostgreSQL connection, and simple API endpoints.


[Component: Docker Orchestration]

Docker Compose templates for local environment and production deployment.

[NEW] docker-compose.yml

Runs frontend, backend, mongodb, and postgresql locally.


[Component: Jenkins CI/CD Pipeline]

The core pipeline configuration.

[NEW] Jenkinsfile

Declarative pipeline with stages:

  1. Initialize & Lint: Check dependencies and style guidelines.
  2. Test: Run unit/integration tests for frontend and backend.
  3. Docker Build: Build Docker images for frontend and backend services.
  4. Deploy: Restart services using docker-compose.jenkins.yml.
  5. Post Actions (Always/Success/Failure): Trigger the Telegram notification script passing build status, duration, commit author, and messages.

[NEW] jenkins/scripts/telegram-notify.sh

Bash script using curl to send formatted HTML messages to Telegram.

  • Renders emoji badges: ✅ Success, ❌ Failure, ⚠️ Aborted.
  • Includes git commit hash, author, commit message, pipeline duration, and build number linking to Jenkins UI.

Verification Plan

Automated Verification

  • We will lint and run build checks in both the frontend and backend directories.
  • We will test the Telegram notification script locally (mocking token/chat ID or using a test token if provided).

Manual Verification

  • Verify the docker build completes successfully for both frontend and backend.
  • Verify docker-compose starts up and connects frontend to backend, and backend to databases (MongoDB and PostgreSQL).
  • Validate the generated Jenkinsfile structure via a Jenkins linter check (if available) or syntax checking.