From 712f54096ced2c682f079c2bfb956b052cb09c77 Mon Sep 17 00:00:00 2001 From: Bae Hyeonseo Date: Sun, 1 Oct 2023 20:32:43 +0900 Subject: [PATCH 01/10] [chore] #1 ci/cd --- Dockerfile | 1 + docker-compose.yml | 1 + scripts/deploy.sh | 3 ++- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 3ef1a25..e1c725e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,4 @@ +#cicd FROM openjdk:17-alpine COPY ./build/libs/server-0.0.1-SNAPSHOT.jar app.jar ENTRYPOINT ["java", "-jar", "app.jar"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index cfbef9a..238cdc8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,3 +1,4 @@ +#cicd version: '3' services: blue: diff --git a/scripts/deploy.sh b/scripts/deploy.sh index 1c64d6e..792cf30 100644 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -44,4 +44,5 @@ else sudo nginx -s reload echo ">>> green container를 down합니다." docker-compose stop green -fi \ No newline at end of file +fi +#cicd \ No newline at end of file From f5d41a7c33880b1086f59dc01165e359613afe29 Mon Sep 17 00:00:00 2001 From: Bae Hyeonseo Date: Sun, 1 Oct 2023 20:45:24 +0900 Subject: [PATCH 02/10] [chore] #1 ci/cd --- .github/workflows/gradle.yml | 2 +- Dockerfile | 2 +- docker-compose.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 48dc409..2af873e 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -1,4 +1,4 @@ -name: meetup Server CI/CD with Docker +name: meetup Server CI/CD with Docker. on: push: diff --git a/Dockerfile b/Dockerfile index e1c725e..1c90ddf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -#cicd +#ci/cd FROM openjdk:17-alpine COPY ./build/libs/server-0.0.1-SNAPSHOT.jar app.jar ENTRYPOINT ["java", "-jar", "app.jar"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 238cdc8..3d3820f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,4 @@ -#cicd +#ci/cd version: '3' services: blue: From 899780667a41d8c17ed4281ee5a02b746a9b8e0b Mon Sep 17 00:00:00 2001 From: Bae Hyeonseo Date: Fri, 6 Oct 2023 15:58:08 +0900 Subject: [PATCH 03/10] ci/cd --- src/main/resources/application.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 1b238de..70b2516 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,4 +1,5 @@ server: + port: 8080 spring: From 275a1bf2fc578e70e0979b01398aa290bc08d100 Mon Sep 17 00:00:00 2001 From: Bae Hyeonseo Date: Fri, 6 Oct 2023 15:58:41 +0900 Subject: [PATCH 04/10] ci/cd --- src/main/java/meetup/server/ServerApplication.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/meetup/server/ServerApplication.java b/src/main/java/meetup/server/ServerApplication.java index 8eecc69..53a02a3 100644 --- a/src/main/java/meetup/server/ServerApplication.java +++ b/src/main/java/meetup/server/ServerApplication.java @@ -5,7 +5,7 @@ @SpringBootApplication public class ServerApplication { -//q +//qq public static void main(String[] args) { SpringApplication.run(ServerApplication.class, args); } From cc9570a4c7831085f76c73c5e95c11549c8d1c54 Mon Sep 17 00:00:00 2001 From: Bae Hyeonseo Date: Fri, 6 Oct 2023 16:19:02 +0900 Subject: [PATCH 05/10] ci/cd --- Dockerfile | 2 +- build.gradle | 28 ++++++++++++++-------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1c90ddf..30fba83 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ #ci/cd -FROM openjdk:17-alpine +FROM openjdk:11-jdk COPY ./build/libs/server-0.0.1-SNAPSHOT.jar app.jar ENTRYPOINT ["java", "-jar", "app.jar"] \ No newline at end of file diff --git a/build.gradle b/build.gradle index 7d2ebcd..af53e2b 100644 --- a/build.gradle +++ b/build.gradle @@ -1,20 +1,14 @@ plugins { id 'java' - id 'org.springframework.boot' version '3.1.4' - id 'io.spring.dependency-management' version '1.1.3' + id 'org.springframework.boot' version '2.7.16' + id 'io.spring.dependency-management' version '1.0.15.RELEASE' } -group = 'meetup' +group = 'com.groupD' version = '0.0.1-SNAPSHOT' java { - sourceCompatibility = '17' -} - -configurations { - compileOnly { - extendsFrom annotationProcessor - } + sourceCompatibility = '11' } repositories { @@ -22,12 +16,18 @@ repositories { } dependencies { - implementation 'org.springframework.boot:spring-boot-starter-data-jpa' - implementation 'org.springframework.boot:spring-boot-starter-web' + implementation 'org.springframework.boot:spring-boot-starter' + testImplementation 'org.springframework.boot:spring-boot-starter-test' + + // lombok compileOnly 'org.projectlombok:lombok' - runtimeOnly 'com.mysql:mysql-connector-j' annotationProcessor 'org.projectlombok:lombok' - testImplementation 'org.springframework.boot:spring-boot-starter-test' + + // jpa + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + + //db + runtimeOnly 'com.mysql:mysql-connector-j' implementation 'mysql:mysql-connector-java:8.0.33' } From df455ebc834ff9c2f52fcbeeed29b6fa51a407a5 Mon Sep 17 00:00:00 2001 From: Bae Hyeonseo Date: Fri, 6 Oct 2023 16:20:29 +0900 Subject: [PATCH 06/10] ci/cd --- .github/workflows/gradle.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 2af873e..ce890c6 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -16,10 +16,10 @@ jobs: steps: - uses: actions/checkout@v3 - - name: 🍃 JDK 17로 설정합니다. + - name: 🍃 JDK 11로 설정합니다. uses: actions/setup-java@v3 with: - java-version: '17' + java-version: '11' distribution: 'temurin' From abeafb11d599ab6fe87e6ab3da8d9661e95c68f9 Mon Sep 17 00:00:00 2001 From: Bae Hyeonseo Date: Fri, 6 Oct 2023 16:58:42 +0900 Subject: [PATCH 07/10] ci/cd --- docker-compose.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 3d3820f..e638dfb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,7 +7,7 @@ services: expose: - 8080 ports: - - 8081:8080 + - 8080:8080 environment: - TZ=Asia/Seoul green: @@ -16,6 +16,6 @@ services: expose: - 8080 ports: - - 8082:8080 + - 8081:8080 environment: - TZ=Asia/Seoul \ No newline at end of file From 04d26174554ec809b3903f362a894763dec54293 Mon Sep 17 00:00:00 2001 From: Bae Hyeonseo Date: Fri, 6 Oct 2023 17:01:56 +0900 Subject: [PATCH 08/10] ci/cd --- scripts/deploy.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/deploy.sh b/scripts/deploy.sh index 792cf30..00b57a7 100644 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -10,7 +10,7 @@ if [ -z $IS_GREEN_EXIST ];then while [ 1 = 1 ]; do echo ">>> green health check 중..." sleep 3 - REQUEST=$(curl http://127.0.0.1:8082) + REQUEST=$(curl http://127.0.0.1:8081) if [ -n "$REQUEST" ]; then echo ">>> 🍃 health check success !" break; @@ -32,7 +32,7 @@ else while [ 1 = 1 ]; do echo ">>> blue health check 중..." sleep 3 - REQUEST=$(curl http://127.0.0.1:8081) + REQUEST=$(curl http://127.0.0.1:8080) if [ -n "$REQUEST" ]; then echo ">>> 🍃 health check success !" break; From df7f35e041caca7f606e36480ae9648b5de7830c Mon Sep 17 00:00:00 2001 From: Bae Hyeonseo Date: Fri, 6 Oct 2023 17:09:27 +0900 Subject: [PATCH 09/10] ci/cd --- scripts/deploy.sh | 67 +++++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 28 deletions(-) diff --git a/scripts/deploy.sh b/scripts/deploy.sh index 00b57a7..abf35b8 100644 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -1,48 +1,59 @@ #!/bin/bash -IS_GREEN_EXIST=$(docker ps | grep green) + +IS_GREEN=$(docker ps | grep green) # 현재 실행중인 App이 blue인지 확인합니다. DEFAULT_CONF=" /etc/nginx/nginx.conf" -if [ -z $IS_GREEN_EXIST ];then + +if [ -z $IS_GREEN ];then # blue라면 + echo "### BLUE => GREEN ####" - echo ">>> green image를 pull합니다." - docker-compose pull green - echo ">>> green container를 up합니다." - docker-compose up -d green + + echo "1. get green image" + docker-compose pull green # green으로 이미지를 내려받습니다. + + echo "2. green container up" + docker-compose up -d green # green 컨테이너 실행 + while [ 1 = 1 ]; do - echo ">>> green health check 중..." + echo "3. green health check..." sleep 3 - REQUEST=$(curl http://127.0.0.1:8081) - if [ -n "$REQUEST" ]; then - echo ">>> 🍃 health check success !" - break; - fi + + REQUEST=$(curl http://127.0.0.1:8081) # green으로 request + if [ -n "$REQUEST" ]; then # 서비스 가능하면 health check 중지 + echo "health check success" + break ; + fi done; - sleep 3 - echo ">>> nginx를 다시 실행 합니다." + + echo "4. reload nginx" sudo cp /etc/nginx/nginx.green.conf /etc/nginx/nginx.conf sudo nginx -s reload - echo ">>> blue container를 down합니다." + + echo "5. blue container down" docker-compose stop blue -# green이 실행 중이면 blue를 up합니다. else echo "### GREEN => BLUE ###" - echo ">>> blue image를 pull합니다." + + echo "1. get blue image" docker-compose pull blue - echo ">>> blue container up합니다." + + echo "2. blue container up" docker-compose up -d blue + while [ 1 = 1 ]; do - echo ">>> blue health check 중..." + echo "3. blue health check..." sleep 3 - REQUEST=$(curl http://127.0.0.1:8080) - if [ -n "$REQUEST" ]; then - echo ">>> 🍃 health check success !" - break; + REQUEST=$(curl http://127.0.0.1:8080) # blue로 request + + if [ -n "$REQUEST" ]; then # 서비스 가능하면 health check 중지 + echo "health check success" + break ; fi done; - sleep 3 - echo ">>> nginx를 다시 실행 합니다." + + echo "4. reload nginx" sudo cp /etc/nginx/nginx.blue.conf /etc/nginx/nginx.conf sudo nginx -s reload - echo ">>> green container를 down합니다." + + echo "5. green container down" docker-compose stop green -fi -#cicd \ No newline at end of file +fi \ No newline at end of file From 1c5312510ec296c872acf20f01bb7b9b17cbb950 Mon Sep 17 00:00:00 2001 From: Bae Hyeonseo Date: Fri, 6 Oct 2023 17:30:54 +0900 Subject: [PATCH 10/10] ci/cd --- docker-compose.yml | 4 ++-- scripts/deploy.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index e638dfb..3d3820f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,7 +7,7 @@ services: expose: - 8080 ports: - - 8080:8080 + - 8081:8080 environment: - TZ=Asia/Seoul green: @@ -16,6 +16,6 @@ services: expose: - 8080 ports: - - 8081:8080 + - 8082:8080 environment: - TZ=Asia/Seoul \ No newline at end of file diff --git a/scripts/deploy.sh b/scripts/deploy.sh index abf35b8..c52d748 100644 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -17,7 +17,7 @@ if [ -z $IS_GREEN ];then # blue라면 echo "3. green health check..." sleep 3 - REQUEST=$(curl http://127.0.0.1:8081) # green으로 request + REQUEST=$(curl http://127.0.0.1:8082) # green으로 request if [ -n "$REQUEST" ]; then # 서비스 가능하면 health check 중지 echo "health check success" break ; @@ -42,7 +42,7 @@ else while [ 1 = 1 ]; do echo "3. blue health check..." sleep 3 - REQUEST=$(curl http://127.0.0.1:8080) # blue로 request + REQUEST=$(curl http://127.0.0.1:8081) # blue로 request if [ -n "$REQUEST" ]; then # 서비스 가능하면 health check 중지 echo "health check success"