Skip to content

Commit 84201ed

Browse files
authored
Merge pull request #78 from mutablelogic/dev
Upgraded postgresql server
2 parents 6c4751b + 7e4a214 commit 84201ed

File tree

12 files changed

+369
-244
lines changed

12 files changed

+369
-244
lines changed

README.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ TODO:
112112
* [ ] Add TLS certificate support
113113
* [ ] Not sure how we can integrate with nomad services
114114

115-
116115
## Ollama
117116

118117
Ollama LLM service, with the Open WebUI.
@@ -139,10 +138,9 @@ TODO:
139138

140139
* [ ] In progress
141140
* [ ] Add TLS support
142-
* [ ] Add replication support
141+
* [ ] Add replication support
143142
* [ ] Add custom schema support
144143

145-
146144
## OpenLDAP Administation
147145

148146
OpenLDAP administration, for adding users and groups, and changing
@@ -162,18 +160,16 @@ TODO:
162160
PostgreSQL is a database server
163161

164162
* [Documentation](https://www.postgresql.org/)
165-
* [Terraform Example](_examples/postgresql.tf)
166-
* [Nomad Job](postgresql/nomad/postgresql.hcl)
163+
* [Terraform Example](_examples/postgres.tf)
164+
* [Nomad Job](postgres/nomad/postgres.hcl)
167165

168166
TODO:
169167

170168
* [ ] LDAP integration
171169
* [ ] Add TLS support
172-
* [ ] Add replication support
173170
* [ ] Use volume instead when the data does not have '/' as prefix
174171
* [ ] Add users, databases and roles support on initialization
175172

176-
177173
## Photoprism
178174

179175
Photoprism is a photo library hosting service. It uses it's own

_examples/postgres.tf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
module "postgres" {
3+
source = "github.com/mutablelogic/tf-nomad//postgres"
4+
5+
enabled = true // If false, no-op
6+
dc = var.dc
7+
namespace = var.namespace
8+
service_dns = ["192.168.86.11", "192.168.86.12", "192.168.86.13"]
9+
10+
root_user = local.POSTGRESQL_ROOT_USER // User for the 'root' user (default: postgres)
11+
root_password = local.POSTGRESQL_ROOT_PASSWORD // Password for the 'root' user
12+
replication_user = local.POSTGRESQL_REPLICATION_USER // User for the 'replication' user (default: replicator)
13+
replication_password = local.POSTGRESQL_REPLICATION_PASSWORD // Password for the 'replication' user
14+
15+
primary = "cm2" // Primary server node
16+
replicas = [ "cm3", "cm5" ] // One or more read-only replica server nodes
17+
port = 5432 // Port to expose (optional)
18+
database = "postgres" // Default database name (optional)
19+
data = "/var/lib/postgresql" // Persistence directory
20+
}

_examples/postgresql.tf

Lines changed: 0 additions & 17 deletions
This file was deleted.

postgresql/input.tf renamed to postgres/input.tf

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ variable "enabled" {
1818

1919
variable "docker_tag" {
2020
type = string
21-
description = "Version of the docker image to use, defaults to pg16"
22-
default = "pg16"
21+
description = "Version of the docker image to use, defaults to 17-bookworm"
22+
default = "17-bookworm"
2323
}
2424

2525
variable "service_provider" {
@@ -31,7 +31,7 @@ variable "service_provider" {
3131
variable "service_name" {
3232
description = "Service name"
3333
type = string
34-
default = "postgresql"
34+
default = "postgres"
3535
}
3636

3737
variable "service_dns" {
@@ -40,32 +40,37 @@ variable "service_dns" {
4040
default = []
4141
}
4242

43-
variable "service_type" {
44-
description = "Run as a service or system"
43+
variable "primary" {
4544
type = string
46-
default = "service"
45+
description = "Host to deploy the primary database on"
4746
}
4847

49-
variable "hosts" {
48+
variable "replicas" {
5049
type = list(string)
51-
description = "List of hosts to deploy on, if not specified deploys to one node"
50+
description = "Hosts to deploy read-only replica databases on"
5251
default = []
5352
}
5453

5554
variable "port" {
5655
type = number
57-
description = "Port to expose service"
56+
description = "Port to expose service for each database"
5857
default = 5432
5958
}
6059

60+
variable "database" {
61+
description = "Default database name"
62+
type = string
63+
default = "postgres"
64+
}
65+
6166
variable "data" {
6267
type = string
6368
description = "Directory for data persistence"
6469
default = ""
6570
}
6671

6772
variable "root_user" {
68-
description = "root user"
73+
description = "root user name"
6974
type = string
7075
default = "postgres"
7176
}
@@ -76,7 +81,14 @@ variable "root_password" {
7681
sensitive = true
7782
}
7883

79-
variable "database" {
80-
description = "Default database"
84+
variable "replication_user" {
85+
description = "replication user name"
8186
type = string
87+
default = "replicator"
88+
}
89+
90+
variable "replication_password" {
91+
description = "replication password (required)"
92+
type = string
93+
sensitive = true
8294
}

postgres/locals.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
locals {
3+
docker_image = "ghcr.io/mutablelogic/docker-postgres:${var.docker_tag}"
4+
docker_always_pull = false
5+
}

postgres/main.tf

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
resource "nomad_job" "postgres" {
3+
count = var.enabled ? 1 : 0
4+
jobspec = file("${path.module}/nomad/postgres.hcl")
5+
6+
hcl2 {
7+
vars = {
8+
dc = jsonencode([var.dc])
9+
namespace = var.namespace
10+
docker_image = local.docker_image
11+
docker_always_pull = jsonencode(local.docker_always_pull)
12+
service_provider = var.service_provider
13+
service_name = var.service_name
14+
service_dns = jsonencode(var.service_dns)
15+
16+
primary = var.primary
17+
replicas = jsonencode(var.replicas)
18+
port = var.port
19+
database = var.database
20+
data = var.data
21+
root_user = var.root_user
22+
root_password = var.root_password
23+
replication_user = var.replication_user
24+
replication_password = var.replication_password
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)