-
Notifications
You must be signed in to change notification settings - Fork 0
265 lines (222 loc) · 8.81 KB
/
aws.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
name: Create and publish a container image, update helm chart 'appVersion'
on:
push:
branches: ["main", "develop", "fix/cicd"]
#############################################
#
# Branch
# - develop > github packages
# - main > amazon ecr repository
#
#############################################
# # [origin] start
# jobs:
# build:
# name: Build Docker Image
# runs-on: ubuntu-latest
# steps:
# - name: Checkout Repository
# uses: actions/checkout@v3
# - name: Set up JDK 21
# uses: actions/setup-java@v2
# with:
# distribution: 'adopt'
# java-version: '21'
# - name: Build JAR
# run: ./gradlew build -x test
# - name: Determine ECR Repository
# id: ecr_repo
# run: |
# REPO_NAME=$(echo ${{ github.repository }} | awk -F '/' '{print $2}' | tr '[:upper:]' '[:lower:]')
# echo "repo=${REPO_NAME}" >> $GITHUB_OUTPUT
# if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
# echo "environment=prod" >> $GITHUB_OUTPUT
# elif [[ "${{ github.ref }}" == "refs/heads/develop" ]]; then
# echo "environment=stag" >> $GITHUB_OUTPUT
# else
# echo "::error::Unsupported branch: ${{ github.event_name }} on ${{ github.ref }}"
# exit 1
# fi
# - name: Configure AWS credentials
# uses: aws-actions/configure-aws-credentials@v2
# with:
# aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
# aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
# - name: Login to Amazon ECR
# id: login-ecr
# uses: aws-actions/amazon-ecr-login@v2
# - name: Docker Build and Push
# run: |
# docker build -t ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_DEFAULT_REGION }}.amazonaws.com/${{ steps.ecr_repo.outputs.repo }}_${{ steps.ecr_repo.outputs.environment }}:${{ github.sha }} .
# docker push ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_DEFAULT_REGION }}.amazonaws.com/${{ steps.ecr_repo.outputs.repo }}_${{ steps.ecr_repo.outputs.environment }}:${{ github.sha }}
# - name: Checkout Private Repository
# uses: actions/checkout@v4
# with:
# repository: NTF-marketplace/devops
# fetch-depth: 0
# ref: develop
# token: ${{ secrets.PAT }}
# - name: Replace image tag in helm values (LOCAL)
# uses: mikefarah/yq@master
# env:
# IMAGE_TAG: ${{ github.sha }}
# with:
# cmd: yq eval -i '.image.tag = env(IMAGE_TAG)' 'chart/${{ steps.ecr_repo.outputs.repo }}_${{ steps.ecr_repo.outputs.environment }}/values.yaml'
# - name: Commit helm chart changes
# env:
# IMAGE_TAG: ${{ github.sha }}
# run: |
# cd chart/${{ steps.ecr_repo.outputs.repo }}_${{ steps.ecr_repo.outputs.environment }}
# git config --global user.email "[email protected]"
# git config --global user.name "dongdorrong"
# git add values.yaml
# git commit --message "ci: update ${{ steps.ecr_repo.outputs.repo }}_${{ steps.ecr_repo.outputs.environment }} image tag to $IMAGE_TAG"
# - name: Push commit
# uses: ad-m/github-push-action@master
# with:
# github_token: ${{ secrets.PAT }}
# repository: NTF-marketplace/devops
# branch: develop
# # [origin] end
jobs:
develop:
### Reference
# https://docs.github.com/ko/actions/publishing-packages/publishing-docker-images#github-packages%EC%97%90-%EC%9D%B4%EB%AF%B8%EC%A7%80-%EA%B2%8C%EC%8B%9C
###
# if: github.ref == 'refs/heads/develop'
if: github.ref == 'refs/heads/fix/cicd'
name: Build and Push Docker Image to GitHub Container Registry
runs-on: ubuntu-latest
env:
ENVIRONMENT: dev
REPOSITORY: auth
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Log in to the GitHub container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Container image
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ghcr.io/${{ github.repository }}
tags: type=sha
- name: Set up JDK 21
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '21'
- name: Build JAR
run: ./gradlew clean build -x test
- name: Build and push Docker image
id: push
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# ### Error
# # [message] Failed to persist attestation
# # Feature not available for the NTF-marketplace organization.
# # To enable this feature, please upgrade the billing plan, or make this repository public.
# # https://docs.github.com/rest/repos/repos#create-an-attestation
# ###
# - name: Generate artifact attestation
# uses: actions/attest-build-provenance@v1
# with:
# subject-name: ${{ env.REGISTRY }}/${{ github.repository }}
# subject-digest: ${{ steps.push.outputs.digest }}
# push-to-registry: true
- name: Checkout Private Repository
uses: actions/checkout@v4
with:
repository: NTF-marketplace/devops
fetch-depth: 0
ref: develop
token: ${{ secrets.PAT }}
- name: Replace image tag in helm values.yaml
uses: mikefarah/yq@master
env:
IMAGE_TAG: ${{ steps.meta.outputs.tags }}
with:
cmd: yq eval -i '.image.tag = env(IMAGE_TAG)' 'chart/${{ env.REPOSITORY }}_${{ env.ENVIRONMENT }}/values.yaml'
- name: Commit helm chart changes
env:
IMAGE_TAG: ${{ steps.meta.outputs.tags }}
run: |
cd chart/${{ github.repository }}_${{ env.ENVIRONMENT }}
git config --global user.email "[email protected]"
git config --global user.name "dongdorrong"
git add values.yaml
git commit --message "ci: update ${{ env.REPOSITORY }}_${{ env.ENVIRONMENT }} image tag to $IMAGE_TAG"
- name: Push commit
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.PAT }}
repository: NTF-marketplace/devops
branch: develop
# main:
# if: github.ref == 'refs/heads/main'
# name: Build and Push Docker Image to ECR
# runs-on: ubuntu-latest
# steps:
# - name: Checkout Repository
# uses: actions/checkout@v3
# - name: Set up JDK 21
# uses: actions/setup-java@v2
# with:
# distribution: 'adopt'
# java-version: '21'
# - name: Build JAR
# run: ./gradlew clean build -x test
# - name: Configure AWS credentials
# uses: aws-actions/configure-aws-credentials@v2
# with:
# aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
# aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
# - name: Login to Amazon ECR
# uses: aws-actions/amazon-ecr-login@v2
# - name: Docker Build and Push to ECR
# run: |
# docker build -t ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_DEFAULT_REGION }}.amazonaws.com/my-repo_prod:${{ github.sha }} .
# docker push ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_DEFAULT_REGION }}.amazonaws.com/my-repo_prod:${{ github.sha }}
# - name: Checkout Private Repository
# uses: actions/checkout@v4
# with:
# repository: NTF-marketplace/devops
# fetch-depth: 0
# ref: develop
# token: ${{ secrets.PAT }}
# - name: Replace image tag in helm values (LOCAL)
# uses: mikefarah/yq@master
# env:
# IMAGE_TAG: ${{ github.sha }}
# with:
# cmd: yq eval -i '.image.tag = env(IMAGE_TAG)' 'chart/my-repo_prod/values.yaml'
# - name: Commit helm chart changes
# env:
# IMAGE_TAG: ${{ github.sha }}
# run: |
# cd chart/my-repo_prod
# git config --global user.email "[email protected]"
# git config --global user.name "dongdorrong"
# git add values.yaml
# git commit --message "ci: update my-repo_prod image tag to $IMAGE_TAG"
# - name: Push commit
# uses: ad-m/github-push-action@master
# with:
# github_token: ${{ secrets.PAT }}
# repository: NTF-marketplace/devops
# branch: develop