Skip to content

Commit

Permalink
Removes consul from default pack and fixes service provider
Browse files Browse the repository at this point in the history
  • Loading branch information
mikenomitch committed Oct 24, 2023
1 parent f237a5a commit a1df3be
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
name = [[ $service.service_name | quote ]]
port = [[ $service.service_port_label | quote ]]
tags = [[ $service.service_tags | toStringList ]]
type = [[ $service.service_type | quote ]]
provider = [[ $service.service_provider | quote ]]
[[- if gt (len $service.upstreams) 0 ]]
connect {
sidecar_service {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
name = [[ $service.service_name | quote ]]
port = [[ $service.service_port_label | quote ]]
tags = [[ $service.service_tags | toStringList ]]
type = [[ $service.service_type | quote ]]
provider = [[ $service.service_provider | quote ]]
[[- if gt (len $service.upstreams) 0 ]]
connect {
sidecar_service {
Expand Down
4 changes: 2 additions & 2 deletions internal/creator/templates/pack_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ This helper creates Nomad constraint blocks from a value of type
```
list(
object(
service_name string, service_port_label string, service_type string, service_tags list(string),
service_name string, service_port_label string, service_provider string, service_tags list(string),
upstreams list(object(name string, port number))
check_type string, check_path string, check_interval string, check_timeout string
)
Expand All @@ -86,7 +86,7 @@ template.
name = [[ $service.service_name | quote ]]
port = [[ $service.service_port_label | quote ]]
tags = [[ $service.service_tags | toStringList ]]
type = [[ $service.service_type | quote ]]
provider = [[ $service.service_provider | quote ]]
[[- if $service.upstreams ]]
connect {
sidecar_service {
Expand Down
7 changes: 4 additions & 3 deletions internal/creator/templates/pack_jobspec.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ job [[ template "job_name" . ]] {
}
}

[[ if var "register_consul_service" . ]]
[[ if var "register_service" . ]]
service {
name = "[[ var "consul_service_name" . ]]"
tags = [[ var "consul_service_tags" . | toStringList ]]
name = "[[ var "service_name" . ]]"
tags = [[ var "service_tags" . | toStringList ]]
provider = "nomad"
port = "http"
check {
name = "alive"
Expand Down
30 changes: 3 additions & 27 deletions internal/creator/templates/pack_readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,6 @@ nomad-pack run {{.PackName}} --var message="Hola Mundo!"
This tells Nomad Pack to tweak the `MESSAGE` environment variable that the
service reads from.

### Consul Service and Load Balancer Integration

Optionally, it can configure a Consul service.

If the `register_consul_service` is unset or set to true, the Consul service
will be registered.

Several load balancers in the [Nomad Pack Community Registry][pack-registry]
are configured to connect to this service by default.

The [NGINX][pack-nginx] and [HAProxy][pack-haproxy] packs are configured to
balance the Consul service `{{.PackName}}-service`, which is the default value
for the `consul_service_name` variable.

The [Fabio][pack-fabio] and [Traefik][pack-traefik] packs are configured to
search for Consul services with the tags found in the default value of the
`consul_service_tags` variable.

## Variables

<!-- Include information on the variables from your pack -->
Expand All @@ -50,15 +32,9 @@ search for Consul services with the tags found in the default value of the
- `datacenters` (list of strings:["dc1"]) - A list of datacenters in the region which
are eligible for task placement
- `region` (string) - The region where jobs will be deployed
- `register_consul_service` (bool: true) - If you want to register a Consul service
- `register_service` (bool: true) - If you want to register a Nomad service
for the job
- `consul_service_tags` (list of string) - The Consul service name for the
{{.PackName}} application
- `consul_service_name` (string) - The Consul service name for the {{.PackName}}
application
- `service_tags` (list of string) - The service tags for the {{.PackName}} application
- `service_name` (string) - The service name for the {{.PackName}} application

[pack-registry]: https://github.com/hashicorp/nomad-pack-community-registry
[pack-nginx]: https://github.com/hashicorp/nomad-pack-community-registry/tree/main/packs/nginx/README.md
[pack-haproxy]: https://github.com/hashicorp/nomad-pack-community-registry/tree/main/packs/haproxy/README.md
[pack-fabio]: https://github.com/hashicorp/nomad-pack-community-registry/tree/main/packs/fabio/README.md
[pack-traefik]: https://github.com/hashicorp/nomad-pack-community-registry/tree/main/packs/traefik/traefik/README.md
16 changes: 8 additions & 8 deletions internal/creator/templates/pack_variables.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ variable "region" {
variable "datacenters" {
description = "A list of datacenters in the region which are eligible for task placement"
type = list(string)
default = ["dc1"]
default = ["*"]
}

variable "count" {
Expand All @@ -29,22 +29,22 @@ variable "message" {
default = "Hello World!"
}

variable "register_consul_service" {
description = "If you want to register a Consul service for the job"
variable "register_service" {
description = "If you want to register a Nomad service for the job"
type = bool
default = true
}

variable "consul_service_name" {
description = "The Consul service name for the {{.PackName}} application"
variable "service_name" {
description = "The service name for the {{.PackName}} application"
type = string
default = "webapp"
}

variable "consul_service_tags" {
description = "The Consul service name for the {{.PackName}} application"
variable "service_tags" {
description = "The service tags for the {{.PackName}} application"
type = list(string)
# The default value is shaped to integrate with Fabio or Traefik
# The default value is shaped to integrate with Traefik
# This routes at the root path "/", to route to this service from
# another path, change "urlprefix-/" to "urlprefix-/<PATH>" and
# "traefik.http.routers.http.rule=Path(∫/∫)" to
Expand Down
Binary file modified nomad-pack
Binary file not shown.

0 comments on commit a1df3be

Please sign in to comment.