From c8e03e4c0df6ee6740b83a2bbc408711610bee3e Mon Sep 17 00:00:00 2001 From: Ian Fijolek Date: Mon, 26 Sep 2022 16:42:25 -0700 Subject: [PATCH] WIP: Deploy immich with postgres --- ansible_hosts.yml | 12 ++ databases/adminer.nomad | 5 + databases/postgres.nomad | 98 +++++++++++ databases/postgres.tf | 39 +++++ immich.nomad | 344 +++++++++++++++++++++++++++++++++++++++ services.tf | 9 + 6 files changed, 507 insertions(+) create mode 100644 databases/postgres.nomad create mode 100644 databases/postgres.tf create mode 100644 immich.nomad diff --git a/ansible_hosts.yml b/ansible_hosts.yml index 267e3ac..5f7e7bc 100644 --- a/ansible_hosts.yml +++ b/ansible_hosts.yml @@ -13,6 +13,12 @@ all: group: "bin" mode: "0755" read_only: false + - name: postgres-data + path: /srv/volumes/postgres + owner: "root" + group: "bin" + mode: "0755" + read_only: false - name: lldap-data path: /srv/volumes/lldap owner: "root" @@ -41,6 +47,12 @@ all: group: "bin" mode: "0755" read_only: false + - name: immich-upload # TODO: Use NFS instead + path: /srv/volumes/immich-upload + owner: "root" + group: "bin" + mode: "0755" + read_only: false # n3.thefij: # nomad_node_class: ingress # nomad_node_role: both diff --git a/databases/adminer.nomad b/databases/adminer.nomad index fa33339..b0ff03b 100644 --- a/databases/adminer.nomad +++ b/databases/adminer.nomad @@ -28,6 +28,11 @@ job "adminer" { local_bind_port = 4040 } + upstreams { + destination_name = "postgres" + local_bind_port = 5432 + } + config { protocol = "tcp" } diff --git a/databases/postgres.nomad b/databases/postgres.nomad new file mode 100644 index 0000000..ae0fb12 --- /dev/null +++ b/databases/postgres.nomad @@ -0,0 +1,98 @@ +job "postgres" { + datacenters = ["dc1"] + type = "service" + priority = 80 + + group "postgres" { + count = 1 + + restart { + attempts = 10 + interval = "5m" + delay = "25s" + mode = "delay" + } + + network { + mode = "bridge" + port "db" { + host_network = "loopback" + to = 5432 + } + } + + volume "postgres-data" { + type = "host" + read_only = false + source = "postgres-data" + } + + service { + name = "postgres" + port = "db" + + connect { + sidecar_service { + proxy { + local_service_port = 5432 + } + } + + sidecar_task { + resources { + cpu = 50 + memory = 50 + } + } + } + + # Can't use a tcp check with bridge network or proxy + # check { + # type = "tcp" + # interval = "10s" + # timeout = "2s" + # } + } + + task "postgres" { + driver = "docker" + + config { + image = "postgres:14" + ports = ["db"] + } + + vault { + policies = [ + "access-tables", + "nomad-task", + ] + } + + volume_mount { + volume = "postgres-data" + destination = "/var/lib/postgresql/data" + read_only = false + } + + env = { + PGDATA = "/var/lib/postgresql/data/pgdata" + } + + template { + data = <