diff --git a/nomad/app_dynamic.hcl b/nomad/app_dynamic.hcl index 91b68ed..584bcda 100644 --- a/nomad/app_dynamic.hcl +++ b/nomad/app_dynamic.hcl @@ -54,7 +54,9 @@ job "dynamic-app" { Port = {{ .Port }} {{end}} - Database = my_app + {{ with secret "dynamic-app/kv/database" }} + Database = {{ .Data.database }} + {{ end }} {{ with secret "dynamic-app/db/creds/app" }} User = {{ .Data.username }} Password = {{ .Data.password }} diff --git a/nomad/app_hardcoded.hcl b/nomad/app_hardcoded.hcl index bbb2170..db0b4cc 100644 --- a/nomad/app_hardcoded.hcl +++ b/nomad/app_hardcoded.hcl @@ -49,9 +49,9 @@ job "dynamic-app" { Port = {{ .Port }} {{end}} - Database = my_app - User = root - Password = super-duper-password + Database = app + User = app + Password = my-app-super-password EOF } resources { diff --git a/nomad/app_static.hcl b/nomad/app_static.hcl index d738e65..993e4cf 100644 --- a/nomad/app_static.hcl +++ b/nomad/app_static.hcl @@ -55,8 +55,8 @@ job "dynamic-app" { Port = {{ .Port }} {{end}} - Database = my_app {{ with secret "dynamic-app/kv/database" }} + Database = {{ .Data.database }} User = {{ .Data.username }} Password = {{ .Data.password }} {{ end }} diff --git a/nomad/app_transit_connect.hcl b/nomad/app_transit_connect.hcl index ff8621e..bff70c0 100644 --- a/nomad/app_transit_connect.hcl +++ b/nomad/app_transit_connect.hcl @@ -64,7 +64,9 @@ job "dynamic-app" { Address = 127.0.0.1 Port = 3306 - Database = my_app + {{ with secret "dynamic-app/kv/database" }} + Database = {{ .Data.database }} + {{ end }} {{ with secret "dynamic-app/db/creds/app" }} User = {{ .Data.username }} Password = {{ .Data.password }} diff --git a/nomad/app_transit_connect_traefik.hcl b/nomad/app_transit_connect_traefik.hcl index 5c5abec..921c1d7 100644 --- a/nomad/app_transit_connect_traefik.hcl +++ b/nomad/app_transit_connect_traefik.hcl @@ -15,9 +15,6 @@ job "dynamic-app" { network { mode = "bridge" - // port "web" { - // to = 8080 - // } } vault { @@ -32,8 +29,8 @@ job "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.http.routers.dynamic-app.entrypoints=https", + "traefik.http.routers.dynamic-app.tls=true", "traefik.connsulcatalog.connect=true" ] connect { @@ -78,7 +75,9 @@ job "dynamic-app" { Address = 127.0.0.1 Port = 3306 - Database = my_app + {{ with secret "dynamic-app/kv/database" }} + Database = {{ .Data.database }} + {{ end }} {{ with secret "dynamic-app/db/creds/app" }} User = {{ .Data.username }} Password = {{ .Data.password }} diff --git a/nomad/mysql.hcl b/nomad/mysql.hcl index 14d5e5d..8037e44 100644 --- a/nomad/mysql.hcl +++ b/nomad/mysql.hcl @@ -22,11 +22,17 @@ job "mysql-server" { env = { "MYSQL_ROOT_PASSWORD" = "super-duper-password" + "MYSQL_DATABASE" = "app" + "MYSQL_USER" = "app" + "MYSQL_PASSWORD" = "my-app-super-password" } config { image = "mysql:9" ports = ["db"] + volumes = [ + "/srv/mysql/:/var/lib/mysql" + ] } resources { diff --git a/nomad/mysql_connect.hcl b/nomad/mysql_connect.hcl index 408b1e9..7013e95 100644 --- a/nomad/mysql_connect.hcl +++ b/nomad/mysql_connect.hcl @@ -13,6 +13,12 @@ job "mysql-server" { } } + vault { + policies = ["nomad-dynamic-app", "nomad-mysql"] + change_mode = "signal" + change_signal = "SIGINT" + } + restart { attempts = 10 interval = "5m" @@ -23,16 +29,31 @@ job "mysql-server" { task "mysql-server" { driver = "docker" - env = { - "MYSQL_ROOT_PASSWORD" = "super-duper-password" - } - config { image = "mysql:9" - ports = ["db"] + volumes = [ + "/srv/mysql/:/var/lib/mysql" + ] } + template { + env = true + destination = "secrets/.envs" + change_mode = "noop" + env = true + data = <