From ded41a3e4604d1d4f3db186116d79026006506f7 Mon Sep 17 00:00:00 2001 From: jaemin0413 <95339052+jaemin0413@users.noreply.github.com> Date: Mon, 17 Nov 2025 23:03:16 +0900 Subject: [PATCH 01/10] =?UTF-8?q?ci=20=EB=B0=8F=20=EB=8F=84=EC=BB=A4?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20main=EC=9C=BC=EB=A1=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 58 ++++++++++++++++++++++++++++++++++++++++ dockerfile | 15 +++++++++++ 2 files changed, 73 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 dockerfile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..9812180 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,58 @@ +# 워크플로우의 이름 +name: CI - Build and Push Docker Image to Docker Hub + +# 워크플로우 트리거 -> main 브랜치에 푸쉬할 때 +on: + push: + branches: [ "main" ] + +# 실행될 작업 정의 +jobs: + build-and-push: + name: Build and Push to Docker Hub + # 작업이 실행될 환경 + runs-on: ubuntu-latest + + steps: + # 1. 소스 코드 가져오기 + - name: Check out the repo + uses: actions/checkout@v4 + + # 2. JDK 17 설정 + - name: Set up JDK 17 with Gradle cache + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + cache: 'gradle' # gradle 의존성 캐싱, 이거 안 하면 한 번 받은 라이브러리는 캐시해두고 다음엔 바로 사용. + # 이거 안 하면 할 때마다 gradle 다 뒤져서 다운받아야 함 + + # 3. 실행 권한 추가 및 빌드 + - name: Grant execute permission for gradlew + run: chmod +x gradlew + - name: Build with Gradle + run: ./gradlew bootJar --no-daemon + + # 4. Docker Buildx 설정 ( Docker 캐시를 위함) + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + # 5. Docker Hub 로그인 + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + # 6. Docker 이미지 빌드 및 푸시 ( 캐시 옵션 추가) + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile + push: true + tags: ${{ secrets.DOCKERHUB_USERNAME }}/loginWithJWT:latest + # Docker 레이어 캐시 설정 + cache-from: type=gha,mode=max + cache-to: type=gha,mode=max + # 이러면 변경된 부분만 새로 빌드함 \ No newline at end of file diff --git a/dockerfile b/dockerfile new file mode 100644 index 0000000..8ab88ba --- /dev/null +++ b/dockerfile @@ -0,0 +1,15 @@ +# Run stage +# 이미지 생성 +# 빌드 단계에서 생성된 JAR 파일만 복사 +FROM bellsoft/liberica-openjdk-alpine:17-jre + +WORKDIR /app + +# ci.yml 의 5단계에서 이미 빌드한 jar 파일을 복사 +COPY build/libs/*.jar app.jar + +# 애플리케이션이 사용할 포트 번호 +EXPOSE 8080 + +# 컨테이너 시작 시 실행될 명령어 +ENTRYPOINT ["java", "-jar", "app.jar"] \ No newline at end of file From 89c7d69294ca6f5fc50cd84cdfa86a93003c3055 Mon Sep 17 00:00:00 2001 From: jaemin0413 <95339052+jaemin0413@users.noreply.github.com> Date: Mon, 17 Nov 2025 23:08:44 +0900 Subject: [PATCH 02/10] =?UTF-8?q?ci=20=EB=B0=8F=20=EB=8F=84=EC=BB=A4?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20main=EC=9C=BC=EB=A1=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9812180..2d1506e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -55,4 +55,4 @@ jobs: # Docker 레이어 캐시 설정 cache-from: type=gha,mode=max cache-to: type=gha,mode=max - # 이러면 변경된 부분만 새로 빌드함 \ No newline at end of file + # 이러면 변경된 부분만 새로 빌드함 From 41cbc31a30a44e3b9cf314ab78474bae4337fbc2 Mon Sep 17 00:00:00 2001 From: jaemin0413 <95339052+jaemin0413@users.noreply.github.com> Date: Mon, 17 Nov 2025 23:16:45 +0900 Subject: [PATCH 03/10] =?UTF-8?q?ci=20=EB=B0=8F=20=EB=8F=84=EC=BB=A4?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20main=EC=9C=BC=EB=A1=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2d1506e..215c53c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,7 +4,7 @@ name: CI - Build and Push Docker Image to Docker Hub # 워크플로우 트리거 -> main 브랜치에 푸쉬할 때 on: push: - branches: [ "main" ] + branches: ["main"] # 실행될 작업 정의 jobs: @@ -24,14 +24,19 @@ jobs: with: java-version: '17' distribution: 'temurin' - cache: 'gradle' # gradle 의존성 캐싱, 이거 안 하면 한 번 받은 라이브러리는 캐시해두고 다음엔 바로 사용. - # 이거 안 하면 할 때마다 gradle 다 뒤져서 다운받아야 함 + cache: 'gradle' + # gradle 의존성 캐싱, 이거 안 하면 한 번 받은 라이브러리는 캐시해두고 다음엔 바로 사용. + # 이거 안 하면 할 때마다 gradle 다 뒤져서 다운받아야 함 # 3. 실행 권한 추가 및 빌드 - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Build with Gradle run: ./gradlew bootJar --no-daemon + - name: Run tests + run: ./gradlew test --no-daemon + # 이러면 테스트 실패시 이미지 빌드 x + # 4. Docker Buildx 설정 ( Docker 캐시를 위함) - name: Set up Docker Buildx From 69d265c9c8722e8e22153a0a7dd3095f05937238 Mon Sep 17 00:00:00 2001 From: jaemin0413 <95339052+jaemin0413@users.noreply.github.com> Date: Mon, 17 Nov 2025 23:23:34 +0900 Subject: [PATCH 04/10] =?UTF-8?q?ci=20=EB=B0=8F=20=EB=8F=84=EC=BB=A4?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20main=EC=9C=BC=EB=A1=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 215c53c..29f02d1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,9 +33,9 @@ jobs: run: chmod +x gradlew - name: Build with Gradle run: ./gradlew bootJar --no-daemon - - name: Run tests - run: ./gradlew test --no-daemon - # 이러면 테스트 실패시 이미지 빌드 x + # - name: Run tests + # run: ./gradlew test --no-daemon + # 이러면 테스트 실패시 이미지 빌드 x, 나중에 하는걸로 # 4. Docker Buildx 설정 ( Docker 캐시를 위함) From ef9aa9de627acc62e96ad64d46f4e4b3d7cb9a22 Mon Sep 17 00:00:00 2001 From: jaemin0413 <95339052+jaemin0413@users.noreply.github.com> Date: Mon, 17 Nov 2025 23:30:11 +0900 Subject: [PATCH 05/10] =?UTF-8?q?=EB=A0=88=ED=8F=AC=EC=A7=80=ED=86=A0?= =?UTF-8?q?=EB=A6=AC=EB=A5=BC=20=EC=86=8C=EB=AC=B8=EC=9E=90=EB=A1=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 29f02d1..715130a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -56,7 +56,7 @@ jobs: context: . file: ./Dockerfile push: true - tags: ${{ secrets.DOCKERHUB_USERNAME }}/loginWithJWT:latest + tags: ${{ secrets.DOCKERHUB_USERNAME }}/loginwithjwt:latest # Docker 레이어 캐시 설정 cache-from: type=gha,mode=max cache-to: type=gha,mode=max From a587fc7b04c98fae5684886dc9191ba2e6b575e9 Mon Sep 17 00:00:00 2001 From: jaemin0413 <95339052+jaemin0413@users.noreply.github.com> Date: Mon, 17 Nov 2025 23:33:00 +0900 Subject: [PATCH 06/10] jre notfound --- dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dockerfile b/dockerfile index 8ab88ba..dc4df0c 100644 --- a/dockerfile +++ b/dockerfile @@ -1,7 +1,7 @@ # Run stage # 이미지 생성 # 빌드 단계에서 생성된 JAR 파일만 복사 -FROM bellsoft/liberica-openjdk-alpine:17-jre +FROM bellsoft/liberica-openjdk-alpine:17 WORKDIR /app From 6700b3d0101f11a7721df588c5b4f343bde1a73e Mon Sep 17 00:00:00 2001 From: jaemin0413 <95339052+jaemin0413@users.noreply.github.com> Date: Tue, 2 Dec 2025 18:50:55 +0900 Subject: [PATCH 07/10] =?UTF-8?q?cd=ED=8C=8C=EC=9D=BC=20=ED=91=B8=EC=89=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 715130a..f5d3db1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -61,3 +61,31 @@ jobs: cache-from: type=gha,mode=max cache-to: type=gha,mode=max # 이러면 변경된 부분만 새로 빌드함 + +deploy: + name: Deploy to EX2 + needs: build-and-push + runs-on: ubuntu-latest + + steps: + - name: Deploy via SSH + uses: appleboy/ssh-action@v1.2.0 + with: + host: ${{secrets.EC2_HOST}} + username: ${{secrets.EC2_USER}} + key: ${{secrets.EC2_KEY}} + port: 22 + script: | + # 도커 허브에서 최신 이미지 가져오기 + sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/loginwithjwt:latest + + #기존 서버 중지 및 삭제 + sudo docker stop login-server || true + sudo docker rm login-server || true + + # 새 컨테이너 실행 + sudo docker run -d -p 8080:8080 --name login-server ${{ secrets.DOCKERHUB_USERNAME }}/loginwithjwt:latest + + # 미사용 이미지 정리 + sudo docker image prune -f + From 47413e8259ea7fa42f85ec6ef705ff13940f48af Mon Sep 17 00:00:00 2001 From: jaemin0413 <95339052+jaemin0413@users.noreply.github.com> Date: Tue, 2 Dec 2025 18:53:20 +0900 Subject: [PATCH 08/10] =?UTF-8?q?=EB=93=A4=EC=97=AC=EC=93=B0=EA=B8=B0=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 51 ++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f5d3db1..29e18cb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -62,30 +62,29 @@ jobs: cache-to: type=gha,mode=max # 이러면 변경된 부분만 새로 빌드함 -deploy: - name: Deploy to EX2 - needs: build-and-push - runs-on: ubuntu-latest + deploy: + name: Deploy to EX2 + needs: build-and-push + runs-on: ubuntu-latest - steps: - - name: Deploy via SSH - uses: appleboy/ssh-action@v1.2.0 - with: - host: ${{secrets.EC2_HOST}} - username: ${{secrets.EC2_USER}} - key: ${{secrets.EC2_KEY}} - port: 22 - script: | - # 도커 허브에서 최신 이미지 가져오기 - sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/loginwithjwt:latest - - #기존 서버 중지 및 삭제 - sudo docker stop login-server || true - sudo docker rm login-server || true - - # 새 컨테이너 실행 - sudo docker run -d -p 8080:8080 --name login-server ${{ secrets.DOCKERHUB_USERNAME }}/loginwithjwt:latest - - # 미사용 이미지 정리 - sudo docker image prune -f - + steps: + - name: Deploy via SSH + uses: appleboy/ssh-action@v1.2.0 + with: + host: ${{secrets.EC2_HOST}} + username: ${{secrets.EC2_USER}} + key: ${{secrets.EC2_KEY}} + port: 22 + script: | + # 도커 허브에서 최신 이미지 가져오기 + sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/loginwithjwt:latest + + #기존 서버 중지 및 삭제 + sudo docker stop login-server || true + sudo docker rm login-server || true + + # 새 컨테이너 실행 + sudo docker run -d -p 8080:8080 --name login-server ${{ secrets.DOCKERHUB_USERNAME }}/loginwithjwt:latest + + # 미사용 이미지 정리 + sudo docker image prune -f From b4411b66b6153513a263ac06251fa63d5f7985d0 Mon Sep 17 00:00:00 2001 From: jaemin0413 <95339052+jaemin0413@users.noreply.github.com> Date: Tue, 2 Dec 2025 19:13:48 +0900 Subject: [PATCH 09/10] =?UTF-8?q?=EB=93=A4=EC=97=AC=EC=93=B0=EA=B8=B0=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 29e18cb..c5687a3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -84,7 +84,14 @@ jobs: sudo docker rm login-server || true # 새 컨테이너 실행 - sudo docker run -d -p 8080:8080 --name login-server ${{ secrets.DOCKERHUB_USERNAME }}/loginwithjwt:latest + sudo docker run -d -p 8080:8080 \ + -e LOCAL_DB_URL='${{ secrets.DB_URL }}' \ + -e LOCAL_DB_USERNAME='${{ secrets.DB_USERNAME }}' \ + -e LOCAL_DB_PASSWORD='${{ secrets.DB_PASSWORD }}' \ + -e JWT_SECRET_KEY='${{ secrets.JWT_SECRET }}' \ + -e JWT_ACCESS_TOKEN_VALIDITY='3600000' \ + -e JWT_REFRESH_TOKEN_VALIDITY='1209600000' \ + --name login-server ${{ secrets.DOCKERHUB_USERNAME }}/loginwithjwt:latest # 미사용 이미지 정리 - sudo docker image prune -f + sudo docker image prune -f \ No newline at end of file From 9f12cbdaec7dc08502571580a28c9d0fc90753bb Mon Sep 17 00:00:00 2001 From: jaemin0413 <95339052+jaemin0413@users.noreply.github.com> Date: Tue, 2 Dec 2025 19:21:11 +0900 Subject: [PATCH 10/10] =?UTF-8?q?=EB=93=A4=EC=97=AC=EC=93=B0=EA=B8=B0=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c5687a3..79e99a2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -94,4 +94,4 @@ jobs: --name login-server ${{ secrets.DOCKERHUB_USERNAME }}/loginwithjwt:latest # 미사용 이미지 정리 - sudo docker image prune -f \ No newline at end of file + sudo docker image prune -f