ci: analytics-ci CD 연결설정

This commit is contained in:
UNGGU0704 2025-06-13 09:58:13 +09:00
parent c7ffb5ae3d
commit 77c07305f3

View File

@ -20,91 +20,162 @@ on:
env: env:
ACR_NAME: acrdigitalgarage03 ACR_NAME: acrdigitalgarage03
IMAGE_NAME: hiorder/analytics IMAGE_NAME: hiorder/analytics
MANIFEST_REPO: dg04-hi/hi-manifest
MANIFEST_FILE_PATH: analytics/deployment.yml
jobs: jobs:
build-and-push: build-and-push:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Set up JDK 21 - name: Set up JDK 21
uses: actions/setup-java@v4 uses: actions/setup-java@v4
with: with:
java-version: '21' java-version: '21'
distribution: 'temurin' distribution: 'temurin'
- name: Setup Gradle - name: Setup Gradle
uses: gradle/actions/setup-gradle@v3 uses: gradle/actions/setup-gradle@v3
with: with:
gradle-version: '8.13' gradle-version: '8.13'
- name: Cache Gradle packages - name: Cache Gradle packages
uses: actions/cache@v4 uses: actions/cache@v4
with: with:
path: | path: |
~/.gradle/caches ~/.gradle/caches
~/.gradle/wrapper ~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: | restore-keys: |
${{ runner.os }}-gradle- ${{ 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 # deployment.yml에서 이미지 태그 업데이트
run: | yq eval '.spec.template.spec.containers[0].image = "'$NEW_IMAGE'"' -i ${{ env.MANIFEST_FILE_PATH }}
echo "Generating gradle wrapper..."
gradle wrapper --gradle-version 8.13 # 변경사항 확인
chmod +x gradlew echo "Updated deployment.yml:"
echo "Testing gradle wrapper..." cat ${{ env.MANIFEST_FILE_PATH }}
./gradlew --version
- name: Commit and push changes
- name: Build analytics module with dependencies run: |
run: ./gradlew analytics:build -x test cd manifest-repo
git config --local user.email "action@github.com"
- name: Run analytics tests git config --local user.name "GitHub Action"
run: ./gradlew analytics:test
git add ${{ env.MANIFEST_FILE_PATH }}
- name: Generate build timestamp
id: timestamp if git diff --staged --quiet; then
run: echo "BUILD_TIME=$(date +'%y%m%d%H%M')" >> $GITHUB_OUTPUT echo "No changes to commit"
else
- name: Set up Docker Buildx git commit -m "🚀 Update analytics image tag to ${{ steps.timestamp.outputs.BUILD_TIME }}
uses: docker/setup-buildx-action@v3
- Updated by: ${{ github.actor }}
- name: Log in to Azure Container Registry - Triggered by: ${{ github.event_name }}
uses: azure/docker-login@v1 - Source commit: ${{ github.sha }}
with: - Build time: ${{ steps.timestamp.outputs.BUILD_TIME }}"
login-server: ${{ env.ACR_NAME }}.azurecr.io
username: ${{ secrets.ACR_USERNAME }} git push
password: ${{ secrets.ACR_PASSWORD }} echo "✅ Successfully updated manifest repository"
fi
- name: Build and push Docker image
uses: docker/build-push-action@v5 - name: Upload test results
with: uses: actions/upload-artifact@v4
context: . if: always()
file: ./analytics/Dockerfile with:
platforms: linux/amd64 name: analytics-test-results
push: true path: analytics/build/reports/tests/test/
tags: |
${{ env.ACR_NAME }}.azurecr.io/${{ env.IMAGE_NAME }}:${{ steps.timestamp.outputs.BUILD_TIME }} - name: Upload build artifacts
${{ env.ACR_NAME }}.azurecr.io/${{ env.IMAGE_NAME }}:latest uses: actions/upload-artifact@v4
if: success()
- name: Output image tags with:
run: | name: analytics-jar
echo "🎉 Image pushed successfully!" path: analytics/build/libs/*.jar
echo "📦 Image: ${{ env.ACR_NAME }}.azurecr.io/${{ env.IMAGE_NAME }}"
echo "🏷️ Tags: ${{ steps.timestamp.outputs.BUILD_TIME }}, latest" # 🎯 배포 완료 알림
- name: Deployment summary
- name: Upload test results if: success()
uses: actions/upload-artifact@v4 run: |
if: always() echo "## 🚀 Analytics Service Deployment Summary" >> $GITHUB_STEP_SUMMARY
with: echo "" >> $GITHUB_STEP_SUMMARY
name: analytics-test-results echo "### 📦 Container Image" >> $GITHUB_STEP_SUMMARY
path: analytics/build/reports/tests/test/ echo "- **Registry**: ${{ env.ACR_NAME }}.azurecr.io" >> $GITHUB_STEP_SUMMARY
echo "- **Image**: ${{ env.IMAGE_NAME }}" >> $GITHUB_STEP_SUMMARY
- name: Upload build artifacts echo "- **Tag**: ${{ steps.timestamp.outputs.BUILD_TIME }}" >> $GITHUB_STEP_SUMMARY
uses: actions/upload-artifact@v4 echo "" >> $GITHUB_STEP_SUMMARY
if: success() echo "### 🔄 ArgoCD Sync" >> $GITHUB_STEP_SUMMARY
with: echo "- **Manifest Repo**: https://github.com/${{ env.MANIFEST_REPO }}" >> $GITHUB_STEP_SUMMARY
name: analytics-jar echo "- **Updated File**: ${{ env.MANIFEST_FILE_PATH }}" >> $GITHUB_STEP_SUMMARY
path: analytics/build/libs/*.jar 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