diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index 6cd8c62..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,44 +0,0 @@ -name: CI - -on: - pull_request: - branches: - - main - - dev - push: - branches: - - main - - dev - -jobs: - build-and-test: - runs-on: ubuntu-latest - env: - FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true - - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Set up JDK 21 - uses: actions/setup-java@v4 - with: - java-version: '21' - distribution: 'temurin' - - - name: Set up Gradle - uses: gradle/actions/setup-gradle@v3 - - - name: Grant execute permission to gradlew - run: chmod +x gradlew - - - name: Build & Test - run: ./gradlew build --no-daemon - - - name: Upload test report (on failure) - if: failure() - uses: actions/upload-artifact@v4 - with: - name: test-report - path: build/reports/tests/ - retention-days: 7 diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..9e24a64 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,99 @@ +name: CI/CD - Build, Test, and Deploy + +on: + pull_request: + branches: + - main + - dev + push: + branches: + - main + - dev + workflow_dispatch: + +permissions: + id-token: write + contents: read + +env: + AWS_REGION: ap-northeast-2 + ECR_REPOSITORY: first-ticket/config-server + +jobs: + # 1) 빌드 + 테스트 (모든 PR/push에서 실행) + build-and-test: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v6 + + - name: Set up JDK 21 + uses: actions/setup-java@v5 + with: + java-version: '21' + distribution: 'temurin' + + - name: Set up Gradle + uses: gradle/actions/setup-gradle@v6 + + - name: Grant execute permission to gradlew + run: chmod +x gradlew + + - name: Build & Test + run: ./gradlew build --no-daemon + + - name: Upload test report (on failure) + if: failure() + uses: actions/upload-artifact@v5 + with: + name: test-report + path: build/reports/tests/ + retention-days: 7 + + # 2) ECR 푸시 (main 브랜치 push 시) + push-to-ecr: + needs: build-and-test + if: | + github.event_name == 'push' && github.ref == 'refs/heads/main' + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v6 + + - uses: actions/setup-java@v5 + with: + java-version: '21' + distribution: 'temurin' + + - name: Grant execute permission for gradlew + run: chmod +x ./gradlew + + - name: Build with Gradle + run: ./gradlew clean build -x test + + - name: Configure AWS credentials (OIDC) + uses: aws-actions/configure-aws-credentials@v6 + with: + role-to-assume: ${{ secrets.AWS_ROLE_ARN }} + aws-region: ${{ env.AWS_REGION }} + + - name: Login to Amazon ECR + id: ecr-login + uses: aws-actions/amazon-ecr-login@v2 + + - name: Build, tag, and push image to ECR + env: + REGISTRY: ${{ steps.ecr-login.outputs.registry }} + IMAGE_TAG: ${{ github.sha }} + run: | + docker build --platform linux/amd64 \ + -t $REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG \ + -t $REGISTRY/$ECR_REPOSITORY:latest . + docker push $REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG + docker push $REGISTRY/$ECR_REPOSITORY:latest + + - name: Show pushed image + run: | + echo "✅ Pushed: $ECR_REPOSITORY:${{ github.sha }}" + echo "✅ Pushed: $ECR_REPOSITORY:latest" diff --git a/build.gradle b/build.gradle index 5050b68..920c22e 100644 --- a/build.gradle +++ b/build.gradle @@ -22,13 +22,24 @@ ext { } dependencies { + // Spring Boot implementation 'org.springframework.boot:spring-boot-starter-actuator' implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.boot:spring-boot-starter-web' + + // Spring Cloud implementation 'org.springframework.cloud:spring-cloud-config-server' implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client' + + // 모니터링 + implementation 'org.springframework.boot:spring-boot-starter-actuator' + implementation 'io.micrometer:micrometer-registry-prometheus' + + // Lombok compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' + + // Test testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.security:spring-security-test' testCompileOnly 'org.projectlombok:lombok' diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index 3731969..ca42f27 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -1,12 +1,22 @@ server: port: 8080 +spring: + cloud: + inetutils: + preferred-networks: + - 10\. + - 172\. + - 192\.168\. + eureka: client: enabled: true service-url: defaultZone: ${EUREKA_URL:http://eureka-server:8761/eureka/} + instance: + prefer-ip-address: true logging: level: - org.springframework.cloud.config: INFO \ No newline at end of file + org.springframework.cloud.config: INFO diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 3db03ef..d4fee04 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -19,6 +19,15 @@ spring: search-paths: - '{application}' +management: + endpoints: + web: + exposure: + include: prometheus, health, info + endpoint: + prometheus: + access: read-only + logging: level: org.springframework.cloud.config: INFO