Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:24-alpine
FROM node:22-alpine

# Create app user and group
RUN addgroup app && adduser -S -G app app
Expand All @@ -15,5 +15,5 @@ COPY . .
# Switch to non-root user for runtime
USER app

EXPOSE 3000
EXPOSE 8000
CMD ["node", "app.js"]
58 changes: 58 additions & 0 deletions Jenkins
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
pipeline {
agent any

environment {
IMAGE_NAME = "sample-node-app"
CONTAINER_NAME = "node-app-container"
PORT = "8000"
}

stages {

stage('Clone Repository') {
steps {
git branch: 'dev',
url: 'https://github.com/Jaygohel164/sample-node-project.git'
}
}

stage('Build Docker Image') {
steps {
sh "docker build -t ${IMAGE_NAME}:latest ."
}
}

stage('Stop Old Container') {
steps {
sh "docker stop ${CONTAINER_NAME} || true"
sh "docker rm ${CONTAINER_NAME} || true"
}
}

stage('Run Docker Container') {
steps {
sh """
docker run -d \
--name ${CONTAINER_NAME} \
-p ${PORT}:${PORT} \
${IMAGE_NAME}:latest
"""
}
}

stage('Verify') {
steps {
sh "docker ps | grep ${CONTAINER_NAME}"
}
}
}

post {
success {
echo "App running at http://3.109.202.16:8000"
}
failure {
sh "docker logs ${CONTAINER_NAME} || true"
}
}
}
2 changes: 1 addition & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const express = require('express');

const app = express();

app.set('port', process.env.PORT || 3000); // Application port is set
app.set('port', process.env.PORT || 8000); // Application port is set
app.set('views', __dirname + '/app/server/views'); // Views folder is set
app.set('view engine', 'ejs'); // View engine is set
app.use(express.static(__dirname + '/app/public')); // Public folder containing static files is set
Expand Down
4 changes: 2 additions & 2 deletions app/server/views/index.ejs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<html lang="en">
<head>
<link rel="stylesheet" href="styles/styles.css" />
<title>Sample Node.js Application</title>
<title>Sample Node.js Application by Jay Gohel</title>
</head>
<body>
<span>Sample Node.js Application</span>
<span>Sample Node.js Application by Jay Gohel</span>
</body>
</html>
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ services:
context: .
dockerfile: Dockerfile
ports:
- "3000:3000"
- "8000:8000"