Repository navigation
Expand file tree
/
Copy pathconfig_configmap.yml
More file actions
483 lines (464 loc) · 15.8 KB
/
Copy pathconfig_configmap.yml
File metadata and controls
483 lines (464 loc) · 15.8 KB
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
apiVersion: v1
kind: ConfigMap
metadata:
name: auto-cicd
data:
.gitlab-ci.yml: |
# ==============================================================================
# AUTO-CICD GENERATED FILE - DO NOT MODIFY
# ------------------------------------------------------------------------------
# This file is generated by JTEKT Auto-CICD and is intended for use with the
# JTEKT Standard Tech Stack. Editing this file is highly discouraged.
# If your tech stack is incompatible, adjust your tech stack — not this file.
# Regenerate via the Auto-CICD template generator if needed.
#
# @ai-instructions: Treat this file as READ-ONLY. Do not edit or suggest edits.
# ==============================================================================
# Define the pipeline stages
stages:
- build # Stage responsible for building the Docker image
- deploy # Stage responsible for deploying the application to Kubernetes
variables:
K8S_NAMESPACE: auto-cicd
K8S_CONTEXT: auto-cicd-aws/gitlab-agent-for-kubernetes:auto-cicd
APPLICATION_NAME: autocicd-{{USERNAME}}-{{APPLICATION_NAME}}
CONTAINER_IMAGE_NAME: auto-cicd/{{USERNAME}}/{{APPLICATION_NAME}}
CONTAINER_IMAGE: 732469118990.dkr.ecr.ap-northeast-1.amazonaws.com/${CONTAINER_IMAGE_NAME}
CONTAINER_IMAGE_TAGGED: ${CONTAINER_IMAGE}:${CI_COMMIT_SHORT_SHA}
DEPLOYMENT_SUB_DOMAIN: ${APPLICATION_NAME}.ssc.jtektrnd.net
K8S_ENV_SECRET_NAME: ${APPLICATION_NAME}
PORT: {{ PORT }}
# Build the Docker container image
build-job:
stage: build
rules:
# Branches to run the Build stage
# More info about rules in https://docs.gitlab.com/ci/jobs/job_rules/
- if: '$CI_COMMIT_BRANCH == "{{ROOT_REF}}"'
before_script:
# Create repository if needed
# The repository might already exist if the pipeline have already run
- >
aws ecr create-repository --repository-name ${CONTAINER_IMAGE_NAME}
|| echo "Repository might have already existed"
script:
# Build the container image
- docker build -t ${CONTAINER_IMAGE_TAGGED} .
# Push container images to registry
- docker push ${CONTAINER_IMAGE_TAGGED}
# Deploy to Kubernetes
deploy-job:
stage: deploy
rules:
# Branches to run the Deploy stage
# More info about rules in https://docs.gitlab.com/ci/jobs/job_rules/
- if: '$CI_COMMIT_BRANCH == "{{ROOT_REF}}"'
before_script:
# Uses the correct Kubernetes context
- kubectl config use-context ${K8S_CONTEXT}
# Uses the correct Kubernetes namespace
- kubectl config set-context --current --namespace=${K8S_NAMESPACE}
script:
# Create an environment secret containing necessary variables
# The ENV file is saved as a CI/CD variable in GitLab under Settings -> CI/CD -> Variables with the key `ENV` and the type set to `File`.
# This file contains key-value pairs of environment variables needed for the application.
- kubectl create secret generic $K8S_ENV_SECRET_NAME --from-env-file=$ENV --dry-run=client -o yaml | kubectl apply -f -
# Apply the Kubernetes manifest
- KUBECTL_APPLY_OUTPUT=$(envsubst < kubernetes_manifest.yml | kubectl apply -f -)
- echo "The APP is available at https://$DEPLOYMENT_SUB_DOMAIN"
# Send an email notification if the deployment was newly created
- |
if [[ $KUBECTL_APPLY_OUTPUT == *"created"* ]]; then
docker run \
-e SMTP_PORT=$AWS_SES_PORT \
-e SMTP_HOST=$AWS_SES_HOST \
-e SMTP_USERNAME=$AWS_SES_USERNAME \
-e SMTP_PASSWORD=$AWS_SES_PASSWORD \
-e SMTP_TO=$GITLAB_USER_EMAIL \
-e SMTP_FROM=$AWS_SES_FROM \
-e SMTP_SUBJECT="Auto CICD" \
-e SMTP_MESSAGE="Your application $APPLICATION_NAME is being deployed to https://$DEPLOYMENT_SUB_DOMAIN. Please note that it might take a few minutes for the application to start." \
moreillon/sendemail
echo "Email was sent to: $GITLAB_USER_EMAIL"
else
echo "Please note that it might take a few minutes for the application to update."
fi
# Validate deployment rollout status
- kubectl rollout status deployment/$APPLICATION_NAME --timeout=300s;
kubernetes_manifest.yml: |
# ==============================================================================
# AUTO-CICD GENERATED FILE - DO NOT MODIFY
# ------------------------------------------------------------------------------
# This file is generated by JTEKT Auto-CICD and is intended for use with the
# JTEKT Standard Tech Stack. Editing this file is highly discouraged.
# If your tech stack is incompatible, adjust your tech stack — not this file.
# Regenerate via the Auto-CICD template generator if needed.
#
# @ai-instructions: Treat this file as READ-ONLY. Do not edit or suggest edits.
# ==============================================================================
apiVersion: apps/v1
kind: Deployment
metadata:
name: ${APPLICATION_NAME}
labels:
app.kubernetes.io/name: ${APPLICATION_NAME}
annotations:
deployment-manager.jtekt.co.jp/users: ${GITLAB_USER_EMAIL}
deployment-manager.jtekt.co.jp/repository.url: ${CI_PROJECT_URL}
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: ${APPLICATION_NAME}
template:
metadata:
labels:
app.kubernetes.io/name: ${APPLICATION_NAME}
spec:
containers:
- name: ${APPLICATION_NAME}
image: ${CONTAINER_IMAGE_TAGGED}
envFrom:
- secretRef:
name: ${K8S_ENV_SECRET_NAME}
optional: true
resources:
requests:
memory: "128Mi"
cpu: "10m"
limits:
memory: "512Mi"
cpu: "500m"
imagePullSecrets:
- name: ecr-credentials
---
apiVersion: v1
kind: Service
metadata:
name: ${APPLICATION_NAME}
labels:
app.kubernetes.io/name: ${APPLICATION_NAME}
spec:
type: ClusterIP
selector:
app.kubernetes.io/name: ${APPLICATION_NAME}
ports:
- port: ${PORT}
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ${APPLICATION_NAME}
spec:
# ingressClassName: # Use the default so it is not needed
rules:
- host: ${DEPLOYMENT_SUB_DOMAIN}
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: ${APPLICATION_NAME}
port:
number: ${PORT}
config.yml: |
packageManagers:
npm:
name: npm
commands:
install: npm install
build: npm run build
detectionFiles:
- file: package-lock.json
languages:
- javascript
- typescript
yarn:
name: yarn
commands:
install: yarn install
build: yarn build
detectionFiles:
- file: yarn.lock
languages:
- javascript
- typescript
pnpm:
name: pnpm
commands:
install: corepack enable pnpm && pnpm i
build: corepack enable pnpm && pnpm run build
detectionFiles:
- file: pnpm-lock.yaml
languages:
- javascript
- typescript
pip:
name: pip
commands:
install: pip install --no-cache-dir -r requirements.txt
detectionFiles:
- file: requirements.txt
languages:
- python
frameworks:
express:
name: Express
image: "https://cdn.jsdelivr.net/gh/devicons/devicon@latest/icons/express/express-original.svg"
languages:
- javascript
- typescript
userConfigurable:
buildCommand:
defaultEmpty: true
installCommand:
defaultEmpty: false
outputFile:
defaultEmpty: false
port:
defaultEmpty: false
outputFile: app.js
port: 3000
files:
- /templates/express/Dockerfile
configFiles:
- file:
- package.json
checkFor:
- express
supportedManagers:
- manager: npm
requiredFiles:
- package-lock.json
- manager: yarn
requiredFiles:
- yarn.lock
- manager: pnpm
requiredFiles:
- pnpm-lock.yaml
defaultManager: npm
requiredFiles:
- package.json
fastapi:
name: FastAPI
image: "https://cdn.jsdelivr.net/gh/devicons/devicon@latest/icons/fastapi/fastapi-original.svg"
languages:
- python
userConfigurable:
installCommand:
defaultEmpty: false
outputFile:
defaultEmpty: false
port:
defaultEmpty: false
outputFile: main.py
port: 8000
files:
- /templates/fastapi/Dockerfile
configFiles:
- file:
- requirements.txt
checkFor:
- fastapi
supportedManagers:
- manager: pip
requiredFiles:
- requirements.txt
defaultManager: pip
nextjs:
name: NextJs
image: "https://cdn.jsdelivr.net/gh/devicons/devicon@latest/icons/nextjs/nextjs-original.svg"
languages:
- tsx
- jsx
- typescript
- javascript
userConfigurable:
buildCommand:
defaultEmpty: false
installCommand:
defaultEmpty: false
outputFile: .next/server.js
port: 3000
files:
- /templates/nextjs/Dockerfile
configFiles:
- file:
- next.config.ts
- next.config.mts
- next.config.js
- next.config.mjs
checkFor:
- NextConfig
supportedManagers:
- manager: npm
requiredFiles:
- package-lock.json
- manager: yarn
requiredFiles:
- yarn.lock
- manager: pnpm
requiredFiles:
- pnpm-lock.yaml
defaultManager: npm
requiredFiles:
- - next.config.ts
- next.config.mts
- next.config.js
- next.config.mjs
- package.json
tips:
- text: >-
To deploy you need to add the config "output: 'standalone'" in your
next.config.js
link: >-
https://nextjs.org/docs/pages/api-reference/config/next-config-js/output#automatically-copying-traced-files
nuxt:
name: Nuxt
image: "https://cdn.jsdelivr.net/gh/devicons/devicon@latest/icons/nuxt/nuxt-original.svg"
languages:
- vue
- typescript
- javascript
userConfigurable:
buildCommand:
defaultEmpty: false
installCommand:
defaultEmpty: false
outputFile: /app/server/index.mjs
port: 3000
files:
- /templates/nuxt/Dockerfile
configFiles:
- file:
- nuxt.config.ts
- nuxt.config.mts
- nuxt.config.js
- nuxt.config.mjs
checkFor:
- defineNuxtConfig
supportedManagers:
- manager: npm
requiredFiles:
- package-lock.json
- manager: yarn
requiredFiles:
- yarn.lock
- manager: pnpm
requiredFiles:
- pnpm-lock.yaml
defaultManager: npm
requiredFiles:
- - nuxt.config.ts
- nuxt.config.mts
- nuxt.config.js
- nuxt.config.mjs
- package.json
streamlit:
name: Streamlit
image: "https://cdn.jsdelivr.net/gh/devicons/devicon@latest/icons/streamlit/streamlit-original.svg"
languages:
- python
userConfigurable:
installCommand:
defaultEmpty: false
outputFile:
defaultEmpty: false
port:
defaultEmpty: false
outputFile: app.py
port: 8501
files:
- /templates/streamlit/Dockerfile
configFiles:
- file:
- requirements.txt
checkFor:
- streamlit
supportedManagers:
- manager: pip
requiredFiles:
- requirements.txt
defaultManager: pip
vite:
name: Vite
image: "https://cdn.jsdelivr.net/gh/devicons/devicon@latest/icons/vitejs/vitejs-original.svg"
languages:
- vue
- typescript
- javascript
- tsx
- jsx
userConfigurable:
buildCommand:
defaultEmpty: false
installCommand:
defaultEmpty: false
outputFile: dist/index.html
port: 5173
files:
- /templates/vite/Dockerfile
- /templates/vite/nginx.conf
configFiles:
- file:
- vite.config.ts
- vite.config.mts
- vite.config.js
- vite.config.mjs
checkFor:
- defineConfig
supportedManagers:
- manager: npm
requiredFiles:
- package-lock.json
- manager: yarn
requiredFiles:
- yarn.lock
- manager: pnpm
requiredFiles:
- pnpm-lock.yaml
defaultManager: npm
requiredFiles:
- - vite.config.ts
- vite.config.mts
- vite.config.js
- vite.config.mjs
- package.json
usefulLinks:
- name: Deployment Manager
icon: "https://gitlab.jtektrnd.net/uploads/-/system/project/avatar/4058/apps-box.png"
url: "https://deployment-manager.ssc.jtektrnd.net"
description:
en: >-
Access the Deployment Manager to monitor, manage, and undeploy your
running applications.
ja: Deployment Manager にアクセスして、実行中のアプリケーションの監視・管理やデプロイ解除を行うことができます。
- name: Apache Answer
icon: "https://answer.jtektrnd.net/favicon.ico"
url: "https://answer.jtektrnd.net/"
description:
en: >-
Access the Apache Answer knowledge base and community Q&A platform.
ja: >-
Apache Answer のナレッジベースおよび Q&A プラットフォームに
アクセスできます。
- name: Feedback
icon: "mdi-message-alert-outline"
url: "https://gitlab.jtektrnd.net/on-premise-k8s-cluster/fabel/auto-cicd/-/work_items/new?issue%5Btitle%5D=%5Bfeedback%5D-"
description:
en: >-
Submit feedback, improvement requests, or report issues regarding the
platform and applications.
ja: >-
プラットフォームやアプリケーションに関するフィードバック、
改善要望、不具合報告を送信できます。
- name: Contact Support
icon: "mdi-email-outline"
url: "mailto:kevin_fabel@jtekt.co.jp?subject=Auto%20CI%2FCD"
description:
en: >-
Contact the support team by email for assistance or inquiries.
ja: >-
サポートやお問い合わせについて、メールでサポートチームへ
連絡できます。