-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
115 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ env: | |
MYSQL_HOST: ${{ secrets.MYSQL_HOST }} | ||
REDIS_HOST: ${{ secrets.REDIS_HOST }} | ||
|
||
|
||
jobs: | ||
build-and-upload: | ||
runs-on: ubuntu-latest | ||
|
@@ -112,19 +113,93 @@ jobs: | |
mkdir -p artifacts | ||
zip -r artifacts/repository.zip . | ||
# (9) GitHub Actions 아티팩트로 저장 (선택 사항) | ||
- name: Upload Artifact | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: repository-archive | ||
path: artifacts/repository.zip | ||
# (9) azure blob에 업로드 | ||
# 1. Azure CLI 설정 | ||
- name: Install azure-cli | ||
uses: pietrobolcato/[email protected] | ||
|
||
# 2. Azure 로그인 | ||
- name: Log in to Azure | ||
run: | | ||
az login --service-principal --username ${{ secrets.AZURE_CLIENT_ID }} --password ${{ secrets.AZURE_CLIENT_SECRET }} --tenant ${{ secrets.AZURE_TENANT_ID }} | ||
# 기존 파일 삭제 | ||
- name: Clear folder in Azure Blob Storage | ||
run: | | ||
az storage blob delete-batch \ | ||
--account-name ${{ secrets.AZURE_STORAGE_ACCOUNT_NAME }} \ | ||
--account-key ${{ secrets.AZURE_STORAGE_ACCOUNT_KEY }} \ | ||
--source ${{ secrets.AZURE_STORAGE_CONTAINER_NAME }} \ | ||
--pattern "*" | ||
# 5. Azure Blob Storage에 파일 업로드 | ||
- name: Upload file to Azure Blob Storage | ||
run: | | ||
az storage blob upload \ | ||
--account-name ${{ secrets.AZURE_STORAGE_ACCOUNT_NAME }} \ | ||
--account-key ${{ secrets.AZURE_STORAGE_ACCOUNT_KEY }} \ | ||
--container-name ${{ secrets.AZURE_STORAGE_CONTAINER_NAME }} \ | ||
--file artifacts/repository.zip \ | ||
--name repository.zip | ||
# (10) Azure DevOps 파이프라인 트리거 | ||
- name: Trigger Azure DevOps Pipeline | ||
run: | | ||
# Azure DevOps 파이프라인을 트리거 | ||
curl -u ":$AZURE_DEVOPS_PAT" \ | ||
response=$(curl -u ":$AZURE_DEVOPS_PAT" \ | ||
-X POST \ | ||
-H "Content-Type: application/json" \ | ||
-d '{"resources": {"repositories": {"self": {"refName": "refs/heads/master"}}}}' \ | ||
"https://dev.azure.com/$AZURE_DEVOPS_ORG/$AZURE_DEVOPS_PROJECT/_apis/pipelines/$AZURE_DEVOPS_PIPELINE_ID/runs?api-version=6.0-preview.1" | ||
-d '{ | ||
"resources": { | ||
"repositories": { | ||
"self": { | ||
"refName": "refs/heads/master" | ||
} | ||
} | ||
}, | ||
"variables": { | ||
"filename": { | ||
"value": "repository.zip" | ||
} | ||
} | ||
}' \ | ||
"https://dev.azure.com/${{ env.AZURE_DEVOPS_ORG }}/${{ env.AZURE_DEVOPS_PROJECT }}/_apis/pipelines/${{ env.AZURE_DEVOPS_PIPELINE_ID }}/runs?api-version=6.0-preview.1") | ||
pipeline_id=$(echo "$response" | jq -r '.id') | ||
echo "pipeline = $response" | ||
echo "Triggered pipeline with ID: $pipeline_id" | ||
# (11) Azure DevOps 파이프라인 상태 확인 | ||
- name: Check Azure DevOps Pipeline Status | ||
run: | | ||
max_wait_time=300 # 최대 대기 시간 (초) | ||
elapsed_time=0 | ||
sleep_interval=10 | ||
status="inProgress" | ||
while [[ "$status" == "inProgress" || "$status" == "queued" ]] && [[ "$elapsed_time" -lt "$max_wait_time" ]]; do | ||
echo "Checking pipeline status..." | ||
response=$(curl -s -u ":$AZURE_DEVOPS_PAT" \ | ||
"https://dev.azure.com/$AZURE_DEVOPS_ORG/$AZURE_DEVOPS_PROJECT/_apis/pipelines/$AZURE_DEVOPS_PIPELINE_ID/runs/$pipeline_id?api-version=6.0-preview.1") | ||
status=$(echo "$response" | jq -r '.status') | ||
sleep $sleep_interval | ||
elapsed_time=$((elapsed_time + sleep_interval)) | ||
done | ||
if [[ "$elapsed_time" -ge "$max_wait_time" ]]; then | ||
echo "Pipeline status check timed out." | ||
exit 1 | ||
fi | ||
# (12) Azure DevOps 파이프라인 성공 여부 확인 | ||
- name: Verify Pipeline Success | ||
run: | | ||
result=$(echo "$response" | jq -r '.result') | ||
if [[ "$result" != "succeeded" ]]; then | ||
failure_reason=$(echo "$response" | jq -r '.logs' || echo "No specific failure reason provided.") | ||
echo "Azure DevOps pipeline failed. Reason:" | ||
echo "${failure_reason:0:500}" # 메시지가 길 경우 자르기 | ||
exit 1 | ||
else | ||
echo "Azure DevOps pipeline succeeded." | ||
fi |