-
Notifications
You must be signed in to change notification settings - Fork 0
116 lines (98 loc) · 3.78 KB
/
deploy.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: Deploy to KC Container Registry and Update K8S Manifest
on:
release:
types: [ published ]
permissions:
contents: read
actions: read
jobs:
build-docker-image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Set Secret yml file.
run: |
touch ./src/main/resources/secret.yml
echo "${{ secrets.SECRETYML }}" > ./src/main/resources/secret.yml
cat ./src/main/resources/secret.yml
- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
shell: bash
- name: Build with Gradle
run: ./gradlew bootJar
shell: bash
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to KakaoCloud Container Registry
run: docker login ${{ secrets.KC_REGISTRY_URL }} --username ${{ secrets.KC_ACCESS_KEY_ID }} --password ${{ secrets.KC_SECRET_KEY }}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
platforms: linux/amd64
tags: ${{ secrets.KC_REGISTRY_URL }}/${{ secrets.IMAGE_NAME }}:${{ github.event.release.tag_name }}, ${{ secrets.KC_REGISTRY_URL }}/${{ secrets.IMAGE_NAME }}:latest
- name: slack-notification
uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
fields: repo,action,ref,job,took
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
if: failure()
update-k8s:
needs: build-docker-image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
repository: kea-dpang/k8s-manifast
token: ${{ secrets.GIT_TOKEN }}
- name: Extract repository name
id: repo-name
run: echo "REPO_NAME=$(echo ${{ github.repository }} | cut -d'/' -f2)" >> $GITHUB_ENV
- name: Extract directory name
id: directory-name
run: echo "DIRECTORY_NAME=$(echo ${{ secrets.IMAGE_NAME }} | cut -d'/' -f2)" >> $GITHUB_ENV
- name: Update image version
run: sed -i 's|${{ secrets.KC_REGISTRY_URL }}/${{ secrets.IMAGE_NAME }}.*|${{ secrets.KC_REGISTRY_URL }}/${{ secrets.IMAGE_NAME }}:${{ github.event.release.tag_name }}|' ./backend/${{ env.DIRECTORY_NAME }}/${{ env.REPO_NAME }}-deployment.yaml
- name: Commit and push changes
run: |
git config --global user.name ${{ secrets.GIT_USER_NAME }}
git config --global user.email ${{ secrets.GIT_USER_EMAIL }}
git add ./backend/${{ env.DIRECTORY_NAME }}/${{ env.REPO_NAME }}-deployment.yaml
git commit -m "update: 이미지 버전 수정 ${{ secrets.IMAGE_NAME }} v${{ github.event.release.tag_name }} by Git Action"
git push
- name: slack-notification
uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
fields: repo,message,commit,author,action,eventName,ref,workflow,job,took,pullRequest
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
if: failure()
- name: slack-notification
uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
fields: repo,action,ref,job,took
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
if: failure()
slack-notification:
needs: [build-docker-image, update-k8s]
runs-on: ubuntu-latest
steps:
- name: slack-notification
uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
fields: repo,action,ref
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
if: always()