ci: analytics-ci CD 연결설정
This commit is contained in:
parent
c7ffb5ae3d
commit
77c07305f3
237
.github/workflows/analytics-ci.yml
vendored
237
.github/workflows/analytics-ci.yml
vendored
@ -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
|
||||
Loading…
x
Reference in New Issue
Block a user