HashiCorp Nomad Triton driver plugin
Build Nomad and place the binary in the plugins directory. This is specified in the config.hcl
go build -v . && sudo mv nomad-driver-triton plugins
Download Consul from https://www.consul.io/downloads.html, run it in dev mode to get started quickly.
consul agent -dev -bind 0.0.0.0 -client 0.0.0.0
Evaluate the account that you want the Nomad Agent to run against.
eval "$(triton env bruce_dev)" && eval "$(ssh-agent)" && ssh-add
Run Nomad in Dev Mode also, provide the absolute path "./" Doesn't work. :(
nomad agent -dev -config=config.hcl -data-dir=/home/arch/go/src/github.com/Smithx10/nomad-driver-triton -plugin-dir=/h
ome/arch/go/src/github.com/Smithx10/nomad-driver-triton/plugins -bind=0.0.0.0
Run an example. Please populate the example.nomad with the correct values that fit your environment.
nomad run example.nomad
You can access the Web UI of Nomad on :4646/ui, and Consul on :8500/ui
taskConfigSpec = hclspec.NewObject(map[string]*hclspec.Spec{
"api_type": hclspec.NewAttr("api_type", "string", true),
"docker_api": hclspec.NewBlock("docker_api", false, hclspec.NewObject(map[string]*hclspec.Spec{
"cmd": hclspec.NewAttr("cmd", "list(string)", false),
"entrypoint": hclspec.NewAttr("entrypoint", "list(string)", false),
"openstdin": hclspec.NewAttr("openstdin", "bool", false),
"stdinonce": hclspec.NewAttr("stdinonce", "bool", false),
"tty": hclspec.NewAttr("tty", "bool", false),
"workingdir": hclspec.NewAttr("workingdir", "string", false),
"hostname": hclspec.NewAttr("hostname", "string", false),
"dns": hclspec.NewAttr("dns", "list(string)", false),
"dns_search": hclspec.NewAttr("dns_search", "list(string)", false),
"extra_hosts": hclspec.NewAttr("extra_hosts", "list(string)", false),
"user": hclspec.NewAttr("user", "string", false),
"domain_name": hclspec.NewAttr("domain_name", "string", false),
"labels": hclspec.NewBlockAttrs("labels", "string", false),
"public_network": hclspec.NewAttr("public_network", "string", false),
"private_network": hclspec.NewAttr("private_network", "string", false),
"log_config": hclspec.NewBlock("log_config", false, hclspec.NewObject(map[string]*hclspec.Spec{
"type": hclspec.NewAttr("type", "string", false),
"config": hclspec.NewBlockAttrs("config", "string", false),
})),
"ports": hclspec.NewBlock("ports", false, hclspec.NewObject(map[string]*hclspec.Spec{
"tcp": hclspec.NewAttr("tcp", "list(number)", false),
"udp": hclspec.NewAttr("udp", "list(number)", false),
"publish_all": hclspec.NewAttr("publish_all", "bool", false),
})),
"image": hclspec.NewBlock("image", true, hclspec.NewObject(map[string]*hclspec.Spec{
"name": hclspec.NewAttr("name", "string", true),
"tag": hclspec.NewAttr("tag", "string", false),
"auto_pull": hclspec.NewAttr("auto_pull", "bool", false),
})),
"restart_policy": hclspec.NewAttr("restart_policy", "string", false),
})),
"cloud_api": hclspec.NewBlock("cloud_api", false, hclspec.NewObject(map[string]*hclspec.Spec{
"image": hclspec.NewBlock("image", true, hclspec.NewObject(map[string]*hclspec.Spec{
"name": hclspec.NewAttr("name", "string", false),
"uuid": hclspec.NewAttr("uuid", "string", false),
"version": hclspec.NewAttr("version", "string", false),
"most_recent": hclspec.NewAttr("most_recent", "bool", false),
})),
"networks": hclspec.NewBlockList("networks", hclspec.NewObject(map[string]*hclspec.Spec{
"name": hclspec.NewAttr("name", "string", false),
"uuid": hclspec.NewAttr("uuid", "string", false),
})),
"user_data": hclspec.NewAttr("user_data", "string", false),
"cloud_config": hclspec.NewAttr("cloud_config", "string", false),
"user_script": hclspec.NewAttr("user_script", "string", false),
})),
"tags": hclspec.NewBlockAttrs("tags", "string", false),
"affinity": hclspec.NewAttr("affinity", "list(string)", false),
"deletion_protection": hclspec.NewAttr("deletion_protection", "bool", false),
"fwenabled": hclspec.NewAttr("fwenabled", "bool", false),
"fwrules": hclspec.NewBlockAttrs("fwrules", "string", false),
"cns": hclspec.NewAttr("cns", "list(string)", false),
"package": hclspec.NewBlock("package", true, hclspec.NewObject(map[string]*hclspec.Spec{
"name": hclspec.NewAttr("name", "string", false),
"uuid": hclspec.NewAttr("uuid", "string", false),
"version": hclspec.NewAttr("version", "string", false),
})),
"exit_strategy": hclspec.NewAttr("exit_strategy", "string", false),
})
Dictates which Triton Provisioning API you want to use.
"api_type": "cloud_api" || "docker_api"
Contains the parameters required to provision a docker instance on Triton.
"docker_api": {}
Command to run specified as a string or an array of strings.
"docker_api": {
"cmd": [
"date",
]
}
Set the entry point for the container as a string or an array of strings.
"docker_api": {
"entrypoint": [
"date",
]
}
Boolean value, opens stdin.
"docker_api": {
"openstdin": false
}
Boolean value, close stdin after the 1 attached client disconnects.
"docker_api": {
"stdinonce": false
}
Boolean value, Attach standard streams to a tty, including stdin if it is not closed.
"docker_api": {
"tty": false
}
A string specifying the working directory for commands to run in.
"docker_api": {
"workingdir": "/foo/bar"
}
A string value containing the hostname to use for the container. This must be a valid RFC 1123 hostname.
"docker_api": {
"hostname": "foo"
}
A list of DNS servers for the container to use.
"docker_api": {
"dns": [
"8.8.8.8",
"8.8.4.4",
]
}
A list of DNS search domains
"docker_api": {
"dns_search": [
"foo.com",
"rxcorp.com",
]
}
A list of hostnames/IP mappings to add to the container’s /etc/hosts file. Specified in the form ["hostname:IP"].
"docker_api": {
"extra_hosts": [
"foo:10.45.136.2",
"bar:10.45.137.3",
]
}
A string value specifying the user inside the container.
"docker_api": {
"user": "foo"
}
A string value containing the domain name to use for the container.
"docker_api": {
"domain_name": "foo.com"
}
Labels - Adds a map of labels to a container. To specify a map: {"key":"value", ... }
"docker_api": {
"labels" {
group = "webservice-cache"
bob.bill.john = "label"
test = "test"
}
}
A string value specifying the public network to use inside the container.
"docker_api": {
"public_network": "sdc_nat"
}
A string value specifying the private network to use inside the container.
"docker_api": {
"private_network": "sdc_nat"
}
Log configuration for the container.
"docker_api": {
"log_config": {}
}
A string value specifying the docker log driver type. see https://github.com/joyent/sdc-docker/blob/master/docs/api/features/logdrivers.md, https://www.joyent.com/blog/docker-log-drivers
"docker_api": {
"log_config" {
"type": "syslog",
}
}
A map of string values specifying the log options for the log driver specified.
"docker_api": {
"log_config" {
"type": "syslog",
"config" {
"syslog-address" = "tcp://host:port"
}
}
}
A stanza defining which tcp and udp ports you would like to publish.
"docker_api": {
"ports": {}
}
A list of int defining which tcp ports you would like to publish.
"docker_api": {
"ports": {
tcp = [
6379,
]
}
}
A list defining which udp ports you would like to publish.
"docker_api": {
"ports": {
udp = [
6379,
]
}
}
Allocates an ephemeral host port for all of a container’s exposed ports. Specified as a boolean value.
"docker_api": {
"publish_all": true
}
Specifies the image name,tag and pull policy to use for the container
"docker_api": {
image {
name = "redis"
tag = "latest"
auto_pull = true
}
}
Specifies the image name to use for the container.
"docker_api": {
image {
name = "redis"
tag = "latest"
auto_pull = true
}
}
Specifies the image tag to use for the container. Defaults to latest
"docker_api": {
image {
name = "redis"
tag = "latest"
auto_pull = true
}
}
A bool specifying if the Triton Docker API will attempt to pull the image.
"docker_api": {
image {
name = "redis"
tag = "latest"
auto_pull = true
}
}
The behavior to apply when the container exits. The value is an object with a Name property of either "always" to always restart, "unless-stopped" to restart always except when user has manually stopped the container or "on-failure" to restart only when the container exit code is non-zero. If on-failure is used, MaximumRetryCount controls the number of times to retry before giving up. The default is not to restart. (optional) An ever increasing delay (double the previous delay, starting at 100mS) is added before each restart to prevent flooding the server.
"docker_api": {
"restart_policy": "always"
}
Contains the parameters required to provision a cloudapi instance on Triton.
"cloud_api": {}
Contains the name, uuid, version, and most_recent attributes in order to provision a cloudapi instance on Triton.
"cloud_api": {
"image" {}
}
A string specifying the name of the image that will be used to provision a cloudapi instance on Triton.
"cloud_api": {
"image" {
"name" = "consul"
}
}
A string specifying the uuid of the image that will be used to provision a cloudapi instance on Triton.
"cloud_api": {
"image" {
"uuid" = "50719951-4dab-4fc0-9549-b36466614324"
}
}
A string specifying the version of the image that will be used to provision a cloudapi instance on Triton.
"cloud_api": {
"image" {
"version" = "1554126304"
}
}
A bool specifying to use the most recent version of the image that will be used to provision a cloudapi instance on Triton.
"cloud_api": {
"image" {
"most_recent" = true
}
}
A list of network objects specifying which networks to use while provisioning a cloudapi instance on Triton.
"cloud_api": {
"networks" = [
{
name = "sdc_nat"
},
{
name = "consul"
},
]
}
A string specifying the name of a network to use while provisioning a cloudapi instance on Triton.
"cloud_api": {
"networks" = [
{
name = "sdc_nat"
},
{
name = "consul"
},
]
}
A list of network objects specifying which networks to use while provisioning a cloudapi instance on Triton.
"cloud_api": {
"networks" = [
{
uuid = "50719951-4dab-4fc0-9549-b36466614324"
},
{
uuid = "50719951-4dab-4fc0-9549-b36466614324"
},
]
}
A string specifying the user_data that will be used when provisioning a cloudapi instance on Triton.
"cloud_api": {
"user_data" = "'{ "foo": "bar"}'"
}
A string specifying the cloud_config that will be used when provisioning a cloudapi instance on Triton.
"cloud_api": {
"cloud_config: "cloud_config string here"
}
A string specifying the user_script that will be used when provisioning a cloudapi instance on Triton.
"cloud_api": {
"user_script: "user_script string here"
}
A map of string specifying the k:v tags that will be used when provisioning a instance on Triton.
tags = {
consul = "true"
}
A list of string specifying the affinity rules that will be used when provisioning an instance on Triton.
affinity = [
"rule 1 here",
]
A bool specifying whether to enable deletion protection for the instance on Triton.
deletion_protection = false
A bool specifying whether to enable the firewall for the instance on Triton.
fwenabled = false
A map of string specifying the firewall rules to use while provisioning an instance on Triton.
fwrules = {
anytoconsului = "FROM any TO tag consul ALLOW tcp (PORT 22 AND PORT 8500)"
consultcp = "FROM tag consul TO tag consul ALLOW tcp PORT all"
consuludp = "FROM tag consul TO tag consul ALLOW udp PORT all"
}
A list of string specifying the cns service names to use while provisioning an instance on Triton.
cns = [
"consul",
]
Specifies the package name and version or uuid to use while provisioning an instance on Triton.
package {
name = "sample-512M"
}
Specifies the package name to use while provisioning an instance on Triton.
package {
name = "sample-512M"
}
Specifies the package version to use while provisioning an instance on Triton.
package {
name = "sample-512M"
version = "0.0.1"
}
Specifies the package uuid to use while provisioning an instance on Triton.
package {
uuid = "50719951-4dab-4fc0-9549-b36466614324"
}
A string specifying the desired exit strategy for the nomad task. Can be either "stopped" or "deleted". Defaults to "stopped".
exit_stratey = "deleted"
Read https://github.com/hashicorp/nomad/blob/website/plugin-docs/website/source/docs/internals/plugins/task-drivers.html.md and then make changes and open a PR.