diff --git a/cookbooks/nomad/files/etc/nomad.d/jobs/countdash-intention.hcl b/cookbooks/nomad/files/etc/nomad.d/jobs/countdash-intention.hcl new file mode 100644 index 0000000..7fc1fc0 --- /dev/null +++ b/cookbooks/nomad/files/etc/nomad.d/jobs/countdash-intention.hcl @@ -0,0 +1,8 @@ +Kind = "service-intentions" +Name = "count-api" +Sources = [ + { + Name = "count-dashboard" + Action = "allow" + } +] diff --git a/cookbooks/nomad/files/etc/nomad.d/jobs/countdash.hcl b/cookbooks/nomad/files/etc/nomad.d/jobs/countdash.hcl new file mode 100644 index 0000000..a963c47 --- /dev/null +++ b/cookbooks/nomad/files/etc/nomad.d/jobs/countdash.hcl @@ -0,0 +1,98 @@ +job "countdash" { + datacenters = ["dc1"] + group "api" { + network { + mode = "bridge" + + port "envoy_metrics" { + to = 9102 + } + } + + service { + name = "count-api" + port = "9001" + + meta { + envoy_metrics_port = "${NOMAD_HOST_PORT_envoy_metrics}" + } + + connect { + sidecar_service { + proxy { + config { + envoy_prometheus_bind_addr = "0.0.0.0:9102" + } + } + tags = ["envoy"] + } + } + } + + task "web" { + driver = "docker" + config { + image = "hashicorpnomad/counter-api:v1" + } + + # constraint { + # attribute = "${attr.unique.hostname}" + # value = "test01" + # } + } + } + + group "dashboard" { + network { + mode ="bridge" + port "http" { + static = 9002 + to = 9002 + } + + port "envoy_metrics" { + to = 9102 + } + } + + service { + name = "count-dashboard" + port = "9002" + + meta { + envoy_metrics_port = "${NOMAD_HOST_PORT_envoy_metrics}" + } + + connect { + sidecar_service { + proxy { + upstreams { + destination_name = "count-api" + local_bind_port = 8080 + } + config { + envoy_prometheus_bind_addr = "0.0.0.0:9102" + } + } + tags = ["envoy"] + } + } + } + + task "dashboard" { + driver = "docker" + env { + COUNTING_SERVICE_URL = "http://${NOMAD_UPSTREAM_ADDR_count_api}" + } + + config { + image = "hashicorpnomad/counter-dashboard:v1" + } + + # constraint { + # attribute = "${attr.unique.hostname}" + # value = "test03" + # } + } + } +} diff --git a/cookbooks/nomad/setup.rb b/cookbooks/nomad/setup.rb index 24b4edb..3661691 100644 --- a/cookbooks/nomad/setup.rb +++ b/cookbooks/nomad/setup.rb @@ -52,6 +52,14 @@ if node['nomad']['client'] group 'nomad' mode '755' end + + %w( countdash.hcl countdash-intention.hcl ).each do |f| + remote_file "/etc/nomad.d/jobs/#{f}" do + owner 'nomad' + group 'nomad' + mode '644' + end + end end # Create directory: