Skip to content

Commit 20f5709

Browse files
taeintaein
authored andcommitted
kustomize upadte
1 parent fe1d18e commit 20f5709

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

.github/workflows/dp.yml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: Deploy to Kubernetes
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Java CI with Gradle"]
6+
branches: [main]
7+
types:
8+
- completed
9+
10+
push:
11+
branches:
12+
- kustomize
13+
14+
env:
15+
AWS_REGION: ${{ secrets.AWS_REGION }}
16+
EKS_CLUSTER_NAME: ${{ secrets.EKS_CLUSTER_NAME }}
17+
OIDC_ROLE_ARN: ${{ secrets.OIDC_ROLE }}
18+
WEBHOOK_URL: ${{ secrets.WEBHOOK }}
19+
DEPLOY_ENV: ${{ github.ref == 'refs/heads/main' && 'PROD' || 'DEV' }}
20+
GITHUB_TOKEN: ${{ secrets.GIT_TOKEN }}
21+
22+
permissions:
23+
contents: write
24+
id-token: write
25+
26+
jobs:
27+
kustomize_upadte:
28+
runs-on: ubuntu-latest
29+
steps:
30+
- name: Checkout code
31+
uses: actions/checkout@v3
32+
33+
- name: Configure AWS Credentials
34+
uses: aws-actions/configure-aws-credentials@v1
35+
with:
36+
aws-region: ${{ env.AWS_REGION }}
37+
role-session-name: GitHubActions
38+
role-to-assume: ${{ env.OIDC_ROLE_ARN }}
39+
40+
- name: Login to Amazon ECR
41+
id: login-ecr
42+
uses: aws-actions/amazon-ecr-login@v1
43+
44+
# kustomize 명령을 가져온다.
45+
- name: Setup Kustomize
46+
uses: imranismail/setup-kustomize@v1
47+
48+
- name: Checkout for Kustomize repository
49+
uses: actions/checkout@v2
50+
with:
51+
repository: Project-Catcher/batch-service-kusto
52+
ref: main
53+
token: ${{ env.GITHUB_TOKEN }}
54+
path: batch-service-kusto
55+
56+
- name: Update Kustomize image
57+
run: |
58+
if [ "${{ env.DEPLOY_ENV }}" == "PROD" ]; then
59+
KUSTOMIZE_PATH="batch-service-kusto/k8s/overlays/production"
60+
FILE_NAME="production-patch.yaml"
61+
else
62+
KUSTOMIZE_PATH="batch-service-kusto/k8s/overlays/development"
63+
FILE_NAME="deployment-patch.yaml"
64+
fi
65+
66+
# Docker 이미지 URL 설정
67+
cd $KUSTOMIZE_PATH
68+
kustomize edit set image batch-service="${{ steps.login-ecr.outputs.registry }}:batch-service"
69+
cat kustomization.yaml
70+
71+
- name: Check for changes
72+
id: git-check
73+
run: |
74+
cd batch-service-kusto
75+
git status
76+
git diff-index --quiet HEAD || echo "::set-output name=changes_exist::true"
77+
78+
# 수정된 파일 commit & push
79+
- name: Commit manifest files
80+
if: steps.git-check.outputs.changes_exist == 'true'
81+
run: |
82+
cd batch-service-kusto
83+
git config --global user.email "[email protected]"
84+
git config --global user.name "github-actions"
85+
git commit -am "Update image tag"
86+
git push -u origin main
87+
88+
- name: Send Notification
89+
if: ${{ always() }}
90+
run: |
91+
if [[ '${{ steps.git-check.outputs.changes_exist }}' == 'true' && ${{ job.status }} == 'success' ]]; then
92+
MESSAGE="✅ ${{ job.status }} Kustomize Update 성공: batch-service-kusto - by ${{ github.actor }}"
93+
elif [[ '${{ steps.git-check.outputs.changes_exist }}' != 'true' && ${{ job.status }} == 'success' ]]; then
94+
MESSAGE="ℹ️ ${{ job.status }} Kustomize : 수정 사항 없음 - batch-service-kusto - by ${{ github.actor }}"
95+
else
96+
MESSAGE="❌ ${{ job.status }} Kustomize Update 실패: batch-service-kusto - by ${{ github.actor }}"
97+
fi
98+
curl -X POST -H "Content-Type: application/json" --data "{\"text\":\"${MESSAGE}\"}" ${{ env.WEBHOOK_URL }}

0 commit comments

Comments
 (0)