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
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
ARG ARCH=
ARG IMAGE_BASE=16-alpine

FROM node:18-alpine

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install --production

COPY . .

EXPOSE 3000

CMD ["npm", "start"]



61 changes: 61 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
pipeline {
agent any

environment {
DOCKER_IMAGE = "amulya2503/node1"
DOCKER_CREDENTIALS = "Docker"
}

stages {
stage('Checkout') {
steps {
git branch: 'master',
url: 'https://github.com/sreepathysois/node-hello_Lab_Exam_Batch_2.git'
}
}

stage('Install Dependencies') {
steps {
sh 'npm install'
}
}

stage('Run Tests') {
steps {
sh 'npm test || echo "No tests found, skipping..."'
}
}

stage('Build Docker Image') {
steps {
script {
sh "docker build -t ${DOCKER_IMAGE}:${BUILD_NUMBER} ."
}
}
}

stage('Push to Docker Hub') {
steps {
script {
withCredentials([usernamePassword(credentialsId: "${DOCKER_CREDENTIALS}", usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]) {
sh """
echo "$DOCKER_PASS" | docker login -u "$DOCKER_USER" --password-stdin
docker push ${DOCKER_IMAGE}:${BUILD_NUMBER}
docker tag ${DOCKER_IMAGE}:${BUILD_NUMBER} ${DOCKER_IMAGE}:latest
docker push ${DOCKER_IMAGE}:latest
"""
}
}
}
}
}

post {
success {
echo "✅ Build & push successful: ${DOCKER_IMAGE}:${BUILD_NUMBER}"
}
failure {
echo "❌ Build failed!"
}
}
}