Skip to content

Commit

Permalink
feat(local): use Nomad's internal service discovery
Browse files Browse the repository at this point in the history
Add support for using Nomad's internal service discovery.
This feature depends on nomad v1.3
https://www.nomadproject.io/docs/job-specification/service#provider

Depends on deislabs/hippo#980

Signed-off-by: Adam Reese <[email protected]>
  • Loading branch information
adamreese committed Jul 1, 2022
1 parent 9cba490 commit 7dadfdf
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 70 deletions.
5 changes: 2 additions & 3 deletions local/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ The environment is ephemeral and will not persist any data.

# Prerequisites

- [Nomad](https://www.nomadproject.io/docs/install)
- [Consul](https://www.consul.io/docs/install)
- [spin](https://github.com/fermyon/spin)
- [Nomad](https://www.nomadproject.io/docs/install) v1.3 or later
- [Spin](https://github.com/fermyon/spin)

# How to Deploy

Expand Down
1 change: 0 additions & 1 deletion local/etc/consul.hcl

This file was deleted.

9 changes: 0 additions & 9 deletions local/etc/nomad.hcl
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
log_level = "INFO"
disable_update_check = true

# these settings allow Nomad to automatically find its peers through Consul
consul {
server_service_name = "nomad"
server_auto_join = true
client_service_name = "nomad-client"
client_auto_join = true
auto_advertise = true
}

server {
enabled = true
bootstrap_expect = 1
Expand Down
14 changes: 4 additions & 10 deletions local/job/bindle.nomad
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,22 @@ job "bindle" {
}

service {
name = "bindle"
port = "http"
name = "bindle"
provider = "nomad"
port = "http"

tags = [
"traefik.enable=true",
"traefik.http.routers.bindle.rule=Host(`bindle.${var.domain}`)",
]

check {
name = "alive"
type = "tcp"
interval = "10s"
timeout = "2s"
}
}

task "bindle" {
driver = "raw_exec"

artifact {
source = lookup({
linux="https://raw.githubusercontent.com/fermyon/installer/9fca2d7b641440cef0f75d38ace9cd3128b5a8a3/local/bindle/bindle-server"
linux = "https://raw.githubusercontent.com/fermyon/installer/9fca2d7b641440cef0f75d38ace9cd3128b5a8a3/local/bindle/bindle-server"
}, var.os, "https://bindle.blob.core.windows.net/releases/bindle-v0.8.0-${var.os}-${var.arch}.tar.gz")
}

Expand Down
23 changes: 9 additions & 14 deletions local/job/hippo.nomad
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,14 @@ job "hippo" {
}

service {
name = "hippo"
port = "http"
name = "hippo"
provider = "nomad"
port = "http"

tags = [
"traefik.enable=true",
"traefik.http.routers.hippo.rule=Host(`hippo.${var.domain}`)",
]

check {
name = "alive"
type = "tcp"
interval = "10s"
timeout = "2s"
}
}

task "hippo" {
Expand All @@ -66,7 +60,7 @@ job "hippo" {
}

artifact {
source = "https://gist.githubusercontent.com/bacongobbler/48dc7b01aa99fa4b893eeb6b62f8cd27/raw/fb4dae8f42bc6aea22b2566084d01fa0de845e7c/logo.svg"
source = "https://gist.githubusercontent.com/bacongobbler/48dc7b01aa99fa4b893eeb6b62f8cd27/raw/fb4dae8f42bc6aea22b2566084d01fa0de845e7c/logo.svg"
destination = "local/${var.os}-x64/wwwroot/assets/"
}

Expand All @@ -75,14 +69,15 @@ job "hippo" {
}

artifact {
source = "https://www.fermyon.com/favicon.ico"
source = "https://www.fermyon.com/favicon.ico"
destination = "local/${var.os}-x64/wwwroot/assets/"
}

env {
Hippo__PlatformDomain = var.domain
Scheduler__Driver = "nomad"
Nomad__Driver = "raw_exec"
Hippo__PlatformDomain = var.domain
Scheduler__Driver = "nomad"
Nomad__Driver = "raw_exec"
Nomad__ServiceProvider = "nomad"

Database__Driver = "sqlite"
ConnectionStrings__Database = "Data Source=hippo.db;Cache=Shared"
Expand Down
24 changes: 6 additions & 18 deletions local/job/traefik.nomad
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,15 @@ job "traefik" {
}

service {
name = "traefik"

check {
name = "alive"
type = "tcp"
port = "http"
interval = "10s"
timeout = "2s"
}
name = "traefik"
provider = "nomad"
}

task "traefik" {
driver = "raw_exec"

artifact {
source = "https://github.com/traefik/traefik/releases/download/v2.7.1/traefik_v2.7.1_${attr.kernel.name}_${attr.cpu.arch}.tar.gz"
source = "https://github.com/traefik/traefik/releases/download/v2.8.0/traefik_v2.8.0_${attr.kernel.name}_${attr.cpu.arch}.tar.gz"
}

config {
Expand All @@ -54,14 +47,9 @@ job "traefik" {
dashboard = true
insecure = true
# Enable Consul Catalog configuration backend.
[providers.consulCatalog]
prefix = "traefik"
exposedByDefault = false
[providers.consulCatalog.endpoint]
address = "127.0.0.1:8500"
scheme = "http"
[providers.nomad]
[providers.nomad.endpoint]
address = "http://127.0.0.1:4646"
EOF

destination = "local/traefik.toml"
Expand Down
15 changes: 0 additions & 15 deletions local/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ require() {
fi
}

require consul
require nomad
require spin

Expand All @@ -34,22 +33,10 @@ cd "$(dirname "${BASH_SOURCE[0]}")"
${SUDO} rm -rf ./data
mkdir -p log

echo "Starting consul..."
consul agent -dev \
-config-file ./etc/consul.hcl \
-bootstrap-expect 1 \
&>log/consul.log &

echo "Waiting for consul..."
while ! consul members &>/dev/null; do
sleep 2
done

echo "Starting nomad..."
${SUDO} nomad agent -dev \
-config ./etc/nomad.hcl \
-data-dir "${PWD}/data/nomad" \
-consul-address "127.0.0.1:8500" \
&>log/nomad.log &

echo "Waiting for nomad..."
Expand Down Expand Up @@ -111,7 +98,6 @@ done
echo
echo "Dashboards"
echo "----------"
echo "Consul: http://localhost:8500"
echo "Nomad: http://localhost:4646"
echo "Traefik: http://localhost:8081"
echo "Hippo: http://hippo.local.fermyon.link"
Expand All @@ -120,7 +106,6 @@ echo "Logs are stored in ./log"
echo
echo "Export these into your shell"
echo
echo " export CONSUL_HTTP_ADDR=http://localhost:8500"
echo " export NOMAD_ADDR=http://localhost:4646"
echo " export BINDLE_URL=http://bindle.local.fermyon.link/v1"
echo " export HIPPO_URL=http://hippo.local.fermyon.link"
Expand Down

0 comments on commit 7dadfdf

Please sign in to comment.