From baf68c7d8fb985fe993a652f9066bb509519913d Mon Sep 17 00:00:00 2001 From: GeunHye <107075096+KimGeunHye21@users.noreply.github.com> Date: Tue, 3 Dec 2024 21:16:04 +0900 Subject: [PATCH 1/7] Update Jenkinsfile --- Jenkinsfile | 70 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 49 insertions(+), 21 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index aaf1357..b7354f4 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,22 +1,50 @@ -node { - def app - stage('Clone repository') { - git 'https://github.com/KimGeunHye21/Wimb_DevOps.git' - } - stage('Build image') { - app = docker.build("kimgeunhye21/wimb") - } - stage('Test image') { - app.inside{ - // sh'make test' - } - } - stage('Push image') { - docker.withRegistry('https://registry.hub.docker.com', 'kimgeunhye21') { - app.push("${env.BUILD_NUMBER}") - app.push("latest") - } - } +pipeline { + agent any + environment { + PROJECT_ID = 'project my-project-2024-442302' + CLUSTER_NAME = 'kube' + LOCATION = 'asia-northeast3-a' + CREDENTIALS_ID = 'gke' + } + stages { + stage("Checkout code") { + steps { + checkout scm + } + } + stage("Copy .env file") { + steps { + script { + sh "cp /var/jenkins_home/.env ./code/.env" + } + } + } + stage("Build image") { + steps { + script { + myapp = docker.build("kimgeunhye21/wimb:${env.BUILD_ID}") + } + } + } + stage("Push image") { + steps { + script { + docker.withRegistry('https://registry.hub.docker.com', 'kimgeunhye21') { + myapp.push("latest") + myapp.push("${env.BUILD_ID}") + } + } + } + } + stage('Deploy to GKE') { + when { + branch 'main' + } + steps{ + sh "sed -i 's/wimb:latest/wimb:${env.BUILD_ID}/g' deployment.yaml" + step([$class: 'KubernetesEngineBuilder', projectId: env.PROJECT_ID, clusterName: env.CLUSTER_NAME, location: env.LOCATION, manifestPattern: 'deployment.yaml', credentialsId: env.CREDENTIALS_ID, +verifyDeployments: true]) + } + } + } } - -// pr기반 테스트1 From da033c3e4757c99ae75ca532cb66378a04f2a374 Mon Sep 17 00:00:00 2001 From: GeunHye <107075096+KimGeunHye21@users.noreply.github.com> Date: Tue, 3 Dec 2024 21:17:38 +0900 Subject: [PATCH 2/7] Create deployment.yaml --- deployment.yaml | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 deployment.yaml diff --git a/deployment.yaml b/deployment.yaml new file mode 100644 index 0000000..ee0ffdd --- /dev/null +++ b/deployment.yaml @@ -0,0 +1,43 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: wimb + labels: + app: wimb +spec: + replicas: 3 + strategy: + type: Recreate + selector: + matchLabels: + app: wimb + template: + metadata: + labels: + app: wimb + tier: wimb + spec: + containers: + - name: wimb + image: kimgeunhye21/wimb:latest + imagePullPolicy: Always + ports: + - containerPort: 5000 + name: wimb + +--- + +apiVersion: v1 +kind: Service +metadata: + name: wimb + labels: + app: wimb +spec: + ports: + - port: 80 + targetPort: 5000 + selector: + app: wimb + tier: wimb + type: LoadBalancer From 8763aadbade980f5c998e21c6b5e76f982d34abf Mon Sep 17 00:00:00 2001 From: GeunHye <107075096+KimGeunHye21@users.noreply.github.com> Date: Tue, 3 Dec 2024 21:43:22 +0900 Subject: [PATCH 3/7] Update Jenkinsfile --- Jenkinsfile | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index b7354f4..be63c71 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -12,13 +12,13 @@ pipeline { checkout scm } } - stage("Copy .env file") { - steps { - script { - sh "cp /var/jenkins_home/.env ./code/.env" - } - } - } + // stage("Copy .env file") { + // steps { + // script { + // sh "cp /var/jenkins_home/.env ./code/.env" + // } + // } + // } stage("Build image") { steps { script { From ccc105c30ec77a4c13188245d0c6d0c498df3975 Mon Sep 17 00:00:00 2001 From: GeunHye <107075096+KimGeunHye21@users.noreply.github.com> Date: Tue, 3 Dec 2024 21:47:27 +0900 Subject: [PATCH 4/7] Update Jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index be63c71..1b48bb2 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,7 +1,7 @@ pipeline { agent any environment { - PROJECT_ID = 'project my-project-2024-442302' + PROJECT_ID = 'my-project-2024-442302' CLUSTER_NAME = 'kube' LOCATION = 'asia-northeast3-a' CREDENTIALS_ID = 'gke' From b8a20f0ccf6add7b8ecb3786bd7e634e389f8bf9 Mon Sep 17 00:00:00 2001 From: GeunHye <107075096+KimGeunHye21@users.noreply.github.com> Date: Tue, 3 Dec 2024 23:47:56 +0900 Subject: [PATCH 5/7] Update Jenkinsfile copy .env --- Jenkinsfile | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 1b48bb2..aec5445 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -12,13 +12,13 @@ pipeline { checkout scm } } - // stage("Copy .env file") { - // steps { - // script { - // sh "cp /var/jenkins_home/.env ./code/.env" - // } - // } - // } + stage("Copy .env file") { + steps { + script { + sh "cp /var/jenkins_home/.env ./code/.env" + } + } + } stage("Build image") { steps { script { From 3cbea73dc582bcdee3d6ab47cfdadc9186bda276 Mon Sep 17 00:00:00 2001 From: GeunHye <107075096+KimGeunHye21@users.noreply.github.com> Date: Wed, 4 Dec 2024 00:46:24 +0900 Subject: [PATCH 6/7] Update Dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index b5ec8bd..3e92723 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,6 +15,6 @@ COPY --from=build /usr/src/app /usr/src/app WORKDIR /usr/src/app COPY ./code/ . -EXPOSE 80 +EXPOSE 5000 CMD ["node", "main.js"] From 92e14e6216b6897e1d2daa7a69a8e4edaacc08ed Mon Sep 17 00:00:00 2001 From: GeunHye <107075096+KimGeunHye21@users.noreply.github.com> Date: Wed, 4 Dec 2024 00:50:59 +0900 Subject: [PATCH 7/7] Update Dockerfile --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 3e92723..18bc5ca 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,6 +15,7 @@ COPY --from=build /usr/src/app /usr/src/app WORKDIR /usr/src/app COPY ./code/ . +ENV PORT 5000 EXPOSE 5000 CMD ["node", "main.js"]