diff --git a/front/.gitignore b/.gitignore similarity index 100% rename from front/.gitignore rename to .gitignore diff --git a/front/Chart.yaml b/Chart.yaml similarity index 100% rename from front/Chart.yaml rename to Chart.yaml diff --git a/templates/_helpers.tpl b/templates/_helpers.tpl new file mode 100644 index 0000000000000000000000000000000000000000..e27fd56b0af5af8ba3f38b91550bb01031e36338 --- /dev/null +++ b/templates/_helpers.tpl @@ -0,0 +1,53 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "MyAppCtx.name" -}} +{{- default .Chart.Name | trunc 63 | trimSuffix "-" }} +{{- end }} + + +{{/* +Application image tag +We select by default the Chart appVersion or an override in values +*/}} +{{- define "MyAppCtx.imageTag" }} +{{- $name := default .Chart.AppVersion .Values.image.tag }} +{{- printf "%s" $name }} +{{- end }} + + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +*/}} +{{- define "MyAppCtx.fullname" }} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-"}} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "MyAppCtx.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "MyAppCtx.labels" -}} +helm.sh/chart: {{ include "MyAppCtx.chart" . }} +{{ include "MyAppCtx.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "MyAppCtx.selectorLabels" -}} +app.kubernetes.io/name: {{ include "MyAppCtx.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} diff --git a/templates/api-config.yaml b/templates/api-config.yaml new file mode 100644 index 0000000000000000000000000000000000000000..d84219d9aed70ff3fcabc4fa9d1cdce08a60930a --- /dev/null +++ b/templates/api-config.yaml @@ -0,0 +1,7 @@ +apiVersion: v1 +data: + db-endpoint: {{ .Values.api.db.endpoint }} + +kind: ConfigMap +metadata: + name: api-config diff --git a/templates/api-deployment.yaml b/templates/api-deployment.yaml new file mode 100644 index 0000000000000000000000000000000000000000..3048b1e52a325a1043571251d6c9a267d522420e --- /dev/null +++ b/templates/api-deployment.yaml @@ -0,0 +1,63 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ .Values.name }}-api + annotations: + checksum/config: {{ include (print $.Template.BasePath "/api-config.yaml") . | sha256sum }} +spec: + replicas: {{ .Values.api.replicaCount }} + selector: + matchLabels: + app: {{ .Values.name }}-api + template: + metadata: + labels: + app: {{ .Values.name }}-api + spec: + containers: + - env: + - name: DB_ENDPOINT + valueFrom: + configMapKeyRef: + key: db-endpoint + name: api-config + - name: POSTGRES_DB + value: {{ .Values.db.dbName }} + - name: POSTGRES_USER + valueFrom: + secretKeyRef: + key: username + name: hydra.acid-hydra-database.credentials.postgresql.acid.zalan.do + - name: POSTGRES_PASSWORD + valueFrom: + secretKeyRef: + key: password + name: hydra.acid-hydra-database.credentials.postgresql.acid.zalan.do + image: {{ .Values.api.image.repository }}:{{ .Values.api.image.tag }} + livenessProbe: + httpGet: + path: /actuator/health/liveness + port: 8080 + initialDelaySeconds: 30 + periodSeconds: 10 + name: {{ .Values.name }}-api + ports: + - containerPort: 8080 + readinessProbe: + httpGet: + path: /actuator/health/readiness + port: 8080 + initialDelaySeconds: 30 + periodSeconds: 5 + resources: + limits: + cpu: '1' + memory: 256Mi + requests: + cpu: 100m + memory: 192Mi + imagePullSecrets: + - name: takima-school-registry + securityContext: + runAsGroup: 1001 + runAsUser: 1001 diff --git a/templates/api-ingress.yaml b/templates/api-ingress.yaml new file mode 100644 index 0000000000000000000000000000000000000000..e675cf618fddc6cb65e4bfeef7a66527d93457f3 --- /dev/null +++ b/templates/api-ingress.yaml @@ -0,0 +1,36 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + annotations: + kubernetes.io/ingress.class: nginx + {{- if .Values.api.ingress.tlsEnabled }} + kubernetes.io/tls-acme: 'true' + nginx.ingress.kubernetes.io/cors-allow-headers: Content-Type + nginx.ingress.kubernetes.io/cors-allow-methods: '*' + nginx.ingress.kubernetes.io/cors-allow-origin: {{ .Values.front.ingress.host }} + nginx.ingress.kubernetes.io/cors-expose-headers: X-Custom-Header + nginx.ingress.kubernetes.io/cors-max-age: '86400' + nginx.ingress.kubernetes.io/enable-cors: 'true' + {{- end }} + labels: + name: {{ .Values.name }}-api-ingress + name: {{ .Values.name }}-api-ingress +spec: + rules: + - host: {{ .Values.api.ingress.host }} + http: + paths: + - backend: + service: + name: {{ .Values.name }}-api-service + port: + number: 80 + path: / + pathType: Prefix +{{- if .Values.api.ingress.tlsEnabled }} + tls: + - hosts: + - {{ .Values.api.ingress.host }} + secretName: app-wildcard +{{- end }} + diff --git a/templates/api-service.yaml b/templates/api-service.yaml new file mode 100644 index 0000000000000000000000000000000000000000..2c4563bd5849a4c61e2e609f30f53c4b21360031 --- /dev/null +++ b/templates/api-service.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ .Values.name }}-api-service +spec: + ports: + - port: 80 + protocol: TCP + targetPort: 8080 + selector: + app: cdb-api diff --git a/front/templates/front-config.yaml b/templates/front-config.yaml similarity index 97% rename from front/templates/front-config.yaml rename to templates/front-config.yaml index da89df77a97e1c3bee1c975c1c7dbb9db99547b5..f04d58379c2ea533125c9fc50d42c99a95451fd7 100644 --- a/front/templates/front-config.yaml +++ b/templates/front-config.yaml @@ -11,4 +11,4 @@ metadata: name: {{ .Values.name }}-front data: API_URL: {{ $apiUrl }} -{{- end }} \ No newline at end of file +{{- end }} diff --git a/front/templates/front-deployment.yaml b/templates/front-deployment.yaml similarity index 92% rename from front/templates/front-deployment.yaml rename to templates/front-deployment.yaml index fa7c697c84c6b69bc07da8282ea9a3952024706f..96220c997dd19a0469ae07a9729d8020670445dc 100644 --- a/front/templates/front-deployment.yaml +++ b/templates/front-deployment.yaml @@ -3,6 +3,9 @@ apiVersion: apps/v1 kind: Deployment metadata: name: {{ .Values.name }}-front + annotations: + checksum/config: {{ include (print $.Template.BasePath "/front-config.yaml") . | sha256sum }} + labels: app: front spec: @@ -65,4 +68,4 @@ spec: configMapKeyRef: name: {{ .Values.name }}-front key: API_URL -{{- end }} \ No newline at end of file +{{- end }} diff --git a/front/templates/front-ingress.yaml b/templates/front-ingress.yaml similarity index 98% rename from front/templates/front-ingress.yaml rename to templates/front-ingress.yaml index 8513bb5bc872270f3785ecc4f51469e7b2b881cc..2bafaad7e4e4f4f60f2dc1a412137c471baf396f 100644 --- a/front/templates/front-ingress.yaml +++ b/templates/front-ingress.yaml @@ -23,4 +23,4 @@ spec: - {{ .Values.front.ingress.host }} secretName: app-wildcard {{- end }} -{{- end }} \ No newline at end of file +{{- end }} diff --git a/front/templates/front-service.yaml b/templates/front-service.yaml similarity index 94% rename from front/templates/front-service.yaml rename to templates/front-service.yaml index 8031d1a9e190946393c8359877c954bfb10ec2d5..1d8c47a98339ecb5112b73b4300f55e24312a87e 100644 --- a/front/templates/front-service.yaml +++ b/templates/front-service.yaml @@ -10,4 +10,4 @@ spec: - protocol: TCP port: 80 targetPort: 8080 -{{- end }} \ No newline at end of file +{{- end }} diff --git a/templates/pg-credentials.yaml b/templates/pg-credentials.yaml new file mode 100644 index 0000000000000000000000000000000000000000..210f92cfea8a0ae9fbd4692c691362d36282e741 --- /dev/null +++ b/templates/pg-credentials.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Secret +metadata: + name: hydra.acid-hydra-database.credentials.postgresql.acid.zalan.do + labels: + application: spilo + cluster-name: acid-hydra-database + team: acid +type: Opaque +data: + username: {{ .Values.db.username | b64enc }} + password: {{ .Values.db.password | b64enc }} diff --git a/templates/pg-operator.yaml b/templates/pg-operator.yaml new file mode 100644 index 0000000000000000000000000000000000000000..03c361d1e13804652aadf7efa99e8bfe800ebed0 --- /dev/null +++ b/templates/pg-operator.yaml @@ -0,0 +1,19 @@ +apiVersion: "acid.zalan.do/v1" +kind: postgresql +metadata: + annotations: + checksum/config: {{ include (print $.Template.BasePath "/pg-credentials.yaml") . | sha256sum }} + name: {{ .Values.db.prefix }}-postgresql +spec: + teamId: {{ .Values.db.prefix }} # le team id doit matcher le préfixe dans le metadata.name, ici formation + volume: + size: 1Gi + numberOfInstances: 2 + users: + {{ .Values.db.username }}: # database owner + - superuser + - createdb + databases: + {{ .Values.db.dbName }}: {{ .Values.db.username }} # dbname: owner + postgresql: + version: "14" diff --git a/front/values.yaml b/values.yaml similarity index 62% rename from front/values.yaml rename to values.yaml index 0d4183a9ac40cb4f4a4c0b67885a3719bf270cdf..7a0780101268d3a7f3855a2d186030db7a639212 100644 --- a/front/values.yaml +++ b/values.yaml @@ -5,9 +5,15 @@ name: cdb api: + image: + repository: registry.gitlab.com/takima-school/images/cdb/api + tag: latest + replicaCount: 1 ingress: - tlsEnabled: false + tlsEnabled: true host: api.czheng.takima.school + db: + endpoint: cdb-postgresql:5432 front: enabled: true @@ -18,3 +24,9 @@ front: ingress: tlsEnabled: false host: www.czheng.takima.school + +db: + dbName: cdb-db + username: username + password: password + prefix: cdb