This commit is contained in:
@@ -0,0 +1,166 @@
|
||||
name: HealthSync Intelligence CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main, develop ]
|
||||
paths:
|
||||
- '**/*.py'
|
||||
- 'requirements.txt'
|
||||
- 'Dockerfile'
|
||||
- 'deployment/**'
|
||||
- '.github/workflows/intelligence-ci.yml'
|
||||
pull_request:
|
||||
branches: [ main, develop ]
|
||||
paths:
|
||||
- '**/*.py'
|
||||
- 'requirements.txt'
|
||||
- 'Dockerfile'
|
||||
- 'deployment/**'
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
version:
|
||||
description: '배포할 버전 (예: 1.2.3)'
|
||||
required: false
|
||||
type: string
|
||||
|
||||
env:
|
||||
ACR_REGISTRY: acrhealthsync01.azurecr.io
|
||||
TEAM_ID: team1tier
|
||||
PYTHON_VERSION: '3.11'
|
||||
MANIFEST_REPO: TeamOneTier/HealthSync_Manifest
|
||||
MANIFEST_BRANCH: main
|
||||
|
||||
jobs:
|
||||
build-and-push:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install Azure CLI
|
||||
run: |
|
||||
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
|
||||
|
||||
- name: Azure 로그인 (Azure Login 액션 사용)
|
||||
uses: azure/login@v1
|
||||
with:
|
||||
creds: ${{ secrets.AZURE_CREDENTIALS }}
|
||||
|
||||
- name: Show ACR Tags
|
||||
run: |
|
||||
az acr repository show-tags \
|
||||
--name acrhealthsync01 \
|
||||
--repository "${{ env.TEAM_ID }}/intelligence-service"
|
||||
|
||||
- name: Generate version
|
||||
id: version
|
||||
run: |
|
||||
if [[ "$GITHUB_EVENT_NAME" == "workflow_dispatch" && -n "${{ github.event.inputs.version }}" ]]; then
|
||||
VERSION="${{ github.event.inputs.version }}"
|
||||
echo "🎯 Using manual version: $VERSION"
|
||||
else
|
||||
echo "🔍 Generating version automatically from ACR..."
|
||||
|
||||
REPO_NAME="${{ env.TEAM_ID }}/intelligence-service"
|
||||
ACR_NAME="$(echo "${{ env.ACR_REGISTRY }}" | cut -d'.' -f1)"
|
||||
|
||||
if TAGS=$(az acr repository show-tags --name "$ACR_NAME" --repository "$REPO_NAME" --output tsv 2>/dev/null); then
|
||||
if [[ -z "$TAGS" ]]; then
|
||||
VERSION="1.0.0"
|
||||
else
|
||||
LATEST_VERSION=$(echo "$TAGS" | tr '\t' '\n' | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | sort -t. -k1,1n -k2,2n -k3,3n | tail -1)
|
||||
if [[ -z "$LATEST_VERSION" ]]; then
|
||||
VERSION="1.0.0"
|
||||
else
|
||||
MAJOR=$(echo "$LATEST_VERSION" | cut -d'.' -f1)
|
||||
MINOR=$(echo "$LATEST_VERSION" | cut -d'.' -f2)
|
||||
PATCH=$(echo "$LATEST_VERSION" | cut -d'.' -f3)
|
||||
VERSION="$MAJOR.$MINOR.$((PATCH + 1))"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
VERSION="1.0.0"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
||||
echo "🏷️ Final version for Intelligence: $VERSION"
|
||||
|
||||
- name: Set up Python ${{ env.PYTHON_VERSION }}
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: ${{ env.PYTHON_VERSION }}
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
if [ -f requirements.txt ]; then
|
||||
pip install -r requirements.txt
|
||||
echo "✅ Python dependencies installed"
|
||||
fi
|
||||
|
||||
- name: Login to ACR
|
||||
run: |
|
||||
echo ${{ secrets.ACR_PASSWORD }} | docker login ${{ env.ACR_REGISTRY }} \
|
||||
--username ${{ secrets.ACR_USERNAME }} \
|
||||
--password-stdin
|
||||
|
||||
- name: Build and Push Docker Image
|
||||
run: |
|
||||
IMAGE_TAG="${{ env.ACR_REGISTRY }}/${{ env.TEAM_ID }}/intelligence-service:${{ steps.version.outputs.version }}"
|
||||
|
||||
docker build \
|
||||
--platform linux/amd64 \
|
||||
--build-arg SERVICE_NAME=healthsync-intelligence \
|
||||
--build-arg VERSION=${{ steps.version.outputs.version }} \
|
||||
-t "$IMAGE_TAG" \
|
||||
.
|
||||
|
||||
docker push "$IMAGE_TAG"
|
||||
echo "✅ Pushed: $IMAGE_TAG"
|
||||
|
||||
- name: Checkout Manifest Repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
repository: ${{ env.MANIFEST_REPO }}
|
||||
token: ${{ secrets.GIT_REPO_TOKEN }}
|
||||
path: manifest-repo
|
||||
|
||||
- name: Update Manifest Deployment
|
||||
run: |
|
||||
cd manifest-repo
|
||||
|
||||
# Intelligence manifest 파일 경로 설정
|
||||
MANIFEST_FILE="HealthSync_Intelligence/manifest/deployment/intelligence-service-deployment.yaml"
|
||||
|
||||
if [ ! -f "$MANIFEST_FILE" ]; then
|
||||
echo "❌ Manifest file not found: $MANIFEST_FILE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 새로운 이미지 태그
|
||||
NEW_IMAGE="${{ env.ACR_REGISTRY }}/${{ env.TEAM_ID }}/intelligence-service:${{ steps.version.outputs.version }}"
|
||||
|
||||
echo "🔄 Updating $MANIFEST_FILE with new image: $NEW_IMAGE"
|
||||
|
||||
# sed를 사용하여 image 태그 업데이트
|
||||
sed -i "s|image: ${{ env.ACR_REGISTRY }}/${{ env.TEAM_ID }}/intelligence-service:.*|image: $NEW_IMAGE|g" "$MANIFEST_FILE"
|
||||
|
||||
echo "✅ Updated manifest file"
|
||||
git diff "$MANIFEST_FILE"
|
||||
|
||||
- name: Commit and Push Manifest Changes
|
||||
run: |
|
||||
cd manifest-repo
|
||||
|
||||
git config --global user.name "github-actions[bot]"
|
||||
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
||||
|
||||
git add .
|
||||
git commit -m "🚀 Update intelligence-service image to ${{ steps.version.outputs.version }}" || {
|
||||
echo "ℹ️ No changes to commit"
|
||||
exit 0
|
||||
}
|
||||
|
||||
git push origin ${{ env.MANIFEST_BRANCH }}
|
||||
echo "✅ Manifest updated and pushed successfully"
|
||||
Reference in New Issue
Block a user