From 31eb97bd6937d04357a5536942f4701d8ed8f365 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 29 Sep 2025 22:41:36 +0800 Subject: [PATCH 1/7] Test CI/CD pipeline before final submission --- Dockerfile | 20 ++++++++++++++++++++ Jenkinsfile | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 Dockerfile create mode 100644 Jenkinsfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..e80281672 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +# Use Node 16 as the base image +FROM node:16 + +# Set the working directory +WORKDIR /app + +# Copy package.json and package-lock.json +COPY package*.json ./ + +# Install dependencies +RUN npm install --save + +# Copy the rest of the application code +COPY . . + +# Expose the app port +EXPOSE 3000 + +# Start the application +CMD ["npm", "start"] diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 000000000..ca3a31fc5 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,49 @@ +pipeline { + agent { + // Use Node 16 Docker image as the build agent + docker { image 'node:16' } + } + + environment { + // Set the Docker image name and tag + IMAGE_NAME = 'chiamintwts/assignment2_22165266:latest' + } + + stages { + stage('Install Dependencies') { + steps { + // Install Node.js dependencies + sh 'npm install' + } + } + stage('Run Unit Tests') { + steps { + // Run your test suite + sh 'npm test' + } + } + stage('Security Scan') { + steps { + // Install Snyk CLI and run a scan + sh 'npm install -g snyk' + // Pipeline fails if any high severity issues are found + sh 'snyk test --severity-threshold=high' + } + } + stage('Build Docker Image') { + steps { + // Build the Docker image for the app + sh 'docker build -t $IMAGE_NAME .' + } + } + stage('Push Docker Image') { + steps { + // Login to Docker Hub and push the image + withCredentials([usernamePassword(credentialsId: 'dockerhub-creds', usernameVariable: 'DOCKERHUB_USER', passwordVariable: 'DOCKERHUB_PASS')]) { + sh 'echo $DOCKERHUB_PASS | docker login -u $DOCKERHUB_USER --password-stdin' + sh 'docker push $IMAGE_NAME' + } + } + } + } +} \ No newline at end of file From 55f60f2fc4bb498d94bd72bc055fd4fdf3e230c0 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 29 Sep 2025 23:37:20 +0800 Subject: [PATCH 2/7] Add Jenkinsfile for automated CI/CD pipeline with securtiy scan --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index ca3a31fc5..3770e68d7 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -39,7 +39,7 @@ pipeline { stage('Push Docker Image') { steps { // Login to Docker Hub and push the image - withCredentials([usernamePassword(credentialsId: 'dockerhub-creds', usernameVariable: 'DOCKERHUB_USER', passwordVariable: 'DOCKERHUB_PASS')]) { + withCredentials([usernamePassword(credentialsId: 'dockerhub-credentials', usernameVariable: 'DOCKERHUB_USER', passwordVariable: 'DOCKERHUB_PASS')]) { sh 'echo $DOCKERHUB_PASS | docker login -u $DOCKERHUB_USER --password-stdin' sh 'docker push $IMAGE_NAME' } From 104571cdd0e6ca0de3b0f1bbc10f4b185c341a2e Mon Sep 17 00:00:00 2001 From: root Date: Tue, 30 Sep 2025 18:23:25 +0800 Subject: [PATCH 3/7] Create-Jenkinsfile --- Jenkinsfile | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 000000000..818eef286 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,49 @@ +pipeline { + agent { + // Use Node 16 Docker image as the build agent + docker { image 'node:16' } + } + + environment { + // Set the Docker image name/tag + IMAGE_NAME = 'chiamintwts/assignment2_22165266:latest' + } + + stages { + stage('Install Dependencies') { + steps { + // Install Node.js dependencies + sh 'npm install' + } + } + stage('Run Unit Tests') { + steps { + // Run your test suite + sh 'npm test' + } + } + stage('Security Scan') { + steps { + // Install Snyk CLI and run a scan + sh 'npm install -g snyk' + // Pipeline fails if any high severity issues are found + sh 'snyk test --severity-threshold=high' + } + } + stage('Build Docker Image') { + steps { + // Build the Docker image for the app + sh 'docker build -t $IMAGE_NAME .' + } + } + stage('Push Docker Image') { + steps { + // Login to Docker Hub and push the image + withCredentials([usernamePassword(credentialsId: 'dockerhub-credentials', usernameVariable: 'DOCKERHUB_USER', passwordVariable: 'DOCKERHUB_PASS')]) { + sh 'echo $DOCKERHUB_PASS | docker login -u $DOCKERHUB_USER --password-stdin' + sh 'docker push $IMAGE_NAME' + } + } + } + } +} \ No newline at end of file From 61eae0952a150fcbff8a8c71e133d58c4c3de8ae Mon Sep 17 00:00:00 2001 From: root Date: Tue, 30 Sep 2025 18:26:37 +0800 Subject: [PATCH 4/7] Jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 818eef286..3770e68d7 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -5,7 +5,7 @@ pipeline { } environment { - // Set the Docker image name/tag + // Set the Docker image name and tag IMAGE_NAME = 'chiamintwts/assignment2_22165266:latest' } From be924f5a4b0bc9ac38b5e3492176e303076de06c Mon Sep 17 00:00:00 2001 From: root Date: Tue, 30 Sep 2025 18:28:30 +0800 Subject: [PATCH 5/7] Create Jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 3770e68d7..07ccc86c3 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -18,7 +18,7 @@ pipeline { } stage('Run Unit Tests') { steps { - // Run your test suite + // Run the test suite sh 'npm test' } } From 417d2ad4a581850a6f1b0de5fe376dc982dab0ad Mon Sep 17 00:00:00 2001 From: root Date: Tue, 30 Sep 2025 18:30:00 +0800 Subject: [PATCH 6/7] Edit Jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 07ccc86c3..1f09e3a7c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -12,7 +12,7 @@ pipeline { stages { stage('Install Dependencies') { steps { - // Install Node.js dependencies + // Install dependencies - Node.js sh 'npm install' } } From 22de49b1664d1c644aa97402223cebb60f1a34c7 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 30 Sep 2025 18:36:46 +0800 Subject: [PATCH 7/7] Edit Jenkinsfile/Dockerfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 3770e68d7..07ccc86c3 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -18,7 +18,7 @@ pipeline { } stage('Run Unit Tests') { steps { - // Run your test suite + // Run the test suite sh 'npm test' } }