-
Notifications
You must be signed in to change notification settings - Fork 0
111 lines (91 loc) · 3.46 KB
/
deploy-k8s-dev.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
name: Deploy-Dev-K8S
on:
push:
branches:
- "sandbox"
env:
REGISTRY_URL: ${{ secrets.REGISTRY_URL }}
IMAGE_NAME: ${{ secrets.IMAGE_NAME }}
IMAGE_TAG: ${{ github.sha }}
jobs:
test:
name: Test
runs-on: ubuntu-latest
environment: dev
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'adopt'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Check ktlint format
run: ./gradlew clean ktlintCheck
- name: Gradle Clean & Build
run: ./gradlew clean build
- name: Test with Gradle
run: ./gradlew test
build:
name: Build
runs-on: ubuntu-latest
environment: dev
outputs:
image: echo ${{ steps.build-image.outputs.image }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Docker Setup QEMU
uses: docker/[email protected]
- name: Docker Setup Buildx
uses: docker/[email protected]
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build Docker image
run: |
docker build \
--platform linux/arm64 \
--build-arg PHASE=${{ vars.PHASE }} \
-f app/api/Dockerfile \
-t $REGISTRY_URL/$IMAGE_NAME:$IMAGE_TAG .
- name: Push Docker image
run: docker push $REGISTRY_URL/$IMAGE_NAME:$IMAGE_TAG
deploy:
name: Deploy
runs-on: ubuntu-latest
environment: dev
needs:
- test
- build
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
repository: ${{ secrets.ARGO_CD_REPO }}
ref: dev
token: ${{ secrets.TOKEN_GITHUB }}
- name: Update YAML file
run: |
# 변경할 YAML 파일 경로
yaml_file="${{ secrets.ARGO_CD_PATH }}/values.yaml"
# 변경할 키와 새 값
key="tag"
new_value="$IMAGE_TAG"
# sed를 사용하여 키 값 변경
sed -i -E "s/(\s*${key}:\s*).*/\1${new_value}/" $yaml_file
echo "Updated $key to $new_value in $yaml_file"
cat $yaml_file
- name: Commit changes
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add ${{ secrets.ARGO_CD_PATH }}/values.yaml
git commit -m "Update YAML file value"
git push
env:
GITHUB_TOKEN: ${{ secrets.TOKEN_GITHUB }}