From 837ef9c735958db70a68119f5d4490ca72932817 Mon Sep 17 00:00:00 2001 From: leeeunda Date: Wed, 13 Aug 2025 11:44:13 +0900 Subject: [PATCH 1/5] fix: build job --- .github/workflows/deploy.yml | 41 +++++++++++++++++------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 7246fa8..3b864a0 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,8 +1,13 @@ name: CI/CD Pipeline on: - push: + pull_request: branches: [ develop, main ] + types: + - opened + - reopened + - synchronize + - closed env: DOCKER_IMAGE: leeeunda/blockcloud-server @@ -59,44 +64,36 @@ jobs: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - # Docker Buildx 설정 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - # Docker 이미지 빌드 및 푸시 - - name: Build and push Docker image - uses: docker/build-push-action@v5 - with: - context: . - push: true - tags: | - ${{ env.DOCKER_IMAGE }}:latest - ${{ env.DOCKER_IMAGE }}:${{ github.sha }} - ${{ env.DOCKER_IMAGE }}:${{ github.event.pull_request.head.sha }} - cache-from: type=gha - cache-to: type=gha,mode=max - platforms: linux/amd64 + - name: Build and Push Docker image + run: | + docker build -t ${{ secrets.DOCKER_USERNAME }}/blockcloud-server . + docker push ${{ secrets.DOCKER_USERNAME }}/blockcloud-server deploy: needs: build-and-test runs-on: ubuntu-latest steps: - name: Deploy to EC2 (pull & replace container) + # EC2에 SSH 접속해 배포 uses: appleboy/ssh-action@v1.2.0 with: host: ${{ secrets.EC2_HOST }} username: ${{ secrets.EC2_USER }} key: ${{ secrets.EC2_SSH_KEY }} script: | - set -e - IMAGE="${{ env.DOCKER_IMAGE }}:${{ github.event.pull_request.head.sha }}" + set -euo pipefail + + IMAGE="${{ secrets.DOCKER_USERNAME }}/blockcloud-server:latest" + + echo "Pulling image: $IMAGE" docker pull "$IMAGE" # 기존 컨테이너 정리 docker stop blockcloud-app || true docker rm blockcloud-app || true - # 새 컨테이너 실행 + # 새 컨테이너 실행 (컨테이너 이름은 이미지와 달라도 됨) docker run -d \ --name blockcloud-app \ --restart unless-stopped \ @@ -114,7 +111,7 @@ jobs: echo "⏳ Waiting for application to start... ($i/30)" sleep 3 done - + echo "❌ Application failed to start properly" docker logs --tail=200 blockcloud-app || true - exit 1 \ No newline at end of file + exit 1 From 135c0a3b94814ac6ecdaa7a0ae1518970e6e3d99 Mon Sep 17 00:00:00 2001 From: leeeunda Date: Wed, 13 Aug 2025 12:02:20 +0900 Subject: [PATCH 2/5] feat: add Dockerfile --- .github/workflows/deploy.yml | 3 +- Dockerfile | 16 +++++++++++ README.md | 54 ++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 Dockerfile diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 3b864a0..01da41a 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -75,7 +75,6 @@ jobs: runs-on: ubuntu-latest steps: - name: Deploy to EC2 (pull & replace container) - # EC2에 SSH 접속해 배포 uses: appleboy/ssh-action@v1.2.0 with: host: ${{ secrets.EC2_HOST }} @@ -93,7 +92,7 @@ jobs: docker stop blockcloud-app || true docker rm blockcloud-app || true - # 새 컨테이너 실행 (컨테이너 이름은 이미지와 달라도 됨) + # 새 컨테이너 실행 docker run -d \ --name blockcloud-app \ --restart unless-stopped \ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b48b57a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +# ---------- Build ---------- +FROM gradle:8.7-jdk21 AS build +WORKDIR /app +COPY gradlew ./ +COPY gradle gradle +COPY build.gradle settings.gradle ./ +RUN ./gradlew dependencies --no-daemon || true +COPY src src +RUN ./gradlew clean bootJar -x test -x jacocoTestCoverageVerification -x jacocoTestReport --no-daemon + +# ---------- Runtime ---------- +FROM eclipse-temurin:21-jre +WORKDIR /app +COPY --from=build /app/build/libs/*.jar app.jar +EXPOSE 8080 +ENTRYPOINT ["java","-jar","app.jar"] diff --git a/README.md b/README.md index 4ba68da..0e4d7ff 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,8 @@ BlockCloud is a Spring Boot-based backend service designed to support the core f ## 🏁 Quick Start +### 로컬 개발 환경 + ```bash git clone https://github.com/your-username/blockcloud-backend.git cd blockcloud-backend @@ -24,6 +26,58 @@ cd blockcloud-backend Visit: [http://localhost:8080](http://localhost:8080) +### Docker를 사용한 실행 + +```bash +# 개발 환경 실행 +docker-compose --profile dev up -d + +# 프로덕션 환경 실행 +docker-compose up -d +``` + +## 🚀 배포 + +### 자동 배포 (GitHub Actions) + +1. GitHub Secrets 설정: + - `HOST`: 서버 IP 주소 + - `USERNAME`: SSH 사용자명 + - `SSH_KEY`: SSH 개인키 + - `PORT`: SSH 포트 (기본값: 22) + +2. main 브랜치에 push하면 자동으로 배포됩니다. + +### 수동 배포 + +```bash +# 배포 스크립트 실행 +chmod +x scripts/deploy.sh +./scripts/deploy.sh production latest +``` + +## 🔧 환경 변수 + +프로젝트 루트에 `.env` 파일을 생성하고 다음 변수들을 설정하세요: + +```bash +# Spring Boot 프로필 +SPRING_PROFILES_ACTIVE=dev + +# 데이터베이스 설정 +SPRING_DATASOURCE_URL=jdbc:postgresql://localhost:5432/blockcloud_dev +SPRING_DATASOURCE_USERNAME=blockcloud +SPRING_DATASOURCE_PASSWORD=password + +# JWT 설정 +JWT_SECRET=your-jwt-secret-key-here +JWT_EXPIRATION=86400000 + +# OAuth2 설정 +GOOGLE_CLIENT_ID=your-google-client-id +GOOGLE_CLIENT_SECRET=your-google-client-secret +``` + --- ## 📄 License From 59aa64f957408c4c8ee399674ae5a855ef02e065 Mon Sep 17 00:00:00 2001 From: leeeunda Date: Wed, 13 Aug 2025 12:06:17 +0900 Subject: [PATCH 3/5] fix: add version.properties file --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index b48b57a..028a6fd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ FROM gradle:8.7-jdk21 AS build WORKDIR /app COPY gradlew ./ COPY gradle gradle -COPY build.gradle settings.gradle ./ +COPY build.gradle settings.gradle version.properties ./ RUN ./gradlew dependencies --no-daemon || true COPY src src RUN ./gradlew clean bootJar -x test -x jacocoTestCoverageVerification -x jacocoTestReport --no-daemon From fb05a0b6fbddeeb9f5cf07bf4831849fb36be24e Mon Sep 17 00:00:00 2001 From: leeeunda Date: Wed, 13 Aug 2025 12:12:52 +0900 Subject: [PATCH 4/5] fix: securityConfig to accept helth check endpoint --- .github/workflows/deploy.yml | 14 ++++++++++---- .../java/com/blockcloud/config/SecurityConfig.java | 3 ++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 01da41a..3c64da2 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -102,15 +102,21 @@ jobs: "$IMAGE" # 헬스체크 - for i in {1..30}; do + echo "🏥 헬스체크 시작 (최대 60초 대기)..." + for i in {1..20}; do if curl -fsS http://127.0.0.1:8080/actuator/health >/dev/null 2>&1; then echo "✅ Application is UP and healthy!" + echo "🎉 배포 성공!" exit 0 + else + echo "⏳ Waiting for application to start... (${i}/20)" + sleep 3 fi - echo "⏳ Waiting for application to start... ($i/30)" - sleep 3 done echo "❌ Application failed to start properly" - docker logs --tail=200 blockcloud-app || true + echo "📊 컨테이너 상태:" + docker ps -a | grep blockcloud-app || true + echo "📋 컨테이너 로그:" + docker logs --tail=100 blockcloud-app || true exit 1 diff --git a/src/main/java/com/blockcloud/config/SecurityConfig.java b/src/main/java/com/blockcloud/config/SecurityConfig.java index ebc2acf..2e71b3e 100644 --- a/src/main/java/com/blockcloud/config/SecurityConfig.java +++ b/src/main/java/com/blockcloud/config/SecurityConfig.java @@ -53,7 +53,8 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { "/error", "/login/oauth2/code/google", "/swagger-ui/**", - "/v3/api-docs/**" + "/v3/api-docs/**", + "/actuator/**" ).permitAll() .anyRequest().authenticated() ) From 4efbf9d0e296eaa97b30415e36a437bcb24483b1 Mon Sep 17 00:00:00 2001 From: leeeunda Date: Wed, 13 Aug 2025 12:17:07 +0900 Subject: [PATCH 5/5] fix: git actions trigger --- .github/workflows/deploy.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 3c64da2..eefe77a 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,13 +1,8 @@ name: CI/CD Pipeline on: - pull_request: + push: branches: [ develop, main ] - types: - - opened - - reopened - - synchronize - - closed env: DOCKER_IMAGE: leeeunda/blockcloud-server