forked from GuyBarros/nomad_jobs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhashicups.nomad
111 lines (100 loc) · 2.68 KB
/
hashicups.nomad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
variable "datacenters" {
description = "A list of datacenters in the region which are eligible for task placement."
type = list(string)
default = ["eu-west-2a","eu-west-2b","eu-west-2c","eu-west-2","dc1"]
}
variable "region" {
description = "The region where the job should be placed."
type = string
default = "global"
}
variable "product_api_version" {
description = "Docker version tag"
default = "v0.0.21"
}
variable "product_api_db_version" {
description = "Docker version tag"
default = "v0.0.20"
}
variable "postgres_db" {
description = "Postgres DB name"
default = "products"
}
variable "postgres_user" {
description = "Postgres DB User"
default = "postgres"
}
variable "postgres_password" {
description = "Postgres DB Password"
default = "password"
}
variable "product_api_port" {
description = "Product API Port"
default = 9090
}
# Begin Job Spec
job "hashicups" {
type = "service"
region = var.region
datacenters = var.datacenters
group "hashicups" {
network {
port "db" {
static = 5432
}
port "product-api" {
static = var.product_api_port
}
}
task "db" {
driver = "docker"
meta {
service = "database"
}
service {
port = "db"
tags = ["hashicups", "backend"]
provider = "nomad"
address = attr.unique.platform.aws.public-ipv4
}
config {
image = "hashicorpdemoapp/product-api-db:${var.product_api_db_version}"
ports = ["db"]
}
env {
POSTGRES_DB = "products"
POSTGRES_USER = "postgres"
POSTGRES_PASSWORD = "password"
}
}
task "product-api" {
driver = "docker"
meta {
service = "product-api"
}
service {
port = "product-api"
tags = ["hashicups", "backend"]
provider = "nomad"
address = attr.unique.platform.aws.public-ipv4
}
config {
image = "hashicorpdemoapp/product-api:${var.product_api_version}"
ports = ["product-api"]
}
template {
data = <<EOH
{{ range nomadService "hashicups-hashicups-db" }}
DB_CONNECTION="host={{ .Address }} port={{ .Port }} user=${var.postgres_user} password=${var.postgres_password} dbname=${var.postgres_db} sslmode=disable"
{{ end }}
EOH
destination = "local/env.txt"
env = true
}
env {
DB_CONNECTION = "host=${NOMAD_IP_db} port=${NOMAD_PORT_db} user=${var.postgres_user} password=${var.postgres_password} dbname=${var.postgres_db} sslmode=disable"
BIND_ADDRESS = "0.0.0.0:${NOMAD_PORT_product-api}"
}
}
}
}