From 77c07305f3039c2aa2a2e3911339aba3a43ec4ca Mon Sep 17 00:00:00 2001 From: UNGGU0704 Date: Fri, 13 Jun 2025 09:58:13 +0900 Subject: [PATCH] =?UTF-8?q?ci:=20analytics-ci=20CD=20=EC=97=B0=EA=B2=B0?= =?UTF-8?q?=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/analytics-ci.yml | 237 +++++++++++++++++++---------- 1 file changed, 154 insertions(+), 83 deletions(-) diff --git a/.github/workflows/analytics-ci.yml b/.github/workflows/analytics-ci.yml index a48a986..e51c3da 100644 --- a/.github/workflows/analytics-ci.yml +++ b/.github/workflows/analytics-ci.yml @@ -20,91 +20,162 @@ on: env: ACR_NAME: acrdigitalgarage03 IMAGE_NAME: hiorder/analytics - + MANIFEST_REPO: dg04-hi/hi-manifest + MANIFEST_FILE_PATH: analytics/deployment.yml + jobs: build-and-push: runs-on: ubuntu-latest - + steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up JDK 21 - uses: actions/setup-java@v4 - with: - java-version: '21' - distribution: 'temurin' - - - name: Setup Gradle - uses: gradle/actions/setup-gradle@v3 - with: - gradle-version: '8.13' - - - name: Cache Gradle packages - uses: actions/cache@v4 - with: - path: | - ~/.gradle/caches - ~/.gradle/wrapper - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} - restore-keys: | - ${{ runner.os }}-gradle- + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + java-version: '21' + distribution: 'temurin' + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + with: + gradle-version: '8.13' + + - name: Cache Gradle packages + uses: actions/cache@v4 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + ${{ runner.os }}-gradle- + + - name: Generate Gradle Wrapper + run: | + echo "Generating gradle wrapper..." + gradle wrapper --gradle-version 8.13 + chmod +x gradlew + echo "Testing gradle wrapper..." + ./gradlew --version + + - name: Build analytics module with dependencies + run: ./gradlew analytics:build -x test + + - name: Run analytics tests + run: ./gradlew analytics:test + + - name: Generate build timestamp + id: timestamp + run: echo "BUILD_TIME=$(date +'%y%m%d%H%M')" >> $GITHUB_OUTPUT + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to Azure Container Registry + uses: azure/docker-login@v1 + with: + login-server: ${{ env.ACR_NAME }}.azurecr.io + username: ${{ secrets.ACR_USERNAME }} + password: ${{ secrets.ACR_PASSWORD }} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + file: ./analytics/Dockerfile + platforms: linux/amd64 + push: true + tags: | + ${{ env.ACR_NAME }}.azurecr.io/${{ env.IMAGE_NAME }}:${{ steps.timestamp.outputs.BUILD_TIME }} + ${{ env.ACR_NAME }}.azurecr.io/${{ env.IMAGE_NAME }}:latest + + - name: Output image tags + run: | + echo "πŸŽ‰ Image pushed successfully!" + echo "πŸ“¦ Image: ${{ env.ACR_NAME }}.azurecr.io/${{ env.IMAGE_NAME }}" + echo "🏷️ Tags: ${{ steps.timestamp.outputs.BUILD_TIME }}, latest" + + # πŸš€ Manifest λ ˆν¬μ§€ν† λ¦¬ μ—…λ°μ΄νŠΈ 단계 μΆ”κ°€ + - name: Checkout manifest repository + uses: actions/checkout@v4 + with: + repository: ${{ env.MANIFEST_REPO }} + token: ${{ secrets.MANIFEST_REPO_TOKEN }} + path: manifest-repo + + - name: Install yq + run: | + sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 + sudo chmod +x /usr/local/bin/yq + + - name: Update deployment image tag + run: | + cd manifest-repo + NEW_IMAGE="${{ env.ACR_NAME }}.azurecr.io/${{ env.IMAGE_NAME }}:${{ steps.timestamp.outputs.BUILD_TIME }}" + echo "Updating image tag to: $NEW_IMAGE" - - name: Generate Gradle Wrapper - run: | - echo "Generating gradle wrapper..." - gradle wrapper --gradle-version 8.13 - chmod +x gradlew - echo "Testing gradle wrapper..." - ./gradlew --version - - - name: Build analytics module with dependencies - run: ./gradlew analytics:build -x test - - - name: Run analytics tests - run: ./gradlew analytics:test - - - name: Generate build timestamp - id: timestamp - run: echo "BUILD_TIME=$(date +'%y%m%d%H%M')" >> $GITHUB_OUTPUT - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Log in to Azure Container Registry - uses: azure/docker-login@v1 - with: - login-server: ${{ env.ACR_NAME }}.azurecr.io - username: ${{ secrets.ACR_USERNAME }} - password: ${{ secrets.ACR_PASSWORD }} - - - name: Build and push Docker image - uses: docker/build-push-action@v5 - with: - context: . - file: ./analytics/Dockerfile - platforms: linux/amd64 - push: true - tags: | - ${{ env.ACR_NAME }}.azurecr.io/${{ env.IMAGE_NAME }}:${{ steps.timestamp.outputs.BUILD_TIME }} - ${{ env.ACR_NAME }}.azurecr.io/${{ env.IMAGE_NAME }}:latest - - - name: Output image tags - run: | - echo "πŸŽ‰ Image pushed successfully!" - echo "πŸ“¦ Image: ${{ env.ACR_NAME }}.azurecr.io/${{ env.IMAGE_NAME }}" - echo "🏷️ Tags: ${{ steps.timestamp.outputs.BUILD_TIME }}, latest" - - - name: Upload test results - uses: actions/upload-artifact@v4 - if: always() - with: - name: analytics-test-results - path: analytics/build/reports/tests/test/ - - - name: Upload build artifacts - uses: actions/upload-artifact@v4 - if: success() - with: - name: analytics-jar - path: analytics/build/libs/*.jar + # deployment.ymlμ—μ„œ 이미지 νƒœκ·Έ μ—…λ°μ΄νŠΈ + yq eval '.spec.template.spec.containers[0].image = "'$NEW_IMAGE'"' -i ${{ env.MANIFEST_FILE_PATH }} + + # 변경사항 확인 + echo "Updated deployment.yml:" + cat ${{ env.MANIFEST_FILE_PATH }} + + - name: Commit and push changes + run: | + cd manifest-repo + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + + git add ${{ env.MANIFEST_FILE_PATH }} + + if git diff --staged --quiet; then + echo "No changes to commit" + else + git commit -m "πŸš€ Update analytics image tag to ${{ steps.timestamp.outputs.BUILD_TIME }} + + - Updated by: ${{ github.actor }} + - Triggered by: ${{ github.event_name }} + - Source commit: ${{ github.sha }} + - Build time: ${{ steps.timestamp.outputs.BUILD_TIME }}" + + git push + echo "βœ… Successfully updated manifest repository" + fi + + - name: Upload test results + uses: actions/upload-artifact@v4 + if: always() + with: + name: analytics-test-results + path: analytics/build/reports/tests/test/ + + - name: Upload build artifacts + uses: actions/upload-artifact@v4 + if: success() + with: + name: analytics-jar + path: analytics/build/libs/*.jar + + # 🎯 배포 μ™„λ£Œ μ•Œλ¦Ό + - name: Deployment summary + if: success() + run: | + echo "## πŸš€ Analytics Service Deployment Summary" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "### πŸ“¦ Container Image" >> $GITHUB_STEP_SUMMARY + echo "- **Registry**: ${{ env.ACR_NAME }}.azurecr.io" >> $GITHUB_STEP_SUMMARY + echo "- **Image**: ${{ env.IMAGE_NAME }}" >> $GITHUB_STEP_SUMMARY + echo "- **Tag**: ${{ steps.timestamp.outputs.BUILD_TIME }}" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "### πŸ”„ ArgoCD Sync" >> $GITHUB_STEP_SUMMARY + echo "- **Manifest Repo**: https://github.com/${{ env.MANIFEST_REPO }}" >> $GITHUB_STEP_SUMMARY + echo "- **Updated File**: ${{ env.MANIFEST_FILE_PATH }}" >> $GITHUB_STEP_SUMMARY + echo "- **ArgoCD will automatically sync the new image**" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "### ⏱️ Build Info" >> $GITHUB_STEP_SUMMARY + echo "- **Build Time**: $(date)" >> $GITHUB_STEP_SUMMARY + echo "- **Triggered By**: ${{ github.actor }}" >> $GITHUB_STEP_SUMMARY + echo "- **Event**: ${{ github.event_name }}" >> $GITHUB_STEP_SUMMARY \ No newline at end of file