Skip to content

Instantly share code, notes, and snippets.

@lgfa29
Created October 26, 2021 20:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lgfa29/0758eba74676f8a5bde48152ba31d49c to your computer and use it in GitHub Desktop.
Save lgfa29/0758eba74676f8a5bde48152ba31d49c to your computer and use it in GitHub Desktop.
job "hashicups" {
datacenters = ["dc1"]
group "hashicups" {
network {
port "http" {
static = 19090
}
port "metrics" {
static = 19102
}
port "db" {
to = 5432
}
}
service {
name = "hashicups-api"
port = "http"
}
service {
name = "hashicups-db"
port = "db"
}
task "api" {
driver = "docker"
config {
image = "hashicorpdemoapp/product-api:v4280cf7"
ports = ["http", "metrics"]
volumes = ["local/config.json:/config/config.json"]
}
env {
CONFIG_FILE = "/config/config.json"
}
template {
data = <<EOF
{
"db_connection": "host={{env "NOMAD_HOST_IP_db"}} port={{env "NOMAD_HOST_PORT_db"}} user=postgres password=password dbname=products sslmode=disable",
"bind_address": "0.0.0.0:{{ env "NOMAD_PORT_http" }}",
"metrics_address": "0.0.0.0:{{ env "NOMAD_PORT_metrics" }}"
}
EOF
destination = "local/config.json"
}
}
task "db" {
driver = "docker"
config {
image = "hashicorpdemoapp/product-api-db:v4280cf7"
ports = ["db"]
}
env {
POSTGRES_DB = "products"
POSTGRES_USER = "postgres"
POSTGRES_PASSWORD = "password"
}
}
}
}
job "hashicups" {
datacenters = ["dc1"]
group "api" {
network {
port "http" {
static = 19090
}
port "metrics" {
static = 19102
}
}
service {
name = "hashicups-api"
port = "http"
check {
type = "http"
path = "/health"
interval = "5s"
timeout = "2s"
}
}
task "api" {
driver = "docker"
config {
image = "hashicorpdemoapp/product-api:v4280cf7"
ports = ["http", "metrics"]
volumes = ["local/config.json:/config/config.json"]
}
env {
CONFIG_FILE = "/config/config.json"
}
template {
data = <<EOF
{
"db_connection": {{with service "hashicups-db"}}{{with index . 0}}"host={{.Address}} port={{.Port}} user=postgres password=password dbname=products sslmode=disable"{{end}}{{end}},
"bind_address": "0.0.0.0:{{ env "NOMAD_PORT_http" }}",
"metrics_address": "0.0.0.0:{{ env "NOMAD_PORT_metrics" }}"
}
EOF
destination = "local/config.json"
}
}
}
group "db" {
network {
port "db" {
to = 5432
}
}
service {
name = "hashicups-db"
port = "db"
check {
type = "tcp"
interval = "5s"
timeout = "2s"
}
}
task "db" {
driver = "docker"
config {
image = "hashicorpdemoapp/product-api-db:v4280cf7"
ports = ["db"]
}
env {
POSTGRES_DB = "products"
POSTGRES_USER = "postgres"
POSTGRES_PASSWORD = "password"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment