diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 7246fa8..eefe77a 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -59,23 +59,11 @@ 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 @@ -88,8 +76,11 @@ jobs: 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" # 기존 컨테이너 정리 @@ -106,15 +97,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 - exit 1 \ No newline at end of file + echo "📊 컨테이너 상태:" + docker ps -a | grep blockcloud-app || true + echo "📋 컨테이너 로그:" + docker logs --tail=100 blockcloud-app || true + exit 1 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..028a6fd --- /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 version.properties ./ +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 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() )