Skip to content

Commit cc5253b

Browse files
committed
Add PostgreSQL
1 parent 9bd9ad4 commit cc5253b

File tree

5 files changed

+105
-0
lines changed

5 files changed

+105
-0
lines changed

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ FROM node:20.9.0-slim
77
# Update basic packages
88
RUN apt-get update && apt-get install -y nano supervisor openssh-server git bash wget curl locales libc6 libstdc++6 python-is-python3 ca-certificates tar
99

10+
# Install PostgreSQL client
11+
RUN apt-get install -y postgresql-client
12+
1013
# SSH keys and some login related stuff (some work only for prod)
1114
RUN mkdir -p /run/sshd /root/.ssh \
1215
&& chmod 0700 /root/.ssh \

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
11
[Astro](https://astro.build/) is an all-in-one web framework for building fast, content-focused websites.
22
SSR support with the [Node.js](https://docs.astro.build/en/guides/integrations-guide/node/) adapter is preconfigured.
3+
4+
### PostgreSQL
5+
6+
You can optionally add a PostgreSQL DB to your project.
7+
8+
Connect via CLI:
9+
10+
```bash
11+
su postgres -c 'psql'
12+
```

diploi-template.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,35 @@ contexts:
1515
- name: app
1616
identifier: app
1717

18+
parameterGroups:
19+
- name: PostgreSQL Database
20+
identifier: postgres
21+
toggleable: true
22+
description: Database connection info
23+
defaultValue: FALSE
24+
parameters:
25+
- name: Host
26+
identifier: POSTGRES_HOST
27+
defaultValue: postgres
28+
type: string
29+
- name: Port
30+
identifier: POSTGRES_PORT
31+
defaultValue: 5432
32+
type: integer
33+
- name: User
34+
identifier: POSTGRES_USER
35+
defaultValue: postgres
36+
type: string
37+
contexts: label=postgres,label=app
38+
- name: Password
39+
identifier: POSTGRES_PASSWORD
40+
defaultValue: postgres
41+
type: secret
42+
- name: Schema
43+
identifier: POSTGRES_DB
44+
defaultValue: todo
45+
type: string
46+
1847
repositories:
1948
- name: app
2049
identifier: app
@@ -59,6 +88,12 @@ storage:
5988
stages:
6089
- development
6190
sizeMiB: 6144
91+
- identifier: postgres
92+
stages:
93+
- production
94+
- staging
95+
- development
96+
sizeMiB: 4096
6297

6398
status:
6499
url: http://app:3000/status

templates/postgres-service.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{{- if eq .Values.parameterGroupsEnabled.postgres true }}
2+
apiVersion: v1
3+
kind: Service
4+
metadata:
5+
name: postgres
6+
spec:
7+
type: NodePort
8+
ports:
9+
- name: postgres
10+
port: 5432
11+
selector:
12+
app: postgres
13+
{{ end }}

templates/postgres.yaml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{{- if eq .Values.parameterGroupsEnabled.postgres true }}
2+
apiVersion: apps/v1
3+
kind: StatefulSet
4+
metadata:
5+
name: postgres
6+
spec:
7+
selector:
8+
matchLabels:
9+
app: postgres
10+
serviceName: postgres
11+
replicas: {{ ternary 1 0 $.Values.enabled }}
12+
template:
13+
metadata:
14+
labels:
15+
app: postgres
16+
spec:
17+
containers:
18+
- name: postgres
19+
image: postgres:14.1
20+
imagePullPolicy: Always
21+
ports:
22+
- containerPort: 5432
23+
name: postgres
24+
env:
25+
- name: PGDATA
26+
value: /postgres/data
27+
{{- range $.Values.env }}
28+
{{- if contains "postgres" .contexts }}
29+
- name: {{ .identifier }}
30+
value: {{ .value | quote }}
31+
{{- end }}
32+
{{- end }}
33+
{{- range $.Values.parameterGroups }}
34+
- name: {{ .identifier }}
35+
value: {{ .value | quote }}
36+
{{- end }}
37+
volumeMounts:
38+
- name: postgres-mount
39+
mountPath: /postgres
40+
volumes:
41+
- name: postgres-mount
42+
hostPath:
43+
path: {{ $.Values.storage.postgres.hostPath }}
44+
{{ end }}

0 commit comments

Comments
 (0)