A simple, custom CI/CD server built with Node.js, Express, and TypeScript. It listens for GitHub webhooks to automatically pull, build, and deploy your projects, and sends status notifications via Telegram.
- 🚀 Automated Deployment: Triggers on GitHub repository events (e.g.,
push). - 🔐 Secure: Validates GitHub webhook signatures using HMAC SHA256.
- 📱 Telegram Notifications: Sends deployment success or failure logs to a Telegram chat.
- 🛠 Configurable: Support for multiple projects with custom build and start commands.
- Node.js (v16 or higher recommended)
- npm or yarn
- A publicly accessible URL (use ngrok for development)
-
Clone the repository:
git clone https://github.com/thedhruvish/ci-cd-server.git cd ci-cd-server -
Install dependencies:
npm install
The configuration is managed in src/config.ts.
Set up your Telegram bot details to receive notifications.
// src/config.ts
export const TG_CONFIG = {
TG_BOT_TOKEN: "YOUR_TELEGRAM_BOT_TOKEN", // Get from @BotFather
TG_CHAT_ID: "YOUR_CHAT_ID", // Get via /id command or bot API
};Add your projects to the CI_CD_CONFIG array.
// src/config.ts
export const CI_CD_CONFIG: ICICDProject[] = [
{
projectName: "My Awesome Project",
repoUrl: "https://github.com/username/repo", // Repository URL
event: "push", // Event to trigger deploy
secret: "YourWebhookSecret", // Must match GitHub Webhook Secret
branch: "main", // Branch to deploy
projectRoot: "/absolute/path/to/project", // Local path where the project is located
Buildcommand: ["npm install", "npm run build"], // Array of commands to build
Startcommand: "pm2 reload app", // Command to restart/start the app
},
];Run the server with hot-reloading:
npm run devBuild and start the server:
npm run build
npm startThe server will start on port 3000 by default.
- Go to your repository on GitHub.
- Navigate to Settings > Webhooks > Add webhook.
- Payload URL:
http://<your-server-ip-or-domain>:3000/deploy- If developing locally, use your ngrok URL:
https://<your-ngrok-id>.ngrok-free.app/deploy
- If developing locally, use your ngrok URL:
- Content type:
application/json - Secret: Enter the same secret you put in
src/config.ts(e.g.,Myprojects123). - Which events would you like to trigger this webhook?: Select "Just the push event" (or match your config).
- Click Add webhook.
If you are setting this up on a fresh VPS (like DigitalOcean, AWS EC2, or Hetzner):
-
Install Node.js & npm:
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - sudo apt-get install -y nodejs -
Install PM2 (Process Manager): PM2 keeps your server running in the background and restarts it on crashes.
sudo npm install -g pm2
-
Setup the CI/CD Server:
cd /path/to/ci-cd-server npm install npm run build pm2 start dist/index.js --name "ci-cd-server" pm2 save
-
Setup Your Target Projects: Ensure the
projectRootdirectories defined in config exist and are git initialized.# Example for a target project cd /home/user/projects git clone https://github.com/username/target-repo.git
-
Security Note:
- Ensure your firewall allows traffic on port
3000(or use Nginx as a reverse proxy). - Keep your secret keys safe.
- Ensure your firewall allows traffic on port