From 46b1d8974d7797ea5a745d6e573ac52108a76d3c Mon Sep 17 00:00:00 2001 From: hyunseo Date: Thu, 3 Oct 2024 16:35:23 +0900 Subject: [PATCH 1/7] =?UTF-8?q?[refactor]=20ci/cd=20=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/gradle.yml | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 13d21f76..bb85e25b 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -1,15 +1,13 @@ name: Java CI with Gradle -# Master, develop 브랜치에 push 혹은 pull request가 발생할 경우 동작한다. +# Master, develop, weekly/* 브랜치에 push가 발생할 경우 동작한다. on: push: - branches: [ "Master", "develop" ] - pull_request: - branches: [ "Master", "develop" ] + branches: [ "Master", "develop", "weekly/*" ] permissions: contents: read - + jobs: # Spring Boot 애플리케이션을 빌드하여 도커허브에 푸시하는 과정 build-docker-image: @@ -17,34 +15,39 @@ jobs: steps: - uses: actions/checkout@v4 - # 1. Java 17 세팅 + # Java 17 세팅 - name: Set up JDK 17 uses: actions/setup-java@v4 with: java-version: '17' distribution: 'temurin' + # Gradle Wrapper 파일 실행 권한 주기 - name: Run chmod to make gradlew executable run: chmod +x ./gradlew - # 2. Spring Boot 애플리케이션 빌드 + # Spring Boot 애플리케이션 빌드 - name: Build with Gradle uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1 with: arguments: clean bootJar - # 3. Docker 이미지 빌드 + # 테스트 실행 + - name: Run tests + run: ./gradlew test + + # Docker 이미지 빌드 - name: docker image build run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/inplace . - # 4. DockerHub 로그인 + # DockerHub 로그인 - name: docker login uses: docker/login-action@v2 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_PASSWORD }} - # 5. Docker Hub 이미지 푸시 + # Docker Hub 이미지 푸시 - name: docker Hub push run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/inplace @@ -55,6 +58,9 @@ jobs: needs: build-docker-image runs-on: self-hosted + # weekly/* 브랜치에서는 실행되지 않도록 조건 추가 + if: startsWith(github.ref, 'refs/heads/master') || startsWith(github.ref, 'refs/heads/develop') + steps: # 1. 최신 이미지를 pull - name: docker pull From 66394b208e814f3e302fb3021a3fadd57591a8fb Mon Sep 17 00:00:00 2001 From: hyunseo Date: Thu, 3 Oct 2024 16:36:53 +0900 Subject: [PATCH 2/7] =?UTF-8?q?[feat]=20=EB=8F=84=EC=BB=A4=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EB=B0=8F=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 17 +++++++++++++++++ .../java/team7/inplace/cicd/TestController.java | 13 +++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 Dockerfile create mode 100644 src/main/java/team7/inplace/cicd/TestController.java diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..f3f3a7dc --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +# Dockerfile + +# jdk17 Image Start +#FROM --platform=linux/amd64 ubuntu:latest +FROM openjdk:17 + +# 인자 설정 - Jar_File +ARG JAR_FILE=build/libs/*.jar + +# jar 파일 복제 +COPY ${JAR_FILE} app.jar + +# 인자 설정 부분과 jar 파일 복제 부분 합쳐서 진행해도 무방 +#COPY build/libs/*.jar app.jar + +# 실행 명령어 +ENTRYPOINT ["java", "-jar", "app.jar"] diff --git a/src/main/java/team7/inplace/cicd/TestController.java b/src/main/java/team7/inplace/cicd/TestController.java new file mode 100644 index 00000000..07821772 --- /dev/null +++ b/src/main/java/team7/inplace/cicd/TestController.java @@ -0,0 +1,13 @@ +package team7.inplace.cicd; + +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class TestController { + @GetMapping("/cicd") + public ResponseEntity test() { + return ResponseEntity.ok("ci/cd 테스트"); + } +} From 9fa2f8ce247931cedd634b1de5435dcfc3340e00 Mon Sep 17 00:00:00 2001 From: hyunseo Date: Thu, 3 Oct 2024 16:52:21 +0900 Subject: [PATCH 3/7] =?UTF-8?q?[feat]=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=8B=A4=ED=96=89=20=EC=A3=BC=EC=84=9D=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .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 bb85e25b..0ce6d9de 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -33,8 +33,8 @@ jobs: arguments: clean bootJar # 테스트 실행 - - name: Run tests - run: ./gradlew test +# - name: Run tests +# run: ./gradlew test # Docker 이미지 빌드 - name: docker image build From cb9369f58f631303f7c4fcaee9c412fa4a39371a Mon Sep 17 00:00:00 2001 From: wndlthsk <80496766+wndlthsk@users.noreply.github.com> Date: Fri, 4 Oct 2024 12:30:42 +0900 Subject: [PATCH 4/7] =?UTF-8?q?[feat]=20cd=20=ED=99=98=EA=B2=BD=EB=B3=80?= =?UTF-8?q?=EC=88=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/gradle.yml | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 0ce6d9de..5bbf6e98 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -62,22 +62,32 @@ jobs: if: startsWith(github.ref, 'refs/heads/master') || startsWith(github.ref, 'refs/heads/develop') steps: - # 1. 최신 이미지를 pull + # 최신 이미지를 pull - name: docker pull run: sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/inplace - # 2. 기존의 컨테이너를 중지 + # 기존의 컨테이너를 중지 - name: docker stop container run: sudo docker stop $(sudo docker ps -q) 2>/dev/null || true - # 3. 브랜치에 따라 다른 환경 변수를 설정하여 컨테이너 실행 + # .env 파일 생성 + - name: Create .env file + run: | + echo "KAKAO_CLIENT_ID=${{ secrets.KAKAO_CLIENT_ID }}" >> .env + echo "KAKAO_CLIENT_SECRET=${{ secrets.KAKAO_CLIENT_SECRET }}" >> .env + echo "KAKAO_REDIRECT_URI=${{ secrets.KAKAO_REDIRECT_URI }}" >> .env + echo "JWT_SECRET=${{ secrets.JWT_SECRET }}" >> .env + echo "JWT_ACCESS_TOKEN_EXPIRED_TIME=${{ secrets.JWT_ACCESS_TOKEN_EXPIRED_TIME }}" >> .env + echo "JWT_REFRESH_TOKEN_EXPIRED_TIME=${{ secrets.JWT_REFRESH_TOKEN_EXPIRED_TIME }}" >> .env + + # 브랜치에 따라 다른 환경 변수를 설정하여 컨테이너 실행 - name: docker run new container run: | if [ "${{ github.ref }}" == "refs/heads/master" ]; then - sudo docker run --name inplace --rm -d -p 8080:8080 ${{ secrets.DOCKERHUB_USERNAME }}/inplace + sudo docker run --name inplace --rm -d -p 8080:8080 --env-file .env ${{ secrets.DOCKERHUB_USERNAME }}/inplace elif [ "${{ github.ref }}" == "refs/heads/develop" ]; then - sudo docker run --name inplace-dev --rm -d -p 8081:8080 ${{ secrets.DOCKERHUB_USERNAME }}/inplace + sudo docker run --name inplace-dev --rm -d -p 8081:8080 --env-file .env ${{ secrets.DOCKERHUB_USERNAME }}/inplace - # 4. 미사용 이미지를 정리 + # 미사용 이미지를 정리 - name: delete old docker image run: sudo docker system prune -f From 303914858860591a9878e63deefc7a5094b22140 Mon Sep 17 00:00:00 2001 From: wndlthsk <80496766+wndlthsk@users.noreply.github.com> Date: Fri, 4 Oct 2024 12:42:34 +0900 Subject: [PATCH 5/7] =?UTF-8?q?[fix]=20fi=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/gradle.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 5bbf6e98..f1c739a9 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -87,7 +87,8 @@ jobs: sudo docker run --name inplace --rm -d -p 8080:8080 --env-file .env ${{ secrets.DOCKERHUB_USERNAME }}/inplace elif [ "${{ github.ref }}" == "refs/heads/develop" ]; then sudo docker run --name inplace-dev --rm -d -p 8081:8080 --env-file .env ${{ secrets.DOCKERHUB_USERNAME }}/inplace - + fi + # 미사용 이미지를 정리 - name: delete old docker image run: sudo docker system prune -f From e3a0e29431d0601e4ad96c6866bdfb830c827bdf Mon Sep 17 00:00:00 2001 From: wndlthsk <80496766+wndlthsk@users.noreply.github.com> Date: Fri, 4 Oct 2024 14:27:22 +0900 Subject: [PATCH 6/7] =?UTF-8?q?[fix]=20=EB=B8=8C=EB=9E=9C=EC=B9=98?= =?UTF-8?q?=EB=AA=85=20=EB=8C=80=EB=AC=B8=EC=9E=90=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .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 f1c739a9..4c38f392 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -59,7 +59,7 @@ jobs: runs-on: self-hosted # weekly/* 브랜치에서는 실행되지 않도록 조건 추가 - if: startsWith(github.ref, 'refs/heads/master') || startsWith(github.ref, 'refs/heads/develop') + if: startsWith(github.ref, 'refs/heads/Master') || startsWith(github.ref, 'refs/heads/develop') steps: # 최신 이미지를 pull @@ -83,7 +83,7 @@ jobs: # 브랜치에 따라 다른 환경 변수를 설정하여 컨테이너 실행 - name: docker run new container run: | - if [ "${{ github.ref }}" == "refs/heads/master" ]; then + if [ "${{ github.ref }}" == "refs/heads/Master" ]; then sudo docker run --name inplace --rm -d -p 8080:8080 --env-file .env ${{ secrets.DOCKERHUB_USERNAME }}/inplace elif [ "${{ github.ref }}" == "refs/heads/develop" ]; then sudo docker run --name inplace-dev --rm -d -p 8081:8080 --env-file .env ${{ secrets.DOCKERHUB_USERNAME }}/inplace From 419891985995bd822275721d7b2bb4bb162e142c Mon Sep 17 00:00:00 2001 From: wndlthsk <80496766+wndlthsk@users.noreply.github.com> Date: Fri, 4 Oct 2024 14:36:09 +0900 Subject: [PATCH 7/7] =?UTF-8?q?[test]=20cicd=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EC=9A=A9=20=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/team7/inplace/cicd/TestController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/team7/inplace/cicd/TestController.java b/src/main/java/team7/inplace/cicd/TestController.java index 07821772..34bcc01a 100644 --- a/src/main/java/team7/inplace/cicd/TestController.java +++ b/src/main/java/team7/inplace/cicd/TestController.java @@ -8,6 +8,6 @@ public class TestController { @GetMapping("/cicd") public ResponseEntity test() { - return ResponseEntity.ok("ci/cd 테스트"); + return ResponseEntity.ok("ci/cd 테스트2"); } }