Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
41624c1
Create jenkins
MANIKANDAN242221 Jul 15, 2025
a727361
Update jenkins
MANIKANDAN242221 Jul 15, 2025
e5cbcff
Update Dockerfile
MANIKANDAN242221 Aug 8, 2025
0ca8c2d
Update jenkins
MANIKANDAN242221 Aug 8, 2025
43185cc
Update Dockerfile
MANIKANDAN242221 Aug 8, 2025
fea017a
Update index.js
MANIKANDAN242221 Aug 8, 2025
c21635e
Create docker-compose.yml
MANIKANDAN242221 Aug 8, 2025
86e0961
Update jenkins
MANIKANDAN242221 Aug 8, 2025
d0046e5
Update docker-compose.yml
MANIKANDAN242221 Aug 8, 2025
a2a14a9
Update docker-compose.yml
MANIKANDAN242221 Aug 8, 2025
84f993d
Update index.js
MANIKANDAN242221 Aug 8, 2025
35acf22
Update jenkins
MANIKANDAN242221 Aug 8, 2025
382ffa3
Update package.json
MANIKANDAN242221 Aug 8, 2025
71b2d9f
Update docker-compose.yml
MANIKANDAN242221 Aug 8, 2025
55cdaaf
Update jenkins
MANIKANDAN242221 Aug 8, 2025
4e256eb
Update jenkins
MANIKANDAN242221 Aug 8, 2025
85601c9
Update docker-compose.yml
MANIKANDAN242221 Aug 8, 2025
c6f667e
Update jenkins
MANIKANDAN242221 Aug 8, 2025
02907cd
Update docker-compose.yml
MANIKANDAN242221 Aug 9, 2025
62efa99
Update README.md
MANIKANDAN242221 Aug 9, 2025
d6d6f82
Update deployment.yaml
MANIKANDAN242221 Aug 9, 2025
f12b0f6
Update jenkins
MANIKANDAN242221 Aug 9, 2025
b56bd55
Update docker-compose.yml
MANIKANDAN242221 Aug 11, 2025
612c78d
Update Dockerfile
MANIKANDAN242221 Aug 11, 2025
b9ce7da
Update jenkins
MANIKANDAN242221 Aug 11, 2025
4017c72
Update package.json
MANIKANDAN242221 Aug 11, 2025
6b35cf2
Update Dockerfile
MANIKANDAN242221 Aug 11, 2025
8731931
Update index.js
MANIKANDAN242221 Aug 11, 2025
5ec423b
Update index.js
MANIKANDAN242221 Aug 11, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
FROM node:6.10.3
FROM node:18-alpine

# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

# Install app dependencies
COPY package.json /usr/src/app/
# Copy package.json and package-lock.json first for caching
COPY package*.json ./

# Install dependencies (including dev if you need nodemon in container)
RUN npm install

# Bundle app source
COPY . /usr/src/app
# Copy application source code
COPY . .

# Expose the application port
EXPOSE 9000
CMD [ "npm", "start" ]
#helo

# Start the app
CMD ["npm", "start"]
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@


hello
Jenkins
14 changes: 14 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: '3.8'

services:
app:
build:
context: .
dockerfile: Dockerfile
image: sample-node-app:latest
container_name: sample-node-app
ports:
- "9000:9000"
env_file:
- .env
restart: unless-stopped
14 changes: 10 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
const express = require('express');
require('dotenv').config(); // 👈 Load env variables

const app = express();
const port = 9000;
const port = process.env.PORT || 9000;
const message = process.env.CUSTOM_MESSAGE || 'Hello World!';

app.get('/', (req, res) => {
res.send('<h1>Hello World from Docker and Node.js!</h1>');
res.send(`<h1>${message}</h1>`);
});
app.listen(port, () => {
console.log(`Listening on port ${port}`);

app.listen(port, '0.0.0.0', () => {
console.log(`🚀 Server running on port ${port}`);
});

117 changes: 117 additions & 0 deletions jenkins
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
pipeline {
agent none

environment {
AWS_ACCOUNT_ID = '951042686423'
AWS_REGION = 'ap-south-1'
REPO_NAME = 'sample-node-app'
IMAGE_TAG = 'latest'
ECR_REGISTRY = "${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com"
IMAGE_URI = "${ECR_REGISTRY}/${REPO_NAME}:${IMAGE_TAG}"
GIT_REPO = 'https://github.com/MANIKANDAN242221/sample-node-app.git'
AWS_CREDENTIALS_ID = 'aws-jenkins-creds'
}

stages {
stage('Clone Repository') {
agent { label 'master' }
steps {
git url: "${GIT_REPO}", branch: 'main'
}
}

stage('Ensure .env File') {
agent { label 'master' }
steps {
sh '''
echo "PORT=9000" > .env
echo "NODE_ENV=production" >> .env
echo "CUSTOM_MESSAGE=Hello from Jenkins pipeline" >> .env
'''
}
}

stage('Install Dependencies & Build UI') {
agent { label 'master' }
steps {
sh '''
echo "📦 Installing Node.js dependencies..."
npm install

echo "🏗️ Building frontend..."
npm run build
'''
}
}

stage('Build Docker Image') {
agent { label 'master' }
steps {
sh '''
echo "🗑️ Removing old Docker image..."
docker rmi -f ${REPO_NAME}:latest || true

echo "🐳 Building new Docker image..."
docker-compose build --no-cache
'''
}
}

stage('Tag Image for ECR') {
agent { label 'master' }
steps {
sh "docker tag ${REPO_NAME}:latest ${IMAGE_URI}"
}
}

stage('Login to ECR') {
agent { label 'master' }
steps {
withCredentials([
usernamePassword(
credentialsId: "${AWS_CREDENTIALS_ID}",
usernameVariable: 'AWS_ACCESS_KEY_ID',
passwordVariable: 'AWS_SECRET_ACCESS_KEY'
)
]) {
sh '''
aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID
aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY
aws configure set default.region ${AWS_REGION}
aws ecr get-login-password --region ${AWS_REGION} \
| docker login --username AWS --password-stdin ${ECR_REGISTRY}
'''
}
}
}

stage('Push Image to ECR') {
agent { label 'master' }
steps {
sh "docker push ${IMAGE_URI}"
}
}

stage('Deploy Container on Agent') {
agent { label 'agent' }
steps {
sh '''
docker-compose down || true
docker-compose up -d
'''
}
}
}

post {
always {
echo '🧹 Cleaning up...'
}
success {
echo '✅ Pipeline executed successfully!'
}
failure {
echo '❌ Pipeline failed!'
}
}
}
2 changes: 1 addition & 1 deletion node-app/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ spec:
spec:
containers:
- name: node-app
image: arunmagi/node-app
image: techdocker24/node-app
ports:
- containerPort: 9000
---
Expand Down
16 changes: 12 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
{
"name": "docker-node-example",
"version": "1.0.0",
"description": "Sample Node.js Express app for Docker & Jenkins",
"main": "index.js",
"scripts": {
"start": "nodemon index.js"
"start": "node index.js",
"dev": "nodemon index.js",
"build": "echo 'No build step needed for backend API'"
},
"dependencies": {
"express": "^4.15.3",
"nodemon": "^1.11.0"
}
"express": "^4.18.2",
"dotenv": "^16.0.0"
},
"devDependencies": {
"nodemon": "^3.0.2"
},
"author": "",
"license": "ISC"
}