Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update nomad jobs #2

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions nomad/app_dynamic.hcl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
job "dynamic-app" {
datacenters = ["core"]
datacenters = ["dc1"]
type = "service"
namespace = "demo"

group "dynamic-app" {
count = 1
Expand All @@ -15,6 +14,14 @@ job "dynamic-app" {
service {
name = "dynamic-app"
port = "web"

check {
type = "http"
method = "GET"
interval = "10s"
timeout = "2s"
path = "/health"
}
}
restart {
attempts = 10
Expand Down
3 changes: 1 addition & 2 deletions nomad/app_hardcoded.hcl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
job "dynamic-app" {
datacenters = ["core"]
datacenters = ["dc1"]
type = "service"
namespace = "demo"

group "dynamic-app" {
count = 1
Expand Down
3 changes: 1 addition & 2 deletions nomad/app_static.hcl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
job "dynamic-app" {
datacenters = ["core"]
datacenters = ["dc1"]
type = "service"
namespace = "demo"

group "dynamic-app" {
count = 1
Expand Down
3 changes: 1 addition & 2 deletions nomad/app_transit.hcl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
job "dynamic-app" {
datacenters = ["core"]
datacenters = ["dc1"]
type = "service"
namespace = "demo"

group "dynamic-app" {
count = 1
Expand Down
3 changes: 1 addition & 2 deletions nomad/app_transit_connect.hcl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
job "dynamic-app" {
datacenters = ["core"]
datacenters = ["dc1"]
type = "service"
namespace = "demo"

group "dynamic-app" {
count = 1
Expand Down
102 changes: 102 additions & 0 deletions nomad/app_transit_connect_traefik.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
job "dynamic-app" {
datacenters = ["dc1"]
type = "service"
namespace = "demo"

group "dynamic-app" {
count = 1

restart {
attempts = 10
interval = "5m"
delay = "25s"
mode = "delay"
}

network {
mode = "bridge"
// port "web" {
// to = 8080
// }
}

vault {
policies = ["nomad-dynamic-app"]
change_mode = "signal"
change_signal = "SIGINT"
}


service {
name = "dynamic-app"
port = "8080"
tags = ["traefik.enable=true",
"traefik.http.routers.dynamic-app.rule=Host(`dynamic-app.127.0.0.1.nip.io`)",
"traefik.http.routers.dynamic-app.entrypoints=http",
"traefik.http.routers.dynamic-app.tls=false",
"traefik.connsulcatalog.connect=true"
]
connect {
sidecar_service {
proxy {
upstreams {
destination_name = "mysql-server"
local_bind_port = 3306
}
}
}
}
check {
expose = true
type = "http"
name = "heatlh"
method = "GET"
interval = "10s"
timeout = "2s"
path = "/health"
}
}

task "dynamic-app" {
driver = "docker"

config {
image = "docker.io/mabunixda/dynamic-vault-app"
volumes = [
"local/config.ini:/usr/src/app/config/config.ini"
]
ports = [8080]
}

template {
destination = "local/config.ini"
data = <<EOF
[DEFAULT]
LogLevel = DEBUG
Port = 8080
[DATABASE]
Address = 127.0.0.1
Port = 3306

Database = my_app
{{ with secret "dynamic-app/db/creds/app" }}
User = {{ .Data.username }}
Password = {{ .Data.password }}
{{ end }}

[VAULT]
Enabled = True
InjectToken = True
Namespace =
Address = {{ env "VAULT_ADDR" }}
KeyPath = dynamic-app/transit
KeyName = app
EOF
}
resources {
cpu = 256
memory = 256
}
}
}
}
92 changes: 92 additions & 0 deletions nomad/app_transit_traefik.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
job "dynamic-app" {
datacenters = ["dc1"]
type = "service"
namespace = "demo"

group "dynamic-app" {
count = 1


vault {
policies = ["nomad-dynamic-app"]
change_mode = "signal"
change_signal = "SIGINT"
}

service {
name = "dynamic-app"
port = "web"

tags = ["traefik.enable=true",
"traefik.http.routers.${NOMAD_JOB_NAME}.rule=Host(`dynamic-app.127.0.0.1.nip.io`)",
"traefik.http.routers.${NOMAD_JOB_NAME}.entrypoints=http",
"traefik.http.routers.${NOMAD_JOB_NAME}.tls=false"
]

check {
type = "http"
method = "GET"
interval = "10s"
timeout = "2s"
path = "/health"
}
}

restart {
attempts = 10
interval = "5m"
delay = "25s"
mode = "delay"
}

task "dynamic-app" {
driver = "docker"

config {
image = "docker.io/mabunixda/dynamic-vault-app"
volumes = [
"local/config.ini:/usr/src/app/config/config.ini"
]

ports = ["web"]
}

template {
destination = "local/config.ini"
data = <<EOF
[DEFAULT]
LogLevel = DEBUG
Port = 8080
[DATABASE]
{{ range service "mysql-server" }}
Address = {{ .Address }}
Port = {{ .Port }}
{{end}}

Database = my_app
{{ with secret "dynamic-app/db/creds/app" }}
User = {{ .Data.username }}
Password = {{ .Data.password }}
{{ end }}

[VAULT]
Enabled = True
InjectToken = True
Namespace =
Address = {{ env "VAULT_ADDR" }}
KeyPath = dynamic-app/transit
KeyName = app
EOF
}
resources {
cpu = 256
memory = 256
}
}
network {
port "web" {
to = 8080
}
}
}
}
5 changes: 2 additions & 3 deletions nomad/mysql.hcl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
job "mysql-server" {
datacenters = ["core"]
datacenters = ["dc1"]
type = "service"
namespace = "demo"

group "mysql-server" {
count = 1
Expand Down Expand Up @@ -32,7 +31,7 @@ job "mysql-server" {

resources {
cpu = 500
memory = 1024
memory = 500
}
}
network {
Expand Down
8 changes: 2 additions & 6 deletions nomad/mysql_connect.hcl
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
job "mysql-server" {
datacenters = ["core"]
datacenters = ["dc1"]
type = "service"
namespace = "demo"

group "mysql-server" {
count = 1

service {
name = "mysql-server"
port = "db"

connect {
sidecar_service {}
}


}

restart {
Expand All @@ -39,7 +35,7 @@ job "mysql-server" {

resources {
cpu = 500
memory = 1024
memory = 500
}
}
network {
Expand Down
54 changes: 54 additions & 0 deletions nomad/whoami.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
job "whoami" {
datacenters = ["dc1"]
type = "service"
namespace = "demo"

group "whoami" {
count = 1
restart {
attempts = 10
interval = "5m"
delay = "25s"
mode = "delay"
}
network {
mode = "bridge"
}
service {
name = "whoami"
port = "80"
tags = ["traefik.enable=true",
"traefik.http.routers.whoami.rule=Host(`whoami.127.0.0.1.nip.io`)",
"traefik.http.routers.whoami.entrypoints=http",
"traefik.http.routers.whoami.tls=false",
"traefik.consulcatalog.connect=true"
]
connect {
sidecar_service {}
}
check {
expose = true
type = "http"
name = "heatlh"
method = "GET"
interval = "10s"
timeout = "2s"
path = "/health"
}
}
task "whoami" {
driver = "docker"

config {
image = "containous/whoami"
ports = [80]

}

resources {
cpu = 100
memory = 100
}
}
}
}