From 9d99e481b6553ca775629103eb3e306cf365ebbc Mon Sep 17 00:00:00 2001 From: can019 Date: Wed, 27 Aug 2025 16:18:09 +0900 Subject: [PATCH 01/11] feat: Docker image push spring (experimental) --- .github/workflows/ci-java.yml | 83 ++++++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci-java.yml b/.github/workflows/ci-java.yml index 1a4faaa2..ae1ec482 100644 --- a/.github/workflows/ci-java.yml +++ b/.github/workflows/ci-java.yml @@ -44,4 +44,85 @@ jobs: - name: Run Spotless Check run: ./gradlew spotlessCheck - working-directory: apps/user-service \ No newline at end of file + working-directory: apps/user-service + + build: + name: Build + runs-on: ubuntu-latest + needs: spotless-check + strategy: + matrix: + java-version: [ "21" ] + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up JDK ${{ matrix.java-version }} + uses: actions/setup-java@v4 + with: + java-version: '${{ matrix.java-version }}' + distribution: 'temurin' + cache: 'gradle' + + - name: Grant execute permission for Gradle wrapper + run: chmod +x ./gradlew + working-directory: apps/user-service + + - name: Run Gradle Build + run: ./gradlew build -x test + working-directory: apps/user-service + +# - name: Run Tests +# run: | +# if [ "${{ github.base_ref }}" == "main" ]; then +# ./gradlew test +# else +# ./gradlew prTest +# fi +# working-directory: apps/user-service + - name: Upload build artifacts +# if: matrix.java-version == '21' && github.ref == 'refs/heads/main' && github.event_name == 'push' + uses: actions/upload-artifact@v4 + with: + name: build-artifacts + path: apps/user-service/build/libs/ + + docker: + name: Build Spring Boot Docker Image and push to registry + runs-on: ubuntu-latest +# if: github.ref == 'refs/heads/main' && github.event_name == 'push' + needs: + - build + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Download build artifacts (JAR) + uses: actions/download-artifact@v4 + with: + name: build-artifacts + path: apps/user-service/build/libs/ + + - name: Login to Docker Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push Docker image + id: docker_build + uses: docker/build-push-action@v5 + with: + context: ./apps/user-service + push: true + tags: | + ghcr.io/${{ github.repository }}/icebang-springboot-app:latest + ghcr.io/${{ github.repository }}/icebang-springboot-app:${{ github.sha }} + + - name: Analyze image layers + run: | + echo "=== Image Layer Analysis ===" + docker history ghcr.io/${{ github.repository }}/mvp-app:latest --human --no-trunc \ No newline at end of file From 4a8edc1ef57005a2c32ed9a44cedb918abeb5811 Mon Sep 17 00:00:00 2001 From: can019 Date: Wed, 27 Aug 2025 16:21:02 +0900 Subject: [PATCH 02/11] =?UTF-8?q?chore:=20trigger=EB=A5=BC=20=EC=9C=84?= =?UTF-8?q?=ED=95=9C=20=EC=9E=84=EC=8B=9C=20commit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/user-service/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/user-service/Dockerfile b/apps/user-service/Dockerfile index 3fb9d854..d54c0a99 100644 --- a/apps/user-service/Dockerfile +++ b/apps/user-service/Dockerfile @@ -39,4 +39,4 @@ COPY --from=builder /app/build/libs/glt-korea-0.0.1-SNAPSHOT.jar ./app.jar EXPOSE 8080 # 컨테이너 시작 시 실행될 명령어를 정의합니다. -CMD ["java", "-jar", "app.jar"] \ No newline at end of file +CMD ["java", "-jar", "app.jar"] From f2658350904ca49696dbdb9e49bfdaadfcb6f875 Mon Sep 17 00:00:00 2001 From: can019 Date: Wed, 27 Aug 2025 16:28:42 +0900 Subject: [PATCH 03/11] fix: Dockerfile (spring) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit docker 내부에서 build 없이 build 산출물 사용 --- apps/user-service/Dockerfile | 36 +----------------------------------- 1 file changed, 1 insertion(+), 35 deletions(-) diff --git a/apps/user-service/Dockerfile b/apps/user-service/Dockerfile index d54c0a99..116a7161 100644 --- a/apps/user-service/Dockerfile +++ b/apps/user-service/Dockerfile @@ -1,42 +1,8 @@ -# 1단계: 빌드 스테이지 -# Java 21 JDK가 포함된 경량 이미지를 사용합니다. -# 이 단계에서 애플리케이션을 빌드합니다. -FROM openjdk:21-jdk-slim AS builder - -# 컨테이너 내부에 작업 디렉토리를 생성하고 설정합니다. -WORKDIR /app - -# Gradle Wrapper, 설정 파일, 소스 코드를 복사합니다. -# Docker의 레이어 캐싱을 활용하여 빌드 속도를 높입니다. -COPY gradlew . -COPY gradle/ gradle/ -COPY build.gradle . -COPY settings.gradle . - -# 애플리케이션 소스 코드를 복사합니다. -COPY src src - -# 애플리케이션을 빌드하여 실행 가능한 JAR 파일을 만듭니다. -# `-x test`는 이미지 빌드 시 테스트를 건너뛰는 명령입니다. -RUN ./gradlew clean build -x test - ---- - -# 2단계: 실행 스테이지 -# 애플리케이션 실행에 필요한 Java 21 JRE만 포함된 경량 이미지를 사용합니다. FROM openjdk:21-jre-slim -# 컨테이너 내부의 작업 디렉토리를 설정합니다. WORKDIR /app -# 빌드 스테이지에서 생성된 JAR 파일을 복사합니다. -# `--from=builder` 옵션을 사용하여 첫 번째 단계에서 빌드된 JAR만 가져옵니다. -# 파일명은 `group`, `version`에 따라 `glt-korea-0.0.1-SNAPSHOT.jar`가 되므로, -# 이를 `app.jar`라는 간단한 이름으로 변경합니다. -COPY --from=builder /app/build/libs/glt-korea-0.0.1-SNAPSHOT.jar ./app.jar +COPY build/libs/*.jar app.jar -# 애플리케이션이 외부 요청을 받을 포트를 노출합니다. EXPOSE 8080 - -# 컨테이너 시작 시 실행될 명령어를 정의합니다. CMD ["java", "-jar", "app.jar"] From e8be80065253cbc40d804757884f45ecd35446be Mon Sep 17 00:00:00 2001 From: can019 Date: Wed, 27 Aug 2025 16:32:03 +0900 Subject: [PATCH 04/11] =?UTF-8?q?chore:=20repository=20=EC=9D=B4=EB=A6=84?= =?UTF-8?q?=20=EC=86=8C=EB=AC=B8=EC=9E=90=EB=A1=9C=20=EA=B0=95=EC=A0=9C=20?= =?UTF-8?q?=EC=B9=98=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci-java.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci-java.yml b/.github/workflows/ci-java.yml index ae1ec482..b5a95cfe 100644 --- a/.github/workflows/ci-java.yml +++ b/.github/workflows/ci-java.yml @@ -112,15 +112,17 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Set repo lowercase + run: echo "REPO_LC=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV + - name: Build and push Docker image - id: docker_build uses: docker/build-push-action@v5 with: context: ./apps/user-service push: true tags: | - ghcr.io/${{ github.repository }}/icebang-springboot-app:latest - ghcr.io/${{ github.repository }}/icebang-springboot-app:${{ github.sha }} + ghcr.io/${{ env.REPO_LC }}/user-service:latest + ghcr.io/${{ env.REPO_LC }}/user-service:${{ github.sha }} - name: Analyze image layers run: | From cce510bd1ee49c11cd6f46713ee43073907b1277 Mon Sep 17 00:00:00 2001 From: can019 Date: Wed, 27 Aug 2025 16:35:06 +0900 Subject: [PATCH 05/11] =?UTF-8?q?fix:=20DockerFile=20base=20image=20temuri?= =?UTF-8?q?n=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/user-service/Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/user-service/Dockerfile b/apps/user-service/Dockerfile index 116a7161..e3fb24a4 100644 --- a/apps/user-service/Dockerfile +++ b/apps/user-service/Dockerfile @@ -1,8 +1,9 @@ -FROM openjdk:21-jre-slim +FROM eclipse-temurin:21-jre WORKDIR /app COPY build/libs/*.jar app.jar EXPOSE 8080 + CMD ["java", "-jar", "app.jar"] From f663862bede248ae4b951dae303142886582bd7a Mon Sep 17 00:00:00 2001 From: can019 Date: Wed, 27 Aug 2025 16:40:48 +0900 Subject: [PATCH 06/11] =?UTF-8?q?fix:=20ci=EC=97=90=EC=84=9C=20image=20lay?= =?UTF-8?q?er=20=EB=B6=84=EC=84=9D=20=EC=8B=9C=20image=EC=9D=B4=EB=A6=84?= =?UTF-8?q?=EC=9D=B4=20=EC=9E=98=EB=AA=BB=EB=90=98=EC=97=88=EB=8D=98=20?= =?UTF-8?q?=EB=AC=B8=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci-java.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-java.yml b/.github/workflows/ci-java.yml index b5a95cfe..c85de3d5 100644 --- a/.github/workflows/ci-java.yml +++ b/.github/workflows/ci-java.yml @@ -127,4 +127,4 @@ jobs: - name: Analyze image layers run: | echo "=== Image Layer Analysis ===" - docker history ghcr.io/${{ github.repository }}/mvp-app:latest --human --no-trunc \ No newline at end of file + docker history ghcr.io/${{ env.REPO_LC }}/user-service:latest --human --no-trunc \ No newline at end of file From 68371f4159a0f1849e2061e00bcca6738f47a891 Mon Sep 17 00:00:00 2001 From: can019 Date: Wed, 27 Aug 2025 16:47:52 +0900 Subject: [PATCH 07/11] feat: Ec2 deploy (java) --- .github/workflows/deploy-java.yml | 73 +++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 .github/workflows/deploy-java.yml diff --git a/.github/workflows/deploy-java.yml b/.github/workflows/deploy-java.yml new file mode 100644 index 00000000..8d373dc1 --- /dev/null +++ b/.github/workflows/deploy-java.yml @@ -0,0 +1,73 @@ +name: Deploy + +on: + workflow_dispatch: + push: + tags: + - 'v*' + +jobs: + deploy: + name: Deploy to AWS EC2 + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Set repo lowercase + run: echo "REPO_LC=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV + + - name: Copy docker compose files to EC2 + uses: appleboy/scp-action@v0.1.7 + with: + host: ${{ secrets.SERVER_HOST }} + username: ${{ secrets.SERVER_USER }} + key: ${{ secrets.SERVER_SSH_KEY }} + source: "docker/production/docker-compose.yml" + target: "~/app" + + - name: Deploy on EC2 + uses: appleboy/ssh-action@v1.0.3 + with: + host: ${{ secrets.SERVER_HOST }} + username: ${{ secrets.SERVER_USER }} + key: ${{ secrets.SERVER_SSH_KEY }} + script: | + cd ~/app/docker/production + echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin + + docker pull ghcr.io/${{ env.REPO_LC }}/user-service:latest + + docker compose down + docker compose up -d + + sleep 10 + docker compose ps + + docker image prune -f + +# - name: Send Discord notification - Success +# if: success() +# uses: Ilshidur/action-discord@master +# env: +# DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_URL }} +# with: +# args: | +# **배포 성공** +# **Repository:** ${{ env.REPO_LC }} +# **Tag:** ${{ github.ref_name }} +# **Server:** ${{ secrets.SERVER_HOST }} +# **Status:** Success! +# +# - name: Send Discord notification - Failure +# if: failure() +# uses: Ilshidur/action-discord@master +# env: +# DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_URL }} +# with: +# args: | +# **배포 실패** +# **Repository:** ${{ env.REPO_LC }} +# **Tag:** ${{ github.ref_name }} +# **Error:** 배포 중 오류가 발생했습니다. +# **Check:** ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} From 05c08a03e5d68c521771acc8bb5e873ef3adcb68 Mon Sep 17 00:00:00 2001 From: can019 Date: Wed, 27 Aug 2025 16:53:21 +0900 Subject: [PATCH 08/11] chore: Deploy --- .github/workflows/deploy-java.yml | 3 ++- docker/production/docker-compose.yml | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy-java.yml b/.github/workflows/deploy-java.yml index 8d373dc1..9d1e2e03 100644 --- a/.github/workflows/deploy-java.yml +++ b/.github/workflows/deploy-java.yml @@ -30,7 +30,8 @@ jobs: uses: appleboy/ssh-action@v1.0.3 with: host: ${{ secrets.SERVER_HOST }} - username: ${{ secrets.SERVER_USER }} +# username: ${{ secrets.SERVER_USER }} + username: ubuntu key: ${{ secrets.SERVER_SSH_KEY }} script: | cd ~/app/docker/production diff --git a/docker/production/docker-compose.yml b/docker/production/docker-compose.yml index e69de29b..3d417fe8 100644 --- a/docker/production/docker-compose.yml +++ b/docker/production/docker-compose.yml @@ -0,0 +1,17 @@ +version: "3.9" + +services: + user-service: + image: ghcr.io/kernel180-be12/final-4team-icebang/user-service:latest + container_name: user-service + restart: always + ports: + - "80:8080" + env_file: + - .env + networks: + - app-network + +networks: + app-network: + driver: bridge From 04168b4c0a5b5a5fc7642a4fbc7c350ca4dbcdb2 Mon Sep 17 00:00:00 2001 From: can019 Date: Wed, 27 Aug 2025 16:56:37 +0900 Subject: [PATCH 09/11] =?UTF-8?q?chore:=20=EC=9E=84=EC=8B=9C=EB=A1=9C=20de?= =?UTF-8?q?ploy=20workflow=20=EC=8B=A4=ED=96=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy-java.yml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/workflows/deploy-java.yml b/.github/workflows/deploy-java.yml index 9d1e2e03..c5827da2 100644 --- a/.github/workflows/deploy-java.yml +++ b/.github/workflows/deploy-java.yml @@ -1,11 +1,16 @@ name: Deploy +#on: +# workflow_dispatch: +# push: +# tags: +# - 'v*' on: - workflow_dispatch: - push: - tags: - - 'v*' - + workflow_dispatch: # 수동 실행 가능 + workflow_run: # 다른 워크플로우 완료 후 트리거 + workflows: ["CI (Java)"] # CI 워크플로우 이름 + types: + - completed jobs: deploy: name: Deploy to AWS EC2 From d14cea1cb19407e8bdda103f1fd29e3080e8c762 Mon Sep 17 00:00:00 2001 From: can019 Date: Wed, 27 Aug 2025 16:59:23 +0900 Subject: [PATCH 10/11] chore: restore workflow dispatch --- .github/workflows/deploy-java.yml | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/.github/workflows/deploy-java.yml b/.github/workflows/deploy-java.yml index c5827da2..9d1e2e03 100644 --- a/.github/workflows/deploy-java.yml +++ b/.github/workflows/deploy-java.yml @@ -1,16 +1,11 @@ name: Deploy -#on: -# workflow_dispatch: -# push: -# tags: -# - 'v*' on: - workflow_dispatch: # 수동 실행 가능 - workflow_run: # 다른 워크플로우 완료 후 트리거 - workflows: ["CI (Java)"] # CI 워크플로우 이름 - types: - - completed + workflow_dispatch: + push: + tags: + - 'v*' + jobs: deploy: name: Deploy to AWS EC2 From f2a54a458f7cd4e882f72af30f4cad7f412904ab Mon Sep 17 00:00:00 2001 From: can019 Date: Wed, 27 Aug 2025 17:01:10 +0900 Subject: [PATCH 11/11] =?UTF-8?q?chore:=20ci=20trigger=20=EC=A1=B0?= =?UTF-8?q?=EA=B1=B4=20=EC=9B=90=EB=B3=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit main일 시 docker image push, artifact upload --- .github/workflows/ci-java.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-java.yml b/.github/workflows/ci-java.yml index c85de3d5..42ac78b0 100644 --- a/.github/workflows/ci-java.yml +++ b/.github/workflows/ci-java.yml @@ -82,7 +82,7 @@ jobs: # fi # working-directory: apps/user-service - name: Upload build artifacts -# if: matrix.java-version == '21' && github.ref == 'refs/heads/main' && github.event_name == 'push' + if: matrix.java-version == '21' && github.ref == 'refs/heads/main' && github.event_name == 'push' uses: actions/upload-artifact@v4 with: name: build-artifacts @@ -91,7 +91,7 @@ jobs: docker: name: Build Spring Boot Docker Image and push to registry runs-on: ubuntu-latest -# if: github.ref == 'refs/heads/main' && github.event_name == 'push' + if: github.ref == 'refs/heads/main' && github.event_name == 'push' needs: - build