-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathYAML.txt
More file actions
2972 lines (2645 loc) · 69.5 KB
/
YAML.txt
File metadata and controls
2972 lines (2645 loc) · 69.5 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
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# YAML - Yet Another Markup Language / YAML Ain't Markup Language Reference - by Richard Rembert
# YAML is a human-readable data serialization standard for configuration files and data exchange
# Widely used in DevOps, cloud infrastructure, CI/CD pipelines, and application configuration
# YAML BASICS AND SYNTAX
# YAML is case sensitive and uses indentation (spaces, not tabs) to denote structure
# Files typically use .yml or .yaml extension
# YAML documents can contain multiple documents separated by ---
# Comments
# This is a single line comment
# YAML only supports single-line comments starting with #
# Document separators
---
# First document
name: "John Doe"
---
# Second document
name: "Jane Smith"
# Basic data types
string_value: "Hello World"
string_unquoted: Hello World
string_multiline: |
This is a multi-line string
that preserves line breaks
string_folded: >
This is a folded string
that joins lines with spaces
integer: 42
float: 3.14159
boolean_true: true
boolean_false: false
null_value: null
date: 2023-12-25
datetime: 2023-12-25T10:30:00Z
# Quotes in strings
single_quotes: 'Can contain "double quotes"'
double_quotes: "Can contain 'single quotes' and \n escape sequences"
no_quotes: Simple strings don't need quotes
# Special characters and escaping
escaped_string: "Line 1\nLine 2\tTabbed"
raw_string: 'No escaping here: \n \t'
yaml_special: "YAML special chars: : { } [ ] , & * # | > ' \" % @ `"
# Numbers in different formats
decimal: 123
octal: 0123
hexadecimal: 0x1A
binary: 0b1010
scientific: 1.23e+3
infinity: .inf
not_a_number: .nan
# Collections - Lists (Arrays)
simple_list:
- item1
- item2
- item3
inline_list: [item1, item2, item3]
nested_list:
- item1
-
- nested_item1
- nested_item2
- item3
mixed_list:
- string_item
- 42
- true
- null
# Collections - Dictionaries (Objects/Maps)
simple_dict:
key1: value1
key2: value2
key3: value3
inline_dict: {key1: value1, key2: value2}
nested_dict:
level1:
level2:
key: value
another_key: another_value
# Complex nested structures
complex_structure:
users:
- name: "John Doe"
age: 30
roles: [admin, user]
settings:
theme: dark
notifications: true
- name: "Jane Smith"
age: 25
roles: [user]
settings:
theme: light
notifications: false
# Multi-line strings
literal_block: |
This preserves line breaks.
Each line will appear exactly
as written in the YAML file.
Including blank lines.
folded_block: >
This folds lines into a single
paragraph. Line breaks are
converted to spaces, except
for blank lines which create
paragraph breaks.
strip_final_newlines: |-
This literal block strips
the final newline character.
keep_final_newlines: |+
This literal block preserves
trailing newlines.
# YAML ANCHORS AND ALIASES
# Anchors (&) create reusable nodes
# Aliases (*) reference anchored nodes
default_settings: &default
timeout: 30
retries: 3
debug: false
# Using aliases to reuse configurations
service1:
name: web-service
<<: *default
port: 8080
service2:
name: api-service
<<: *default
port: 3000
timeout: 60 # Override default value
# Complex anchor example
database_config: &db_config
host: localhost
port: 5432
ssl: true
connection_pool:
min: 5
max: 20
# Reference the anchor
production:
database:
<<: *db_config
host: prod-db.example.com
username: prod_user
password: prod_password
development:
database:
<<: *db_config
host: dev-db.example.com
username: dev_user
password: dev_password
# Anchoring lists
common_volumes: &common_volumes
- /var/log
- /tmp
- /opt/app
container1:
volumes: *common_volumes
container2:
volumes:
- *common_volumes
- /additional/volume
# Merge multiple anchors
defaults: &defaults
image: ubuntu:20.04
restart: unless-stopped
logging: &logging
logging:
driver: json-file
options:
max-size: 10m
max-file: 3
web_service:
<<: [*defaults, *logging]
ports:
- "80:80"
# DOCKER COMPOSE YAML
# Complete Docker Compose example
version: '3.8'
# Define reusable configurations
x-logging: &default-logging
logging:
driver: json-file
options:
max-size: "10m"
max-file: "3"
x-restart-policy: &restart-policy
restart: unless-stopped
services:
# Web application
web:
<<: [*default-logging, *restart-policy]
build:
context: .
dockerfile: Dockerfile
args:
NODE_ENV: production
ports:
- "3000:3000"
- "3001:3001"
environment:
- NODE_ENV=production
- DATABASE_URL=postgres://user:password@db:5432/myapp
- REDIS_URL=redis://redis:6379
volumes:
- ./app:/usr/src/app:ro
- app_data:/usr/src/app/data
- type: tmpfs
target: /tmp
tmpfs:
size: 100M
depends_on:
db:
condition: service_healthy
redis:
condition: service_started
networks:
- frontend
- backend
deploy:
replicas: 2
resources:
limits:
cpus: '0.5'
memory: 512M
reservations:
cpus: '0.25'
memory: 256M
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s
# Database
db:
<<: [*default-logging, *restart-policy]
image: postgres:13-alpine
environment:
POSTGRES_DB: myapp
POSTGRES_USER: user
POSTGRES_PASSWORD_FILE: /run/secrets/db_password
volumes:
- postgres_data:/var/lib/postgresql/data
- ./init.sql:/docker-entrypoint-initdb.d/init.sql:ro
networks:
- backend
secrets:
- db_password
healthcheck:
test: ["CMD-SHELL", "pg_isready -U user -d myapp"]
interval: 10s
timeout: 5s
retries: 5
# Redis cache
redis:
<<: [*default-logging, *restart-policy]
image: redis:6-alpine
command: redis-server --appendonly yes --requirepass mypassword
volumes:
- redis_data:/data
- ./redis.conf:/usr/local/etc/redis/redis.conf:ro
networks:
- backend
sysctls:
net.core.somaxconn: 1024
# Nginx reverse proxy
nginx:
<<: [*default-logging, *restart-policy]
image: nginx:alpine
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
- ./nginx/conf.d:/etc/nginx/conf.d:ro
- ./ssl:/etc/nginx/ssl:ro
- nginx_logs:/var/log/nginx
depends_on:
- web
networks:
- frontend
labels:
- "com.example.description=Nginx reverse proxy"
- "com.example.department=ops"
# Background worker
worker:
<<: [*default-logging, *restart-policy]
build:
context: .
target: worker
environment:
- NODE_ENV=production
- QUEUE_URL=redis://redis:6379/1
volumes:
- worker_data:/app/data
depends_on:
- redis
networks:
- backend
deploy:
replicas: 3
volumes:
postgres_data:
driver: local
driver_opts:
type: none
o: bind
device: /data/postgres
redis_data:
driver: local
app_data:
external: true
worker_data:
name: myapp_worker_data
nginx_logs:
driver: local
networks:
frontend:
driver: bridge
ipam:
config:
- subnet: 172.20.0.0/16
backend:
driver: bridge
internal: true
default:
external:
name: myapp_network
secrets:
db_password:
file: ./secrets/db_password.txt
api_key:
external: true
configs:
nginx_config:
file: ./nginx/nginx.conf
app_config:
external: true
# KUBERNETES YAML MANIFESTS
# Namespace
apiVersion: v1
kind: Namespace
metadata:
name: myapp
labels:
environment: production
team: backend
---
# ConfigMap
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
namespace: myapp
data:
database.properties: |
database.host=postgres-service
database.port=5432
database.name=myapp
redis.conf: |
maxmemory 256mb
maxmemory-policy allkeys-lru
nginx.conf: |
upstream backend {
server web-service:3000;
}
server {
listen 80;
location / {
proxy_pass http://backend;
}
}
---
# Secret
apiVersion: v1
kind: Secret
metadata:
name: app-secrets
namespace: myapp
type: Opaque
data:
database-password: cGFzc3dvcmQxMjM= # base64 encoded
api-key: YWJjZGVmZ2hpams= # base64 encoded
stringData:
redis-password: myredispassword # plain text, will be base64 encoded
---
# Persistent Volume
apiVersion: v1
kind: PersistentVolume
metadata:
name: postgres-pv
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: fast-ssd
hostPath:
path: /data/postgres
---
# Persistent Volume Claim
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: postgres-pvc
namespace: myapp
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storageClassName: fast-ssd
---
# Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-deployment
namespace: myapp
labels:
app: web
version: v1.0.0
spec:
replicas: 3
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
version: v1.0.0
spec:
containers:
- name: web
image: myapp:latest
ports:
- containerPort: 3000
name: http
env:
- name: NODE_ENV
value: production
- name: DATABASE_URL
value: postgres://$(DB_USER):$(DB_PASSWORD)@postgres-service:5432/myapp
- name: DB_USER
valueFrom:
secretKeyRef:
name: app-secrets
key: database-user
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
name: app-secrets
key: database-password
volumeMounts:
- name: config-volume
mountPath: /app/config
- name: app-storage
mountPath: /app/data
resources:
requests:
memory: "128Mi"
cpu: "100m"
limits:
memory: "256Mi"
cpu: "200m"
livenessProbe:
httpGet:
path: /health
port: 3000
initialDelaySeconds: 30
periodSeconds: 10
readinessProbe:
httpGet:
path: /ready
port: 3000
initialDelaySeconds: 5
periodSeconds: 5
lifecycle:
preStop:
exec:
command: ["/bin/sh", "-c", "sleep 10"]
volumes:
- name: config-volume
configMap:
name: app-config
- name: app-storage
persistentVolumeClaim:
claimName: app-pvc
imagePullSecrets:
- name: regcred
nodeSelector:
kubernetes.io/os: linux
tolerations:
- key: "node-role.kubernetes.io/master"
operator: "Exists"
effect: "NoSchedule"
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchExpressions:
- key: app
operator: In
values:
- web
topologyKey: kubernetes.io/hostname
---
# Service
apiVersion: v1
kind: Service
metadata:
name: web-service
namespace: myapp
labels:
app: web
spec:
selector:
app: web
ports:
- port: 80
targetPort: 3000
protocol: TCP
name: http
type: ClusterIP
---
# Ingress
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: web-ingress
namespace: myapp
annotations:
kubernetes.io/ingress.class: nginx
cert-manager.io/cluster-issuer: letsencrypt-prod
nginx.ingress.kubernetes.io/rate-limit: "100"
nginx.ingress.kubernetes.io/ssl-redirect: "true"
spec:
tls:
- hosts:
- myapp.example.com
secretName: myapp-tls
rules:
- host: myapp.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: web-service
port:
number: 80
---
# HorizontalPodAutoscaler
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: web-hpa
namespace: myapp
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: web-deployment
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 80
behavior:
scaleDown:
stabilizationWindowSeconds: 300
policies:
- type: Percent
value: 10
periodSeconds: 60
scaleUp:
stabilizationWindowSeconds: 0
policies:
- type: Percent
value: 100
periodSeconds: 15
- type: Pods
value: 4
periodSeconds: 15
selectPolicy: Max
# CI/CD PIPELINE YAML
# GitHub Actions
name: CI/CD Pipeline
on:
push:
branches: [main, develop]
pull_request:
branches: [main]
schedule:
- cron: '0 2 * * 0' # Weekly on Sunday at 2 AM
env:
NODE_VERSION: '16'
DOCKER_REGISTRY: ghcr.io
IMAGE_NAME: myorg/myapp
jobs:
# Test job
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14, 16, 18]
database: [postgres, mysql]
exclude:
- node-version: 14
database: mysql
services:
postgres:
image: postgres:13
env:
POSTGRES_PASSWORD: postgres
POSTGRES_DB: testdb
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Install dependencies
run: |
npm ci
npm install -g @angular/cli
- name: Run linting
run: npm run lint
- name: Run tests
run: |
npm run test:unit
npm run test:integration
env:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/testdb
NODE_ENV: test
- name: Upload coverage reports
uses: codecov/codecov-action@v3
with:
file: ./coverage/lcov.info
flags: unittests
name: codecov-umbrella
- name: Build application
run: npm run build
- name: Run security scan
run: |
npm audit --audit-level high
npx snyk test
# Build and push Docker image
build:
needs: test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
outputs:
image-tag: ${{ steps.meta.outputs.tags }}
image-digest: ${{ steps.build.outputs.digest }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to Container Registry
uses: docker/login-action@v2
with:
registry: ${{ env.DOCKER_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=sha,prefix={{branch}}-
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push
id: build
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
NODE_ENV=production
BUILD_DATE=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }}
VCS_REF=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }}
# Deploy to staging
deploy-staging:
needs: build
runs-on: ubuntu-latest
environment:
name: staging
url: https://staging.myapp.com
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Configure kubectl
uses: azure/setup-kubectl@v3
with:
version: 'v1.21.0'
- name: Deploy to Kubernetes
run: |
echo "${{ secrets.KUBECONFIG }}" | base64 -d > kubeconfig
export KUBECONFIG=kubeconfig
# Update image in deployment
kubectl set image deployment/web-deployment \
web=${{ needs.build.outputs.image-tag }} \
-n staging
# Wait for rollout
kubectl rollout status deployment/web-deployment -n staging --timeout=300s
# Run smoke tests
kubectl run smoke-test --rm -i --restart=Never \
--image=curlimages/curl:latest \
-- curl -f http://web-service.staging.svc.cluster.local/health
# Deploy to production
deploy-production:
needs: [build, deploy-staging]
runs-on: ubuntu-latest
environment:
name: production
url: https://myapp.com
if: github.ref == 'refs/heads/main'
steps:
- name: Manual approval
uses: trstringer/manual-approval@v1
with:
secret: ${{ github.TOKEN }}
approvers: team-leads
minimum-approvals: 2
- name: Deploy to production
run: |
# Production deployment logic here
echo "Deploying to production..."
# GITLAB CI YAML
stages:
- validate
- test
- build
- deploy-staging
- deploy-production
variables:
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: "/certs"
IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
KUBECONFIG: /tmp/kubeconfig
# Global before_script
before_script:
- echo "Starting pipeline for commit $CI_COMMIT_SHA"
# Validate stage
validate-yaml:
stage: validate
image: alpine:latest
before_script:
- apk add --no-cache yamllint
script:
- yamllint -d relaxed .
rules:
- changes:
- "**/*.yml"
- "**/*.yaml"
validate-dockerfile:
stage: validate
image: hadolint/hadolint:latest-debian
script:
- hadolint Dockerfile
rules:
- changes:
- Dockerfile
# Test stage
unit-tests:
stage: test
image: node:16-alpine
services:
- postgres:13-alpine
variables:
POSTGRES_DB: testdb
POSTGRES_USER: testuser
POSTGRES_PASSWORD: testpass
DATABASE_URL: postgres://testuser:testpass@postgres:5432/testdb
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- node_modules/
script:
- npm ci
- npm run test:coverage
coverage: '/Lines\s*:\s*(\d+\.\d+)%/'
artifacts:
reports:
coverage_report:
coverage_format: cobertura
path: coverage/cobertura-coverage.xml
expire_in: 1 week
security-scan:
stage: test
image: securecodewarrior/docker-auto-labels:latest
script:
- npm audit --audit-level high
- docker run --rm -v "$PWD":/app securecodewarrior/docker-auto-labels:latest /app
allow_failure: true
# Build stage
build-image:
stage: build
image: docker:20.10.16
services:
- docker:20.10.16-dind
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
script:
- docker build --pull -t $IMAGE_TAG .
- docker push $IMAGE_TAG
- docker tag $IMAGE_TAG $CI_REGISTRY_IMAGE:latest
- docker push $CI_REGISTRY_IMAGE:latest
rules:
- if: $CI_COMMIT_BRANCH == "main"
- if: $CI_COMMIT_BRANCH == "develop"
# Deploy staging
deploy-staging:
stage: deploy-staging
image: bitnami/kubectl:latest
environment:
name: staging
url: https://staging.myapp.com
before_script:
- echo $KUBE_CONFIG | base64 -d > $KUBECONFIG
script:
- kubectl set image deployment/web-deployment web=$IMAGE_TAG -n staging
- kubectl rollout status deployment/web-deployment -n staging
rules:
- if: $CI_COMMIT_BRANCH == "develop"
# Deploy production
deploy-production:
stage: deploy-production
image: bitnami/kubectl:latest
environment:
name: production
url: https://myapp.com
before_script:
- echo $KUBE_CONFIG_PROD | base64 -d > $KUBECONFIG
script:
- kubectl set image deployment/web-deployment web=$IMAGE_TAG -n production
- kubectl rollout status deployment/web-deployment -n production
when: manual
rules:
- if: $CI_COMMIT_BRANCH == "main"
# ANSIBLE YAML PLAYBOOKS
# Site playbook
---
- name: Deploy web application
hosts: webservers
become: yes
gather_facts: yes
vars:
app_name: myapp
app_version: "{{ version | default('latest') }}"
app_port: 3000
app_user: webapp
app_directory: "/opt/{{ app_name }}"
vars_files:
- vars/{{ ansible_environment }}.yml
- vault/secrets.yml
pre_tasks: