From d21d0b8b38a5c403eb170756992e15d5bc6f4901 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 --- nomad/ansible_hosts.yml | 12 ++ nomad/databases/adminer.nomad | 5 + nomad/databases/postgres.nomad | 98 ++++++++++ nomad/databases/postgres.tf | 39 ++++ nomad/immich.nomad | 344 +++++++++++++++++++++++++++++++++ nomad/services.tf | 9 + 6 files changed, 507 insertions(+) create mode 100644 nomad/databases/postgres.nomad create mode 100644 nomad/databases/postgres.tf create mode 100644 nomad/immich.nomad diff --git a/nomad/ansible_hosts.yml b/nomad/ansible_hosts.yml index 267e3ac..5f7e7bc 100644 --- a/nomad/ansible_hosts.yml +++ b/nomad/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/nomad/databases/adminer.nomad b/nomad/databases/adminer.nomad index fa33339..b0ff03b 100644 --- a/nomad/databases/adminer.nomad +++ b/nomad/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/nomad/databases/postgres.nomad b/nomad/databases/postgres.nomad new file mode 100644 index 0000000..ae0fb12 --- /dev/null +++ b/nomad/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 = <