-
Notifications
You must be signed in to change notification settings - Fork 0
/
nomad.go
75 lines (64 loc) · 1.18 KB
/
nomad.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"fmt"
"os"
nomad "github.com/hashicorp/nomad/api"
)
type NomadAPI struct {
client *nomad.Client
}
func NewNomad() (*NomadAPI, error) {
addr := os.Getenv("BEE_NOMAD_ADDR")
if addr == "" {
addr = "http://localhost:4646"
}
c, err := nomad.NewClient(&nomad.Config{Address: addr})
return &NomadAPI{client: c}, err
}
func (n *NomadAPI) CreateBeeJob(b *Bee) error {
jobsApi := n.client.Jobs()
job, err := jobsApi.ParseHCL(NomadBeeHCL, true)
if err != nil {
return err
}
job.ID = &b.Id
job.Name = &b.Id
dc := os.Getenv("NOMAD_DC")
if dc == "" {
dc = "dc1"
}
job.Datacenters = append(job.Datacenters, dc)
_, _, err = jobsApi.Register(job, &nomad.WriteOptions{})
return err
}
var NomadBeeHCL = fmt.Sprintf(`
job "bee" {
group "bee" {
network {
mode = "bridge"
}
service {
name = "bee"
connect {
sidecar_service {
proxy {
upstreams {
destination_name = "redis"
local_bind_port = 6379
}
}
}
}
}
task "bee" {
driver = "docker"
env {
BEE_REDIS_ADDR = "${NOMAD_UPSTREAM_ADDR_redis}"
}
config {
image = "ghcr.io/kpenfound/bees:latest"
args = ["bee"]
}
}
}
}`)