From d44970b15b9ef840c1efb190e48c70d09747e2d3 Mon Sep 17 00:00:00 2001 From: "Jessada.n" Date: Mon, 14 Oct 2024 19:53:47 +0700 Subject: [PATCH 01/26] shitly code --- __test__/app.spec.js | 4 ++-- app.js | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/__test__/app.spec.js b/__test__/app.spec.js index 716aa49..6d410f1 100644 --- a/__test__/app.spec.js +++ b/__test__/app.spec.js @@ -6,7 +6,7 @@ describe('GET /', () => { it('responds with status 200 and returns the expected message', async () => { const response = await request(app).get('/'); expect(response.status).toBe(200); - expect(response.text).toBe('Hello I am senior devsecops engineer'); // ปรับให้ตรงกับข้อความที่ตอบกลับ + expect(response.text).toBe('Hello I am senior DevSecOps engineer'); // ปรับให้ตรงกับข้อความที่ตอบกลับ }); }); @@ -14,6 +14,6 @@ describe('GET /about', () => { it('responds with status 200 and renders the about page', async () => { const response = await request(app).get('/about'); expect(response.status).toBe(200); - expect(response.text).toContain('about gay'); // เปลี่ยนข้อความให้ตรงกับเนื้อหาใน about.html + expect(response.text).toContain('about page'); // เปลี่ยนข้อความให้ตรงกับเนื้อหาใน about.html }); }); diff --git a/app.js b/app.js index 941a53e..f088e57 100644 --- a/app.js +++ b/app.js @@ -11,19 +11,19 @@ app.use(express.static("public")); // Define routes app.get("/", (req, res) => { // Unused variable - const unusedVar = "Hello I am senior devsecops engineer"; + const unusedVar = "Hello I am senior DevSecOps engineer"; res.status(200).send(unusedVar); }); app.get("/about", (req, res) => { // Redundant code - res.send("about gay"); + res.send("about page"); res.send("This line will never execute"); // This line is unreachable }); // Function with no purpose function uselessFunction() { - var text = "bom gay"; + var text = "This is useless variable"; // This function does nothing but takes up space } From d831ae873a79d2f2e7aad460cceb9ff1c6caa240 Mon Sep 17 00:00:00 2001 From: "Jessada.n" Date: Mon, 14 Oct 2024 19:59:34 +0700 Subject: [PATCH 02/26] shitty code --- Jenkinsfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 4a28f94..60706b2 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -101,6 +101,8 @@ pipeline { // } // } + + stage('Deploy') { steps { echo 'Deploying the application...' From 0927ece78ce68c7d783fe2e1378bce0055132a06 Mon Sep 17 00:00:00 2001 From: "Jessada.n" Date: Mon, 14 Oct 2024 20:03:58 +0700 Subject: [PATCH 03/26] shitty code --- Jenkinsfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 60706b2..df53ab9 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -101,6 +101,8 @@ pipeline { // } // } + + stage('Deploy') { From 61c414ca3912d4d4ae212128faa7eb8cbf541c68 Mon Sep 17 00:00:00 2001 From: "Jessada.n" Date: Mon, 14 Oct 2024 20:06:00 +0700 Subject: [PATCH 04/26] shity code --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index df53ab9..12b6d0b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -6,7 +6,7 @@ pipeline { DOCKER_IMAGE = 'your-docker-image' APP_PORT = '3201' APP_NAME = 'your-app-name' - GIT_URL = 'https://github.com/ohmjess/DevSecOps' + GIT_URL = 'https://github.com/BSO-Space/DevSecOps' } parameters { @@ -103,7 +103,7 @@ pipeline { - + stage('Deploy') { steps { From 8e5346e822ef9cabf121efb8cbc12a08731ef9c6 Mon Sep 17 00:00:00 2001 From: "Jessada.n" Date: Mon, 14 Oct 2024 20:29:55 +0700 Subject: [PATCH 05/26] shitty code --- Jenkinsfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 12b6d0b..05c6c86 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -14,6 +14,8 @@ pipeline { string(name: 'DOCKER_TAG', defaultValue: 'latest', description: 'Docker image tag') } + + stages { stage('Checkout') { steps { From aebf1ad8a1568df51bfc41cc65cad25ffdc5b813 Mon Sep 17 00:00:00 2001 From: "Jessada.n" Date: Mon, 14 Oct 2024 20:33:42 +0700 Subject: [PATCH 06/26] shitty code --- Jenkinsfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 05c6c86..a9746d7 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -14,7 +14,9 @@ pipeline { string(name: 'DOCKER_TAG', defaultValue: 'latest', description: 'Docker image tag') } - + + + stages { stage('Checkout') { From 04f93882e9b2ba540573a903f36172003197b384 Mon Sep 17 00:00:00 2001 From: "Jessada.n" Date: Mon, 14 Oct 2024 20:40:21 +0700 Subject: [PATCH 07/26] shitty code --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index a9746d7..2600072 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -62,7 +62,7 @@ pipeline { stage('Scan') { steps { - withCredentials([string(credentialsId: 'jenkin-sonaqube', variable: 'SONAR_TOKEN')]) { + withCredentials([string(credentialsId: 'test-sonar', variable: 'SONAR_TOKEN')]) { sh ''' npm install sonar-scanner npx sonar-scanner \ From a04dc874dcae5683283395ff15507a489f66517c Mon Sep 17 00:00:00 2001 From: "Jessada.n" Date: Mon, 14 Oct 2024 20:42:10 +0700 Subject: [PATCH 08/26] shittty code --- __test__/app.spec.js | 2 +- app.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/__test__/app.spec.js b/__test__/app.spec.js index 6d410f1..10acbbd 100644 --- a/__test__/app.spec.js +++ b/__test__/app.spec.js @@ -6,7 +6,7 @@ describe('GET /', () => { it('responds with status 200 and returns the expected message', async () => { const response = await request(app).get('/'); expect(response.status).toBe(200); - expect(response.text).toBe('Hello I am senior DevSecOps engineer'); // ปรับให้ตรงกับข้อความที่ตอบกลับ + expect(response.text).toBe('Hello I bom gay'); // ปรับให้ตรงกับข้อความที่ตอบกลับ }); }); diff --git a/app.js b/app.js index f088e57..6408d0e 100644 --- a/app.js +++ b/app.js @@ -11,7 +11,7 @@ app.use(express.static("public")); // Define routes app.get("/", (req, res) => { // Unused variable - const unusedVar = "Hello I am senior DevSecOps engineer"; + const unusedVar = "Hello I bom gay"; res.status(200).send(unusedVar); }); From 90fac1ed5afb124c384dbc12d52c05474e10f97f Mon Sep 17 00:00:00 2001 From: "Jessada.n" Date: Mon, 14 Oct 2024 20:46:44 +0700 Subject: [PATCH 09/26] shitty code --- Jenkinsfile | 44 -------------------------------------------- 1 file changed, 44 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 2600072..b6d7e92 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,10 +2,7 @@ pipeline { agent any environment { - SONARQUBE_SERVER = 'SonarQube' - DOCKER_IMAGE = 'your-docker-image' APP_PORT = '3201' - APP_NAME = 'your-app-name' GIT_URL = 'https://github.com/BSO-Space/DevSecOps' } @@ -14,10 +11,6 @@ pipeline { string(name: 'DOCKER_TAG', defaultValue: 'latest', description: 'Docker image tag') } - - - - stages { stage('Checkout') { steps { @@ -74,46 +67,9 @@ pipeline { } } - // stage('Clear Image') - // { - // steps { - // echo 'Clearing Docker image...' - // sh "docker rmi -f ${DOCKER_IMAGE}:${params.DOCKER_TAG}" - // } - // } - - // stage('Build Docker Image') { - // steps { - // echo 'Building Docker image...' - // sh "docker build -t ${DOCKER_IMAGE}:${params.DOCKER_TAG} ." - // echo "Docker image built: ${DOCKER_IMAGE}:${params.DOCKER_TAG}" - // } - // } - - // stage('Clear Container') { - // steps { - // script { - // def containers = sh(script: "docker ps -q --filter publish=${APP_PORT}", returnStdout: true).trim() - // if (containers) { - // echo "Stopping and removing containers using port ${APP_PORT}..." - // sh "echo ${containers} | xargs docker stop" - // sh "echo ${containers} | xargs docker rm" - // } else { - // echo "No containers are using port ${APP_PORT}." - // } - // } - // } - // } - - - - - stage('Deploy') { steps { echo 'Deploying the application...' - // ตัวอย่างการนำไปใช้โดยใช้ Docker - // sh "docker run -d -p ${APP_PORT}:3000 ${DOCKER_IMAGE}:${params.DOCKER_TAG}" sh "docker-compose up -d --build" } } From 1c6f96a7c0be8953db2680c76e414101494bbe3b Mon Sep 17 00:00:00 2001 From: "Jessada.n" Date: Mon, 14 Oct 2024 20:50:21 +0700 Subject: [PATCH 10/26] shitty code --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index b6d7e92..10b791d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -60,7 +60,7 @@ pipeline { npm install sonar-scanner npx sonar-scanner \ -Dsonar.projectKey=mywebapp \ - -Dsonar.host.url=http://sonarqube:9000 \ + -Dsonar.host.url=http://sonarqubeddd:9000 \ -Dsonar.login=$SONAR_TOKEN ''' } From 0f26d7ea0a975bce63763389c674d4717a74372f Mon Sep 17 00:00:00 2001 From: "Jessada.n" Date: Mon, 14 Oct 2024 20:51:32 +0700 Subject: [PATCH 11/26] shit code --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 10b791d..1417c09 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -60,7 +60,7 @@ pipeline { npm install sonar-scanner npx sonar-scanner \ -Dsonar.projectKey=mywebapp \ - -Dsonar.host.url=http://sonarqubeddd:9000 \ + -Dsonar.host.url=http://sonarqube1:9000 \ -Dsonar.login=$SONAR_TOKEN ''' } From df3eaecc67cf5b784c55bfabf8d33beb9e38c9ed Mon Sep 17 00:00:00 2001 From: "Jessada.n" Date: Mon, 14 Oct 2024 20:52:52 +0700 Subject: [PATCH 12/26] shitty code --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 1417c09..b6d7e92 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -60,7 +60,7 @@ pipeline { npm install sonar-scanner npx sonar-scanner \ -Dsonar.projectKey=mywebapp \ - -Dsonar.host.url=http://sonarqube1:9000 \ + -Dsonar.host.url=http://sonarqube:9000 \ -Dsonar.login=$SONAR_TOKEN ''' } From 07d1f0c6ff0928266774d253657ff8d9dde7c5aa Mon Sep 17 00:00:00 2001 From: "Jessada.n" Date: Mon, 14 Oct 2024 20:55:15 +0700 Subject: [PATCH 13/26] shitty code --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index b6d7e92..0a8f3ec 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -60,7 +60,7 @@ pipeline { npm install sonar-scanner npx sonar-scanner \ -Dsonar.projectKey=mywebapp \ - -Dsonar.host.url=http://sonarqube:9000 \ + -Dsonar.host.url=http://sonarqube-dso-demo:9000 \ -Dsonar.login=$SONAR_TOKEN ''' } From 79ef9ec3bd6c4dd951db20e3181b6f2a71555749 Mon Sep 17 00:00:00 2001 From: "Jessada.n" Date: Mon, 14 Oct 2024 20:56:38 +0700 Subject: [PATCH 14/26] shitty code --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 0a8f3ec..dc4f282 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -60,7 +60,7 @@ pipeline { npm install sonar-scanner npx sonar-scanner \ -Dsonar.projectKey=mywebapp \ - -Dsonar.host.url=http://sonarqube-dso-demo:9000 \ + -Dsonar.host.url=http://sonarqube-dso-demo:9001 \ -Dsonar.login=$SONAR_TOKEN ''' } From 6cf723ae3296d0ae69213c42e9b1bd018048b990 Mon Sep 17 00:00:00 2001 From: "Jessada.n" Date: Mon, 14 Oct 2024 20:57:53 +0700 Subject: [PATCH 15/26] shitty code --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index dc4f282..53b45f4 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -60,7 +60,7 @@ pipeline { npm install sonar-scanner npx sonar-scanner \ -Dsonar.projectKey=mywebapp \ - -Dsonar.host.url=http://sonarqube-dso-demo:9001 \ + -Dsonar.host.url=http://sonarqube-dso-demo:3001 \ -Dsonar.login=$SONAR_TOKEN ''' } From 0954d7d245256fbeccc531f1289328a6bd14ebe9 Mon Sep 17 00:00:00 2001 From: "Jessada.n" Date: Mon, 14 Oct 2024 21:02:08 +0700 Subject: [PATCH 16/26] the last shitty code --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 53b45f4..0a8f3ec 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -60,7 +60,7 @@ pipeline { npm install sonar-scanner npx sonar-scanner \ -Dsonar.projectKey=mywebapp \ - -Dsonar.host.url=http://sonarqube-dso-demo:3001 \ + -Dsonar.host.url=http://sonarqube-dso-demo:9000 \ -Dsonar.login=$SONAR_TOKEN ''' } From 90b986e63c3dffd1fa707524f001e37ddfee9e01 Mon Sep 17 00:00:00 2001 From: "Jessada.n" Date: Wed, 16 Oct 2024 00:57:35 +0700 Subject: [PATCH 17/26] shit code --- __test__/app.spec.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/__test__/app.spec.js b/__test__/app.spec.js index 10acbbd..442a76a 100644 --- a/__test__/app.spec.js +++ b/__test__/app.spec.js @@ -10,6 +10,8 @@ describe('GET /', () => { }); }); + + describe('GET /about', () => { it('responds with status 200 and renders the about page', async () => { const response = await request(app).get('/about'); From bf24ca30317c5e0fe204054d903823f4c33ebf0d Mon Sep 17 00:00:00 2001 From: Piyawat Wongyat <104257779+boytur@users.noreply.github.com> Date: Wed, 16 Oct 2024 02:28:57 +0700 Subject: [PATCH 18/26] hello world --- app.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app.js b/app.js index 6408d0e..1cbeb0b 100644 --- a/app.js +++ b/app.js @@ -21,6 +21,10 @@ app.get("/about", (req, res) => { res.send("This line will never execute"); // This line is unreachable }); +app.get("/helloworld", (req, res) => { + res.send("helloworld"); +}); + // Function with no purpose function uselessFunction() { var text = "This is useless variable"; From 9c5d1a37d4aee6de8263109c6daa952389a3797c Mon Sep 17 00:00:00 2001 From: "Jessada.n" Date: Wed, 16 Oct 2024 07:53:34 +0700 Subject: [PATCH 19/26] chroe - update jenkins file for pipeline --- Jenkinsfile | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 0a8f3ec..1de20c1 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -12,48 +12,53 @@ pipeline { } stages { - stage('Checkout') { + stage('Checkout & Pulling') { steps { script { cleanWs() git branch: "${params.BRANCH_NAME}", url: "${GIT_URL}" - } - } - } - - stage('Verify Branch') { - steps { - script { if ("${params.BRANCH_NAME}" != "main") { error("This pipeline only runs on the main branch. Current branch: ${params.BRANCH_NAME}") } + echo 'Pulling the project...' + sh "git pull origin ${params.BRANCH_NAME}" } } } - stage('Pulling Project') - { - steps { - echo 'Pulling the project...' - sh "git pull origin ${params.BRANCH_NAME}" - } - } + // stage('Verify Branch') { + // steps { + // script { + // if ("${params.BRANCH_NAME}" != "main") { + // error("This pipeline only runs on the main branch. Current branch: ${params.BRANCH_NAME}") + // } + // } + // } + // } + + // stage('Pulling Project') + // { + // steps { + // echo 'Pulling the project...' + // sh "git pull origin ${params.BRANCH_NAME}" + // } + // } - stage('Build') { + stage('Install Dependencies') { steps { echo 'Building the project...' sh 'npm install' } } - stage('Test') { + stage('Testing with Jest') { steps { echo 'Running unit tests...' sh 'npm test' } } - stage('Scan') { + stage('Code analysis') { steps { withCredentials([string(credentialsId: 'test-sonar', variable: 'SONAR_TOKEN')]) { sh ''' @@ -67,7 +72,7 @@ pipeline { } } - stage('Deploy') { + stage('Docker Deployment') { steps { echo 'Deploying the application...' sh "docker-compose up -d --build" From b1be91f05965cca6dc33d050b6c7a1a6e6b4f09c Mon Sep 17 00:00:00 2001 From: "Jessada.n" Date: Wed, 16 Oct 2024 08:00:17 +0700 Subject: [PATCH 20/26] fix - fixed text for demo presentation --- __test__/app.spec.js | 2 +- app.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/__test__/app.spec.js b/__test__/app.spec.js index 442a76a..859a7ba 100644 --- a/__test__/app.spec.js +++ b/__test__/app.spec.js @@ -6,7 +6,7 @@ describe('GET /', () => { it('responds with status 200 and returns the expected message', async () => { const response = await request(app).get('/'); expect(response.status).toBe(200); - expect(response.text).toBe('Hello I bom gay'); // ปรับให้ตรงกับข้อความที่ตอบกลับ + expect(response.text).toBe("

Hello World, this is my first project for becoming a 'DEVSECOPS' engineer

"); // ปรับให้ตรงกับข้อความที่ตอบกลับ }); }); diff --git a/app.js b/app.js index 1cbeb0b..e84e2c4 100644 --- a/app.js +++ b/app.js @@ -11,7 +11,7 @@ app.use(express.static("public")); // Define routes app.get("/", (req, res) => { // Unused variable - const unusedVar = "Hello I bom gay"; + const unusedVar = "

Hello World, this is my first project for becoming a 'DEVSECOPS' engineer

"; res.status(200).send(unusedVar); }); From bb47b6b136e3dc5d46e2f58837906bd05b1dfdb5 Mon Sep 17 00:00:00 2001 From: "Jessada.n" Date: Wed, 16 Oct 2024 08:04:13 +0700 Subject: [PATCH 21/26] fix - update text for presentation --- __test__/app.spec.js | 2 +- app.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/__test__/app.spec.js b/__test__/app.spec.js index 859a7ba..e2f1952 100644 --- a/__test__/app.spec.js +++ b/__test__/app.spec.js @@ -6,7 +6,7 @@ describe('GET /', () => { it('responds with status 200 and returns the expected message', async () => { const response = await request(app).get('/'); expect(response.status).toBe(200); - expect(response.text).toBe("

Hello World, this is my first project for becoming a 'DEVSECOPS' engineer

"); // ปรับให้ตรงกับข้อความที่ตอบกลับ + expect(response.text).toBe("

Hello world! This is our first project towards becoming DevSecOps engineers.

"); // ปรับให้ตรงกับข้อความที่ตอบกลับ }); }); diff --git a/app.js b/app.js index e84e2c4..8c7855f 100644 --- a/app.js +++ b/app.js @@ -11,7 +11,7 @@ app.use(express.static("public")); // Define routes app.get("/", (req, res) => { // Unused variable - const unusedVar = "

Hello World, this is my first project for becoming a 'DEVSECOPS' engineer

"; + const unusedVar = "

Hello world! This is our first project towards becoming DevSecOps engineers.

"; res.status(200).send(unusedVar); }); From af908a0615f303e6475ebc0dc9fc4a793ef84ef0 Mon Sep 17 00:00:00 2001 From: boytur <104257779+boytur@users.noreply.github.com> Date: Wed, 16 Oct 2024 09:10:45 +0700 Subject: [PATCH 22/26] release/0.1 --- __test__/app.spec.js | 28 ++++++++++++++-------------- app.js | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/__test__/app.spec.js b/__test__/app.spec.js index 890c312..6f68194 100644 --- a/__test__/app.spec.js +++ b/__test__/app.spec.js @@ -1,19 +1,19 @@ // __tests__/app.test.js -const request = require('supertest'); -const app = require('../app'); // ปรับตามเส้นทางที่ถูกต้อง +const request = require("supertest"); +const app = require("../app"); // ปรับตามเส้นทางที่ถูกต้อง -describe('GET /', () => { - it('responds with status 200 and returns the expected message', async () => { - const response = await request(app).get('/'); - expect(response.status).toBe(200); - expect(response.text).toBe('bom gay'); // ปรับให้ตรงกับข้อความที่ตอบกลับ - }); +describe("GET /", () => { + it("responds with status 200 and returns the expected message", async () => { + const response = await request(app).get("/"); + expect(response.status).toBe(200); + expect(response.text).toBe("Ohmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm"); + }); }); -describe('GET /about', () => { - it('responds with status 200 and renders the about page', async () => { - const response = await request(app).get('/about'); - expect(response.status).toBe(200); - expect(response.text).toContain('about gay'); // เปลี่ยนข้อความให้ตรงกับเนื้อหาใน about.html - }); +describe("GET /about", () => { + it("responds with status 200 and renders the about page", async () => { + const response = await request(app).get("/about"); + expect(response.status).toBe(200); + expect(response.text).toContain("about gay"); // เปลี่ยนข้อความให้ตรงกับเนื้อหาใน about.html + }); }); diff --git a/app.js b/app.js index aceb0ad..c7bace6 100644 --- a/app.js +++ b/app.js @@ -12,7 +12,7 @@ app.use(express.static("public")); app.get("/", (req, res) => { // Unused variable const unusedVar = "This variable is not used anywhere"; - res.status(200).send("bom gay"); + res.status(200).send("Ohmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm"); }); app.get("/about", (req, res) => { From 5eb641be95d8a99badecc29012e5061b48f02bb2 Mon Sep 17 00:00:00 2001 From: boytur <104257779+boytur@users.noreply.github.com> Date: Wed, 16 Oct 2024 09:24:54 +0700 Subject: [PATCH 23/26] fix conflic --- __test__/app.spec.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/__test__/app.spec.js b/__test__/app.spec.js index a7efc39..0d17afe 100644 --- a/__test__/app.spec.js +++ b/__test__/app.spec.js @@ -2,7 +2,6 @@ const request = require("supertest"); const app = require("../app"); // ปรับตามเส้นทางที่ถูกต้อง - describe("GET /", () => { it("responds with status 200 and returns the expected message", async () => { const response = await request(app).get("/"); @@ -17,21 +16,22 @@ describe("GET /about", () => { expect(response.status).toBe(200); expect(response.text).toContain("about gay"); // เปลี่ยนข้อความให้ตรงกับเนื้อหาใน about.html }); - -describe('GET /', () => { - it('responds with status 200 and returns the expected message', async () => { - const response = await request(app).get('/'); - expect(response.status).toBe(200); - expect(response.text).toBe("

Hello world! This is our first project towards becoming DevSecOps engineers.

"); // ปรับให้ตรงกับข้อความที่ตอบกลับ - }); }); +describe("GET /", () => { + it("responds with status 200 and returns the expected message", async () => { + const response = await request(app).get("/"); + expect(response.status).toBe(200); + expect(response.text).toBe( + "

Hello world! This is our first project towards becoming DevSecOps engineers.

" + ); // ปรับให้ตรงกับข้อความที่ตอบกลับ + }); +}); - -describe('GET /about', () => { - it('responds with status 200 and renders the about page', async () => { - const response = await request(app).get('/about'); - expect(response.status).toBe(200); - expect(response.text).toContain('about page'); // เปลี่ยนข้อความให้ตรงกับเนื้อหาใน about.html - }); +describe("GET /about", () => { + it("responds with status 200 and renders the about page", async () => { + const response = await request(app).get("/about"); + expect(response.status).toBe(200); + expect(response.text).toContain("about page"); // เปลี่ยนข้อความให้ตรงกับเนื้อหาใน about.html + }); }); From 4f4959f91575c4abcd7ad59b06723c39e0e16e08 Mon Sep 17 00:00:00 2001 From: boytur <104257779+boytur@users.noreply.github.com> Date: Wed, 16 Oct 2024 09:26:29 +0700 Subject: [PATCH 24/26] fix conflic --- __test__/app.spec.js | 6 ++++-- app.js | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/__test__/app.spec.js b/__test__/app.spec.js index 0d17afe..5aba205 100644 --- a/__test__/app.spec.js +++ b/__test__/app.spec.js @@ -6,7 +6,9 @@ describe("GET /", () => { it("responds with status 200 and returns the expected message", async () => { const response = await request(app).get("/"); expect(response.status).toBe(200); - expect(response.text).toBe("Ohmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm"); + expect(response.text).toBe( + "

Hello world! This is our first project towards becoming DevSecOps engineers.

" + ); }); }); @@ -14,7 +16,7 @@ describe("GET /about", () => { it("responds with status 200 and renders the about page", async () => { const response = await request(app).get("/about"); expect(response.status).toBe(200); - expect(response.text).toContain("about gay"); // เปลี่ยนข้อความให้ตรงกับเนื้อหาใน about.html + expect(response.text).toContain("about page"); // เปลี่ยนข้อความให้ตรงกับเนื้อหาใน about.html }); }); diff --git a/app.js b/app.js index ba7ea63..13303af 100644 --- a/app.js +++ b/app.js @@ -12,8 +12,11 @@ app.use(express.static("public")); app.get("/", (req, res) => { // Unused variable const unusedVar = "This variable is not used anywhere"; - res.status(200).send("Ohmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm"); - + res + .status(200) + .send( + "

Hello world! This is our first project towards becoming DevSecOps engineers.

" + ); }); app.get("/about", (req, res) => { From ea8ed7d65ba4ad0774ba06212ce06ebd8c0826c8 Mon Sep 17 00:00:00 2001 From: boytur <104257779+boytur@users.noreply.github.com> Date: Wed, 16 Oct 2024 09:29:57 +0700 Subject: [PATCH 25/26] release/0.1 --- __test__/app.spec.js | 4 ++-- app.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/__test__/app.spec.js b/__test__/app.spec.js index 5aba205..e88b6e2 100644 --- a/__test__/app.spec.js +++ b/__test__/app.spec.js @@ -7,7 +7,7 @@ describe("GET /", () => { const response = await request(app).get("/"); expect(response.status).toBe(200); expect(response.text).toBe( - "

Hello world! This is our first project towards becoming DevSecOps engineers.

" + "

Hello world! This is our first project towards becoming DevSecOps engineers.😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎

" ); }); }); @@ -25,7 +25,7 @@ describe("GET /", () => { const response = await request(app).get("/"); expect(response.status).toBe(200); expect(response.text).toBe( - "

Hello world! This is our first project towards becoming DevSecOps engineers.

" + "

Hello world! This is our first project towards becoming DevSecOps engineers.😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎

" ); // ปรับให้ตรงกับข้อความที่ตอบกลับ }); }); diff --git a/app.js b/app.js index 13303af..ac886c1 100644 --- a/app.js +++ b/app.js @@ -15,7 +15,7 @@ app.get("/", (req, res) => { res .status(200) .send( - "

Hello world! This is our first project towards becoming DevSecOps engineers.

" + "

Hello world! This is our first project towards becoming DevSecOps engineers.😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎

" ); }); From 4a7ed2c05d78b0cb18e0a488fd1f103834f30086 Mon Sep 17 00:00:00 2001 From: boytur <104257779+boytur@users.noreply.github.com> Date: Tue, 29 Oct 2024 16:23:30 +0700 Subject: [PATCH 26/26] smell code --- Jenkinsfile | 173 ++++++++++++++++++++++++---------------------------- 1 file changed, 80 insertions(+), 93 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 1de20c1..77fa3b7 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,94 +1,81 @@ -pipeline { - agent any - - environment { - APP_PORT = '3201' - GIT_URL = 'https://github.com/BSO-Space/DevSecOps' - } - - parameters { - string(name: 'BRANCH_NAME', defaultValue: 'main', description: 'Branch name for the build') - string(name: 'DOCKER_TAG', defaultValue: 'latest', description: 'Docker image tag') - } - - stages { - stage('Checkout & Pulling') { - steps { - script { - cleanWs() - git branch: "${params.BRANCH_NAME}", url: "${GIT_URL}" - if ("${params.BRANCH_NAME}" != "main") { - error("This pipeline only runs on the main branch. Current branch: ${params.BRANCH_NAME}") - } - echo 'Pulling the project...' - sh "git pull origin ${params.BRANCH_NAME}" - } - } - } - - // stage('Verify Branch') { - // steps { - // script { - // if ("${params.BRANCH_NAME}" != "main") { - // error("This pipeline only runs on the main branch. Current branch: ${params.BRANCH_NAME}") - // } - // } - // } - // } - - // stage('Pulling Project') - // { - // steps { - // echo 'Pulling the project...' - // sh "git pull origin ${params.BRANCH_NAME}" - // } - // } - - stage('Install Dependencies') { - steps { - echo 'Building the project...' - sh 'npm install' - } - } - - stage('Testing with Jest') { - steps { - echo 'Running unit tests...' - sh 'npm test' - } - } - - stage('Code analysis') { - steps { - withCredentials([string(credentialsId: 'test-sonar', variable: 'SONAR_TOKEN')]) { - sh ''' - npm install sonar-scanner - npx sonar-scanner \ - -Dsonar.projectKey=mywebapp \ - -Dsonar.host.url=http://sonarqube-dso-demo:9000 \ - -Dsonar.login=$SONAR_TOKEN - ''' - } - } - } - - stage('Docker Deployment') { - steps { - echo 'Deploying the application...' - sh "docker-compose up -d --build" - } - } - } - - post { - success { - echo 'Pipeline completed successfully!' - } - failure { - echo 'Pipeline failed.' - } - cleanup { - echo 'Cleaning up...' - } - } +pipeline { + agent any + environment { + APP_PORT = '3201' + GIT_URL = 'https://github.com/BSO-Space/DevSecOps' + } + parameters { + string(name: 'BRANCH_NAME', defaultValue: 'main', description: 'Branch name for the build') + string(name: 'DOCKER_TAG', defaultValue: 'latest', description: 'Docker image tag') + } + stages { + stage('Checkout & Pulling') { + steps { + script { + cleanWs() + git branch: "${params.BRANCH_NAME}", url: "${GIT_URL}" + if ("${params.BRANCH_NAME}" != "main") { + error("This pipeline only runs on the main branch. Current branch: ${params.BRANCH_NAME}") + } + echo 'Pulling the project...' + sh "git pull origin ${params.BRANCH_NAME}" + } + } + } + + stage('Install Dependencies') { + steps { + echo 'Building the project...' + sh 'npm install' + } + } + + stage('Testing with Jest') { + steps { + echo 'Running unit tests...' + sh 'npm test' + } + } + + stage('Code analysis') { + steps { + withCredentials([string(credentialsId: 'test-sonar', variable: 'SONAR_TOKEN')]) { + sh ''' + npm install sonar-scanner + npx sonar-scanner \ + -Dsonar.projectKey=mywebapp \ + -Dsonar.host.url=http://sonarqube-dso-demo:9000 \ + -Dsonar.login=$SONAR_TOKEN + ''' + } + } + post { + success { + echo 'Code analysis passed.' + } + failure { + echo 'Code analysis failed. Stopping the pipeline.' + error("Quality gate failed. Pipeline stopped.") + } + } + } + + stage('Docker Deployment') { + steps { + echo 'Deploying the application...' + sh "docker-compose up -d --build" + } + } + } + post { + success { + echo 'Pipeline completed successfully!' + } + failure { + echo 'Pipeline failed.' + } + cleanup { + echo 'Cleaning up...' + } + } }