-
Notifications
You must be signed in to change notification settings - Fork 0
150 lines (127 loc) · 4.87 KB
/
test.yaml
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#기존 gke 구성에서 gke kustomize 배포기능을 제외함 (Argo CD)가 그 역할을 대신함
#Docker 이미지를 빌드하고, Google Container Registry(GCR)에 푸시한 후, 추가적으로 Argo CD를 사용하여 GKE(Google Kubernetes Engine)에 배포
name: Build and Deploy to GKE For Argo CD
on:
push:
branches:
- release
env:
GKE_PROJECT: ${{ secrets.GKE_PROJECT }}
GKE_EMAIL: ${{ secrets.GKE_EMAIL }}
# GITHUB_SHA: ${{ github.sha }}
GKE_ZONE: asia-east1-a
GKE_CLUSTER: jsvill-cluster-1
IMAGE: jsvill
IMAGE_TAG: latest
REGISTRY_HOSTNAME: gcr.io
DEPLOYMENT_NAME: jsvill
jobs:
#job을 여러개로 나누면, job마다 checkout을 중복으로 해줘야함해서 하나로함
setup-build-publish-deploy:
name: Setup, Build, Publish, and Deploy
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: release
- name: JDK 16 설치
uses: actions/setup-java@v3
with:
java-version: '16'
distribution: 'corretto'
- name: application.yaml 파일 생성
run: touch ./src/main/resources/application.yaml
- name: application.yaml에 작성
run: echo "${{ secrets.APPLICATION }}" | base64 -d > ./src/main/resources/application.yaml
- name: application.yaml 내용 표시
run: cat ./src/main/resources/application.yaml
- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
- name: Build with Gradle
run: ./gradlew clean build -x test
- name: Authenticate with Google Cloud
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GKE_KEY }}
# Setup gcloud CLI
- name: Set up Cloud SDK
uses: 'google-github-actions/setup-gcloud@v2'
with:
project_id: ${{ secrets.GCP_PROJECT_ID }}
service_account_email: ${{ secrets.GKE_EMAIL }}
service_account_key: ${{ secrets.GKE_KEY }}
- name: Install gke-gcloud-auth-plugin
run: gcloud components install gke-gcloud-auth-plugin
- name: Enable gke-gcloud-auth-plugin
run: echo "USE_GKE_GCLOUD_AUTH_PLUGIN=True" >> $GITHUB_ENV
- name: Get GKE credentials
run: gcloud container clusters get-credentials $GKE_CLUSTER --zone $GKE_ZONE --project $GKE_PROJECT
- name: Configure Docker
run: gcloud auth configure-docker
# Build the Docker image
- name: Build
run: |-
docker build -t "$REGISTRY_HOSTNAME"/"$GKE_PROJECT"/"$IMAGE":"$IMAGE_TAG" \
--build-arg IMAGE_TAG="$IMAGE_TAG" \
--build-arg GITHUB_REF="$GITHUB_REF" .
# Push the Docker image to Google Container Registry
- name: Publish
run: docker push $REGISTRY_HOSTNAME/$GKE_PROJECT/$IMAGE:$IMAGE_TAG
bump-version-and-release-charts:
needs: setup-build-publish-deploy
permissions:
contents: write
runs-on: ubuntu-latest
outputs:
new-version: ${{ steps.bump-version.outputs.new-version }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: release
- name: Configure Git
run: |
git config --local user.email "[email protected]"
git config --local user.name "Sean-creative"
- name: Bump chart version
id: bump-version
run: |
CHART_DIR=charts/jsvill-chart
VERSION=$(grep 'version:' $CHART_DIR/Chart.yaml | awk '{print $2}')
NEW_VERSION=$(echo $VERSION | awk -F. '{$NF = $NF + 1;} 1' | sed 's/ /./g')
sed -i "s/version: $VERSION/version: $NEW_VERSION/" $CHART_DIR/Chart.yaml
echo "::set-output name=new-version::$NEW_VERSION"
git add $CHART_DIR/Chart.yaml
git commit -m "Bump chart version to $NEW_VERSION"
git push origin HEAD
- name: Install Helm
uses: azure/setup-helm@v3
- name: Run chart-releaser
uses: helm/[email protected]
with:
charts_dir: charts
env:
CR_TOKEN: "${{ secrets.CR_TOKEN }}"
update-kustomization:
needs: bump-version-and-release-charts
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: release
- name: Configure Git
run: |
git config --local user.email "[email protected]"
git config --local user.name "Sean-creative"
- name: Update kustomization version
run: |
cd kustomize
NEW_VERSION=${{ needs.bump-version-and-release-charts.outputs.new-version }}
sed -i "/jsvill-charts/,/version:/s/version: .*/version: $NEW_VERSION/" kustomization.yaml
git pull origin release
git add kustomization.yaml
git commit -m "Update jsvill-charts version to $NEW_VERSION"
git push origin HEAD