chore(n8n): add module and job specification for Nomad deployment
All checks were successful
Terraform CI/CD / Terraform Format, Validate, Lint, Scan (push) Successful in 1m10s
Terraform CI/CD / Terraform Plan (push) Has been skipped
Terraform CI/CD / Terraform Apply (push) Successful in 45s

This commit is contained in:
Ben Martin 2025-06-02 19:11:02 +01:00
parent 2c3fd199c1
commit 28e9ead743
Signed by: ben
GPG key ID: 859A655FCD290E4A
3 changed files with 136 additions and 0 deletions

View file

@ -50,3 +50,7 @@ module "jayne-martin-counselling" {
module "monica" { module "monica" {
source = "./modules/monica" source = "./modules/monica"
} }
module "n8n" {
source = "./modules/n8n"
}

View file

@ -0,0 +1,97 @@
job "n8n" {
group "n8n" {
network {
mode = "bridge"
port "http" {
to = 5678
}
port "envoy_metrics" {
to = 9102
}
}
service {
provider = "consul"
port = "5678"
meta {
envoy_metrics_port = "${NOMAD_HOST_PORT_envoy_metrics}"
}
connect {
sidecar_service {
proxy {
config {
protocol = "http"
}
expose {
path {
path = "/metrics"
protocol = "http"
local_path_port = 9102
listener_port = "envoy_metrics"
}
}
transparent_proxy {}
}
}
}
tags = [
"traefik.enable=true",
"traefik.http.routers.n8n.rule=Host(`n8n.brmartin.co.uk`)",
"traefik.http.routers.n8n.entrypoints=websecure",
"traefik.consulcatalog.connect=true",
]
}
volume "data" {
type = "csi"
read_only = false
source = "martinibar_prod_n8n_data"
attachment_mode = "file-system"
access_mode = "multi-node-single-writer"
}
task "n8n" {
driver = "docker"
config {
image = "docker.n8n.io/n8nio/n8n:1.97.0"
}
env = {
DB_TYPE = "postgresdb"
DB_POSTGRESDB_DATABASE = "n8n"
DB_POSTGRESDB_HOST = "martinibar.lan"
DB_POSTGRESDB_PORT = "5433"
DB_POSTGRESDB_USER = "n8n"
DB_POSTGRESDB_SCHEMA = "n8n"
}
template {
data = <<-EOF
{{ with nomadVar "nomad/jobs/n8n/n8n/n8n" }}
DB_POSTGRESDB_PASSWORD={{.db_password}}
{{ end }}
EOF
destination = "secrets/file.env"
env = true
}
resources {
cpu = 500
memory = 1024
}
volume_mount {
volume = "data"
destination = "/home/node/.n8n"
}
}
}
}

35
modules/n8n/main.tf Normal file
View file

@ -0,0 +1,35 @@
resource "nomad_job" "n8n" {
depends_on = [
nomad_csi_volume_registration.nfs_volume,
]
jobspec = file("${path.module}/jobspec.nomad.hcl")
}
data "nomad_plugin" "nfs" {
plugin_id = "nfs"
wait_for_healthy = true
}
resource "nomad_csi_volume_registration" "nfs_volume" {
depends_on = [data.nomad_plugin.nfs]
lifecycle {
prevent_destroy = true
}
plugin_id = "nfs"
name = "martinibar_prod_n8n_data"
volume_id = "martinibar_prod_n8n_data"
external_id = "martinibar_prod_n8n_data"
capability {
access_mode = "multi-node-single-writer"
attachment_mode = "file-system"
}
context = {
"server" = "martinibar.lan",
"share" = "/volume1/csi/n8n/data",
}
}