Browse Source

chore: separate app and db jobs

pull/5/head
Karan Sharma 8 months ago
parent
commit
bf9ce66650
  1. 47
      terraform/modules/shynet/conf/app.nomad
  2. 57
      terraform/modules/shynet/conf/db.nomad
  3. 12
      terraform/modules/shynet/job.tf

47
terraform/modules/shynet/conf/shynet.nomad → terraform/modules/shynet/conf/app.nomad

@ -1,4 +1,4 @@
job "shynet" {
job "shynet-app" {
datacenters = ["hydra"]
type = "service"
@ -9,11 +9,6 @@ job "shynet" {
port "http" {
to = 8080
}
port "db" {
to = 5432
host_network = "tailscale"
}
}
restart {
@ -59,6 +54,7 @@ job "shynet" {
PERFORM_CHECKS_AND_SETUP = "True"
PORT = 8080
ONLY_SUPERUSERS_CREATE = "True"
NUM_WORKERS = 2
}
template {
@ -77,44 +73,9 @@ job "shynet" {
}
resources {
cpu = 200
memory = 100
}
}
task "db" {
driver = "docker"
service {
name = "shynet-db"
tags = ["shynet", "db"]
port = "db"
}
config {
image = "postgres:13"
# Bind the data directory to preserve config.
mount {
type = "bind"
target = "/var/lib/postgresql/data"
source = "/data/shynet/db/"
readonly = false
}
ports = ["db"]
cpu = 500
memory = 400
}
env {
POSTGRES_DB = "shynet"
POSTGRES_USER = "shynet"
POSTGRES_PASSWORD = "${shynet_postgresql_password}"
}
# resources {
# cpu = 200
# memory = 200
# }
}
}
}

57
terraform/modules/shynet/conf/db.nomad

@ -0,0 +1,57 @@
job "shynet-db" {
datacenters = ["hydra"]
type = "service"
group "db" {
count = 1
network {
port "db" {
to = 5432
host_network = "tailscale"
}
}
restart {
attempts = 2
interval = "2m"
delay = "30s"
mode = "fail"
}
task "db" {
driver = "docker"
service {
name = "shynet-db"
tags = ["shynet", "db"]
port = "db"
}
config {
image = "postgres:13"
# Bind the data directory to preserve config.
mount {
type = "bind"
target = "/var/lib/postgresql/data"
source = "/data/shynet/db/"
readonly = false
}
ports = ["db"]
}
env {
POSTGRES_DB = "shynet"
POSTGRES_USER = "shynet"
POSTGRES_PASSWORD = "${shynet_postgresql_password}"
}
resources {
cpu = 400
memory = 400
}
}
}
}

12
terraform/modules/shynet/job.tf

@ -1,5 +1,15 @@
resource "nomad_job" "app" {
jobspec = templatefile("${path.module}/conf/shynet.nomad", {
jobspec = templatefile("${path.module}/conf/app.nomad", {
shynet_django_secret_key = var.shynet_django_secret_key,
shynet_postgresql_password = var.shynet_postgresql_password
})
hcl2 {
enabled = true
}
}
resource "nomad_job" "db" {
jobspec = templatefile("${path.module}/conf/db.nomad", {
shynet_django_secret_key = var.shynet_django_secret_key,
shynet_postgresql_password = var.shynet_postgresql_password
})

Loading…
Cancel
Save