-
Notifications
You must be signed in to change notification settings - Fork 0
75 lines (61 loc) · 2.6 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
name: Deploy to KC Container Registry and Update K8S Manifest
on:
release:
types: [ published ]
permissions:
contents: 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
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