From aa0cb1af572612f30676ee6eb0d87441c8c7c07a Mon Sep 17 00:00:00 2001 From: Hitesh Pankhania <225935890+tauruschinatown@users.noreply.github.com> Date: Mon, 29 Sep 2025 05:05:54 +0000 Subject: [PATCH 1/4] Add Jenkinsfile (npm audit high, docker build/push) and app Dockerfile --- Dockerfile | 7 +++++++ Jenkinsfile | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 Dockerfile create mode 100644 Jenkinsfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..46bc635b0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM node:16-alpine +WORKDIR /app +COPY package*.json ./ +RUN npm ci --only=production +COPY . . +EXPOSE 8081 +CMD ["node", "app.js"] diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 000000000..9ddc0dfdc --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,52 @@ +pipeline { + agent any + options { + timestamps() + buildDiscarder(logRotator(numToKeepStr: '15', artifactNumToKeepStr: '10')) + } + environment { + IMAGE_NAME = "/eb-express" + IMAGE_TAG = "${env.BRANCH_NAME}-${env.BUILD_NUMBER}" + } + stages { + stage('Checkout') { + steps { checkout scm } + } + + stage('Install & Test (Node 16)') { + agent { docker { image 'node:16-alpine' args '-v $HOME/.npm:/root/.npm' } } + steps { + sh 'node -v && npm -v' + sh 'npm ci' + sh 'npm test || echo "no tests"' + } + } + + stage('Dependency Scan (fail on HIGH)') { + agent { docker { image 'node:16-alpine' } } + steps { + sh 'npm ci --prefer-offline --no-audit' + sh 'npm audit --audit-level=high' + } + } + + stage('Build Image') { + steps { + sh 'docker build -t $IMAGE_NAME:$IMAGE_TAG .' + } + } + + stage('Login & Push') { + steps { + withCredentials([usernamePassword(credentialsId: 'dockerhub-creds', usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]) { + sh 'echo "$DOCKER_PASS" | docker login -u "$DOCKER_USER" --password-stdin' + } + sh 'docker push $IMAGE_NAME:$IMAGE_TAG' + } + } + } + post { + success { echo "Pushed $IMAGE_NAME:$IMAGE_TAG" } + always { archiveArtifacts artifacts: '**/npm-debug.log', allowEmptyArchive: true } + } +} From fbe74fbd75261cb199cd22bfb85549343112b123 Mon Sep 17 00:00:00 2001 From: Hitesh Pankhania <225935890+tauruschinatown@users.noreply.github.com> Date: Mon, 29 Sep 2025 05:30:09 +0000 Subject: [PATCH 2/4] Set IMAGE_NAME to my Docker Hub repo --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 9ddc0dfdc..56265d681 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -5,7 +5,7 @@ pipeline { buildDiscarder(logRotator(numToKeepStr: '15', artifactNumToKeepStr: '10')) } environment { - IMAGE_NAME = "/eb-express" + IMAGE_NAME = "/eb-express" IMAGE_TAG = "${env.BRANCH_NAME}-${env.BUILD_NUMBER}" } stages { From 91a943d69ee4e65e374677e2cb22c9550cf5c801 Mon Sep 17 00:00:00 2001 From: Hitesh Pankhania <22471264@student.curtin.edu.au> Date: Mon, 29 Sep 2025 14:16:04 +0800 Subject: [PATCH 3/4] Update Jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 56265d681..359257b12 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -5,7 +5,7 @@ pipeline { buildDiscarder(logRotator(numToKeepStr: '15', artifactNumToKeepStr: '10')) } environment { - IMAGE_NAME = "/eb-express" + IMAGE_NAME = "22471264/eb-express" IMAGE_TAG = "${env.BRANCH_NAME}-${env.BUILD_NUMBER}" } stages { From 75ad6045de057a54326b045fd22a45c9312e4c8c Mon Sep 17 00:00:00 2001 From: Hitesh Pankhania <225935890+tauruschinatown@users.noreply.github.com> Date: Mon, 29 Sep 2025 06:40:29 +0000 Subject: [PATCH 4/4] Fix Jenkinsfile docker agent syntax --- Jenkinsfile | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 359257b12..d16746222 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -5,7 +5,7 @@ pipeline { buildDiscarder(logRotator(numToKeepStr: '15', artifactNumToKeepStr: '10')) } environment { - IMAGE_NAME = "22471264/eb-express" + IMAGE_NAME = "22471264/eb-express" IMAGE_TAG = "${env.BRANCH_NAME}-${env.BUILD_NUMBER}" } stages { @@ -14,7 +14,12 @@ pipeline { } stage('Install & Test (Node 16)') { - agent { docker { image 'node:16-alpine' args '-v $HOME/.npm:/root/.npm' } } + agent { + docker { + image 'node:16-alpine' + args '-v $HOME/.npm:/root/.npm' + } + } steps { sh 'node -v && npm -v' sh 'npm ci' @@ -23,7 +28,11 @@ pipeline { } stage('Dependency Scan (fail on HIGH)') { - agent { docker { image 'node:16-alpine' } } + agent { + docker { + image 'node:16-alpine' + } + } steps { sh 'npm ci --prefer-offline --no-audit' sh 'npm audit --audit-level=high'