Skip to content

Commit

Permalink
Merge pull request #4 from komminarlabs/tk/node-red
Browse files Browse the repository at this point in the history
added node-red pack
  • Loading branch information
thulasirajkomminar authored Sep 6, 2024
2 parents 97b01e2 + 784ccca commit 30e23dc
Show file tree
Hide file tree
Showing 9 changed files with 228 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ nomad-pack registry add default github.com/komminarlabs/nomad-pack-registry

- [Grafana OSS](/packs/grafana/README.md)
- [InfluxDB OSS](/packs/influxdb2/README.md)
- [Node-RED](/packs/node-red/README.md)
4 changes: 2 additions & 2 deletions packs/grafana/variables.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ variable "constraints" {
}

variable "consul_service" {
description = "The consul service for grafana."
description = "The consul service for Grafana."
type = object({
name = string
register = bool
Expand All @@ -29,7 +29,7 @@ variable "consul_service" {
}

variable "data_volume" {
description = "The dedicated data volume you want InfluxDB to use."
description = "The dedicated data volume you want Grafana to use."
type = object({
type = string
source = string
Expand Down
3 changes: 3 additions & 0 deletions packs/node-red/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 0.1.0

- Initial release
16 changes: 16 additions & 0 deletions packs/node-red/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Node-RED

This pack uses Docker driver to deploy Node-RED in Nomad.

## Variables

- `docker_env_vars` (map of string) - Environment variables to pass to Docker container.
- `node_pool` (string) - The node_pool where the job should be placed.
- `nodered_task_resources` (object) - The resource to assign to the Node-RED service task.
- `constraints` (list of object) - Constraints to apply to the entire job.
- `data_volume` (object) - The dedicated data volume you want Node-RED to use.
- `namespace` (string) - The namespace where the job should be placed.
- `nodered_version_tag` (string) - The docker image version.
- `region` (string) - The region where the job should be placed.
- `consul_service` (object) - The consul service for Node-RED.
- `datacenters` (list of string) - A list of datacenters in the region which are eligible for task placement.
16 changes: 16 additions & 0 deletions packs/node-red/metadata.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
app {
url = "https://nodered.org/"
author = "Node-RED"
}

pack {
name = "node-red"
description = "Low-code programming for event-driven applications."
url = "https://github.com/komminarlabs/nomad-pack-registry/node-red"
version = "0.1.0"
}

integration {
identifier = "nomad/komminarlabs/node-red"
name = "Node-RED"
}
3 changes: 3 additions & 0 deletions packs/node-red/outputs.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Congrats on deploying [[ meta "pack.name" . ]].

There are [[ var "app_count" . ]] instances of your job now running on Nomad.
9 changes: 9 additions & 0 deletions packs/node-red/overrides.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
data_volume = {
name = "nodered_data_volume"
type = "host"
}

docker_env_vars = {
"NODE_VERSION" : "20",
"NODE_RED_VERSION" : "4.0.2",
}
93 changes: 93 additions & 0 deletions packs/node-red/templates/node-red.nomad.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
job "node-red" {
region = "[[ var "region" . ]]"
datacenters = [[ (var "datacenters" .) | toStringList ]]
node_pool = "[[ var "node_pool" . ]]"
type = "service"
[[- if var "namespace" . ]]
namespace = "[[ var "namespace" . ]]"
[[- end ]]
[[- if var "constraints" . ]][[ range $idx, $constraint := var "constraints" . ]]
constraint {
[[- if ne $constraint.attribute "" ]]
attribute = "[[ $constraint.attribute ]]"
[[- end ]]
[[- if ne $constraint.value "" ]]
value = "[[ $constraint.value ]]"
[[- end ]]
[[- if ne $constraint.operator "" ]]
operator = "[[ $constraint.operator ]]"
[[- end ]]
}
[[- end ]]
[[- end ]]

group "node-red" {
count = 1
network {
port "http" {
static = 1880
}
}

[[- if var "consul_service.register" . ]]

service {
name = "[[ var "consul_service.name" . ]]"
[[- if ne (len (var "consul_service.tags" .)) 0 ]]
tags = [[ (var "consul_service.tags" .) | toStringList ]]
[[- end ]]
port = "http"
check {
name = "alive"
type = "tcp"
interval = "10s"
timeout = "2s"
}
}
[[- end ]]

[[- if var "data_volume" . ]]
volume "[[ var "data_volume.name" . ]]" {
type = "[[ var "data_volume.type" . ]]"
read_only = false
source = "[[ var "data_volume.name" . ]]"
}
[[- end ]]

task "node-red" {
driver = "docker"
[[- if var "data_volume" . ]]
volume_mount {
volume = "[[ var "data_volume.name" . ]]"
destination = "/data"
read_only = false
}
[[- end ]]

config {
image = "nodered/node-red:[[ var "nodered_version_tag" . ]]"
ports = ["http"]
}

resources {
cpu = [[ var "nodered_task_resources.cpu" . ]]
memory = [[ var "nodered_task_resources.memory" . ]]
}

[[- if ne (len (var "docker_env_vars" .)) 0 ]]

env {
[[- range $key, $var := var "docker_env_vars" . ]]
[[if ne (len $var) 0 ]][[ $key | upper ]] = [[ $var | quote ]][[ end ]]
[[- end ]]
}
[[- end ]]
}
}
}
85 changes: 85 additions & 0 deletions packs/node-red/variables.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
variable "constraints" {
description = "Constraints to apply to the entire job."
type = list(object({
attribute = string
operator = string
value = string
}))
default = [
{
attribute = "$${attr.kernel.name}",
value = "(linux|darwin)",
operator = "regexp",
},
]
}

variable "consul_service" {
description = "The consul service for Node-RED."
type = object({
name = string
register = bool
tags = list(string)
})
default = {
name = "nodered",
register = true,
tags = [],
}
}

variable "data_volume" {
description = "The dedicated data volume you want Node-RED to use."
type = object({
type = string
source = string
})
}

variable "datacenters" {
description = "A list of datacenters in the region which are eligible for task placement."
type = list(string)
default = ["dc1"]
}

variable "docker_env_vars" {
type = map(string)
description = "Environment variables to pass to Docker container."
default = {}
}

variable "namespace" {
description = "The namespace where the job should be placed."
type = string
default = "default"
}

variable "node_pool" {
description = "The node_pool where the job should be placed."
type = string
default = "default"
}

variable "nodered_task_resources" {
description = "The resource to assign to the Node-RED service task."
type = object({
cpu = number
memory = number
})
default = {
cpu = 500,
memory = 256,
}
}

variable "nodered_version_tag" {
description = "The docker image version."
type = string
default = "4.0.2-22"
}

variable "region" {
description = "The region where the job should be placed."
type = string
default = "global"
}

0 comments on commit 30e23dc

Please sign in to comment.