Skip to content

Commit

Permalink
Add PostgreSQL
Browse files Browse the repository at this point in the history
  • Loading branch information
Munkkeli committed Feb 26, 2024
1 parent 9bd9ad4 commit cc5253b
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ FROM node:20.9.0-slim
# Update basic packages
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

# Install PostgreSQL client
RUN apt-get install -y postgresql-client

# SSH keys and some login related stuff (some work only for prod)
RUN mkdir -p /run/sshd /root/.ssh \
&& chmod 0700 /root/.ssh \
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
[Astro](https://astro.build/) is an all-in-one web framework for building fast, content-focused websites.
SSR support with the [Node.js](https://docs.astro.build/en/guides/integrations-guide/node/) adapter is preconfigured.

### PostgreSQL

You can optionally add a PostgreSQL DB to your project.

Connect via CLI:

```bash
su postgres -c 'psql'
```
35 changes: 35 additions & 0 deletions diploi-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,35 @@ contexts:
- name: app
identifier: app

parameterGroups:
- name: PostgreSQL Database
identifier: postgres
toggleable: true
description: Database connection info
defaultValue: FALSE
parameters:
- name: Host
identifier: POSTGRES_HOST
defaultValue: postgres
type: string
- name: Port
identifier: POSTGRES_PORT
defaultValue: 5432
type: integer
- name: User
identifier: POSTGRES_USER
defaultValue: postgres
type: string
contexts: label=postgres,label=app
- name: Password
identifier: POSTGRES_PASSWORD
defaultValue: postgres
type: secret
- name: Schema
identifier: POSTGRES_DB
defaultValue: todo
type: string

repositories:
- name: app
identifier: app
Expand Down Expand Up @@ -59,6 +88,12 @@ storage:
stages:
- development
sizeMiB: 6144
- identifier: postgres
stages:
- production
- staging
- development
sizeMiB: 4096

status:
url: http://app:3000/status
13 changes: 13 additions & 0 deletions templates/postgres-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{- if eq .Values.parameterGroupsEnabled.postgres true }}
apiVersion: v1
kind: Service
metadata:
name: postgres
spec:
type: NodePort
ports:
- name: postgres
port: 5432
selector:
app: postgres
{{ end }}
44 changes: 44 additions & 0 deletions templates/postgres.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{{- if eq .Values.parameterGroupsEnabled.postgres true }}
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: postgres
spec:
selector:
matchLabels:
app: postgres
serviceName: postgres
replicas: {{ ternary 1 0 $.Values.enabled }}
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: postgres:14.1
imagePullPolicy: Always
ports:
- containerPort: 5432
name: postgres
env:
- name: PGDATA
value: /postgres/data
{{- range $.Values.env }}
{{- if contains "postgres" .contexts }}
- name: {{ .identifier }}
value: {{ .value | quote }}
{{- end }}
{{- end }}
{{- range $.Values.parameterGroups }}
- name: {{ .identifier }}
value: {{ .value | quote }}
{{- end }}
volumeMounts:
- name: postgres-mount
mountPath: /postgres
volumes:
- name: postgres-mount
hostPath:
path: {{ $.Values.storage.postgres.hostPath }}
{{ end }}

0 comments on commit cc5253b

Please sign in to comment.