feat: add postgres and more templates
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2024-11-29 09:04:48 +01:00
parent 6a1dce43fd
commit 8d97ebd6d3
Signed by: kjuulh
GPG Key ID: D85D7535F18F35FA
21 changed files with 60 additions and 35 deletions

View File

@ -89,14 +89,14 @@ impl Component for PostgresDatabase {
format!("{}.yaml", self.name().replace("/", "-")), format!("{}.yaml", self.name().replace("/", "-")),
r#" r#"
{%- if environment == "dev" %} {%- if environment == "dev" %}
{% set port = 5433 %} {%- set port = 5433 %}
{% else %} {%- else %}
{% set port = 5432 %} {%- set port = 5432 %}
{%- endif%} {%- endif %}
apiVersion: v1 apiVersion: v1
kind: ConfigMap kind: ConfigMap
metadata: metadata:
name: {{ vars.cuddle_crdb.file_name(vars.cuddle_vars.service) }} name: {{ vars.cuddle_postgres.file_name(vars.cuddle_vars.service) }}
namespace: {{ vars.cluster_vars.namespace }} namespace: {{ vars.cluster_vars.namespace }}
data: data:
DATABASE_TYPE: postgresql DATABASE_TYPE: postgresql
@ -104,7 +104,8 @@ data:
DATABASE_PORT: {{ port }} DATABASE_PORT: {{ port }}
DATABASE_USER: {{ vars.cuddle_vars.service | replace("_", "-") }} DATABASE_USER: {{ vars.cuddle_vars.service | replace("_", "-") }}
DATABASE_DB: {{ vars.cuddle_vars.service | replace("_", "-") }} DATABASE_DB: {{ vars.cuddle_vars.service | replace("_", "-") }}
"#
"#
.into(), .into(),
))); )));
} }

View File

@ -354,6 +354,12 @@ async fn process_render_template(
vars => variables vars => variables
})?; })?;
let rendered = if rendered.is_empty() || rendered.ends_with("\n") {
rendered
} else {
format!("{rendered}\n")
};
dest_file.write_all(rendered.as_bytes()).await?; dest_file.write_all(rendered.as_bytes()).await?;
Ok(()) Ok(())

View File

@ -3,4 +3,4 @@
some = { some = {
thing = "some" thing = "some"
} }
} }

View File

@ -1 +1 @@
env: dev env: dev

View File

@ -1 +1 @@
env: prod env: prod

View File

@ -1 +1 @@
some_file: 4 some_file: 4

View File

@ -1 +1 @@
service service

View File

@ -6,4 +6,4 @@ metadata:
namespace: dev namespace: dev
data: data:
DATABASE_URL: postgresql://root@dev-cluster:26257/service DATABASE_URL: postgresql://root@dev-cluster:26257/service

View File

@ -36,4 +36,4 @@ spec:
- containerPort: 3001 - containerPort: 3001
name: internal-http name: internal-http
- containerPort: 3002 - containerPort: 3002
name: internal-grpc name: internal-grpc

View File

@ -118,4 +118,4 @@ spec:
tls: tls:
- hosts: - hosts:
- grpc.service.dev.internal.kjuulh.app - grpc.service.dev.internal.kjuulh.app
secretName: tls-service-kjuulh-app-internal-grpc-ingress-dns secretName: tls-service-kjuulh-app-internal-grpc-ingress-dns

View File

@ -27,4 +27,4 @@ spec:
- containerPort: 3001 - containerPort: 3001
name: internal-http name: internal-http
- containerPort: 3002 - containerPort: 3002
name: internal-grpc name: internal-grpc

View File

@ -118,4 +118,4 @@ spec:
tls: tls:
- hosts: - hosts:
- grpc.service.prod.internal.kjuulh.app - grpc.service.prod.internal.kjuulh.app
secretName: tls-service-kjuulh-app-internal-grpc-ingress-dns secretName: tls-service-kjuulh-app-internal-grpc-ingress-dns

View File

@ -27,4 +27,4 @@ spec:
- containerPort: 3001 - containerPort: 3001
name: internal-http name: internal-http
- containerPort: 3002 - containerPort: 3002
name: internal-grpc name: internal-grpc

View File

@ -0,0 +1,12 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: service-cuddle-postgres
namespace: dev
data:
DATABASE_TYPE: postgresql
DATABASE_HOST: dev.postgresql.kjuulh.app
DATABASE_PORT: 5433
DATABASE_USER: service
DATABASE_DB: service

View File

@ -1,9 +0,0 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: service-cuddle-crdb
namespace: dev
data:
DATABASE_URL: postgresql://root@dev-cluster:26257/service

View File

@ -25,15 +25,30 @@ spec:
- configMapRef: - configMapRef:
name: service-config name: service-config
env: env:
- name: DATABASE_URL - name: DATABASE_HOST
valueFrom: valueFrom:
secretKeyRef: secretKeyRef:
name: service-cuddle-crdb name: service-cuddle-postgres
key: DATABASE_URL key: DATABASE_HOST
- name: DATABASE_PORT
valueFrom:
secretKeyRef:
name: service-cuddle-postgres
key: DATABASE_PORT
- name: DATABASE_USER
valueFrom:
secretKeyRef:
name: service-cuddle-postgres
key: DATABASE_USER
- name: DATABASE_DB
valueFrom:
secretKeyRef:
name: service-cuddle-postgres
key: DATABASE_DB
ports: ports:
- containerPort: 3000 - containerPort: 3000
name: external-http name: external-http
- containerPort: 3001 - containerPort: 3001
name: internal-http name: internal-http
- containerPort: 3002 - containerPort: 3002
name: internal-grpc name: internal-grpc

View File

@ -26,7 +26,7 @@ spec:
envFrom: envFrom:
- configMapRef: - configMapRef:
name: {{service_name}}-config name: {{service_name}}-config
{%- if vars.vault_secret.has_values or vars.cuddle_crdb.has_values %} {%- if vars.vault_secret.has_values or vars.cuddle_postgres.has_values %}
env: env:
{%- if vars.vault_secret.has_values %} {%- if vars.vault_secret.has_values %}
{%- for secret in vars.vault_secret.secrets %} {%- for secret in vars.vault_secret.secrets %}

View File

@ -36,4 +36,4 @@ spec:
- containerPort: 3001 - containerPort: 3001
name: internal-http name: internal-http
- containerPort: 3002 - containerPort: 3002
name: internal-grpc name: internal-grpc

View File

@ -10,4 +10,4 @@ spec:
mount: kvv2 mount: kvv2
path: service/dev path: service/dev
refreshAfter: 30s refreshAfter: 30s
type: kv-v2 type: kv-v2