-
Notifications
You must be signed in to change notification settings - Fork 1
116 lines (95 loc) · 3.74 KB
/
ecr.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
name: Java CI with Gradle
on:
push:
branches: [ "main", "dev" ]
env:
AWS_DEV_BATCH_ECR: ${{ secrets.AWS_DEV_BATCH_ECR }}
AWS_PRD_BATCH_ECR: ${{ secrets.AWS_PRD_BATCH_ECR }}
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
AWS_REGION: ${{ secrets.AWS_REGION }}
WEBHOOK_URL: ${{ secrets.WEBHOOK }}
DEPLOY_ENV: ${{ github.ref == 'refs/heads/main' && 'PROD' || 'DEV' }}
permissions:
id-token: write
contents: write
jobs:
build:
name: Build
runs-on: self-hosted
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: 'gradle'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew bootJar
- name: Docker build
run: docker build -t batch-service .
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-region: ${{ env.AWS_REGION }}
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Publish Image to ECR(BATCH-SERVICE)
run: |
echo ${{ github.sha }}
if [ "${{ env.DEPLOY_ENV }}" == "PROD" ]; then
docker tag batch-service:latest ${{ env.AWS_PRD_BATCH_ECR }}:${{ github.sha }}
docker push ${{ env.AWS_PRD_BATCH_ECR }}:${{ github.sha }}
else
docker tag batch-service:latest ${{ env.AWS_DEV_BATCH_ECR }}:${{ github.sha }}
docker push ${{ env.AWS_DEV_BATCH_ECR }}:${{ github.sha }}
fi
- name: Send Notification
if: ${{ always() }}
run: |
if [[ ${{ job.status }} == "success" ]]; then
MESSAGE="✅ ${{ job.status }} 백엔드 ECR 도커파일 업로드 성공: batch-service - by ${{ github.actor }}"
else
MESSAGE="❌ ${{ job.status }} 백엔드 ECR 도커파일 업로드 실패: batch-service - by ${{ github.actor }}"
fi
curl -X POST -H "Content-Type: application/json" --data "{\"text\":\"${MESSAGE}\"}" ${{ env.WEBHOOK_URL }}
- name: Setup Kustomize
uses: imranismail/setup-kustomize@v1
- name: Checkout for Kustomize repository
uses: actions/checkout@v2
with:
repository: Project-Catcher/batch-service-kusto
ref: main
token: ${{ env.GIT_TOKEN }}
path: batch-service-kusto
- name: Update Kustomize image
run: |
echo ${{ github.sha }}
if [ "${{ env.DEPLOY_ENV }}" == "PROD" ]; then
KUSTOMIZE_PATH="batch-service-kusto/overlays/prd" && cd $KUSTOMIZE_PATH
kustomize edit set image app-batch-img="${{ env.AWS_PRD_BATCH_ECR }}:${{ github.sha }}"
else
KUSTOMIZE_PATH="batch-service-kusto/overlays/dev" && cd $KUSTOMIZE_PATH
kustomize edit set image app-batch-img="${{ env.AWS_DEV_BATCH_ECR }}:${{ github.sha }}"
fi
kustomize build .
- name: Commit minifest files
run: |
cd batch-service-kusto
git config --global user.email "[email protected]"
git config --global user.name "github-actions"
git commit -am "Update image tag"
git push -u origin main
- name: Sync ArgoCD Application
run: |
argocd app sync dev-app-batch \
--server argocd.dev-alltimecatcher.com \
--auth-token ${{ secrets.ARGOCD_TOKEN }} --insecure