def test_docker_task(self): task = DockerTask("hello", image="hashicorp/http-echo") self.assertEqual(task.Driver, "docker") self.assertEqual(task.Name, "hello") self.assertEqual(task.Config.image, "hashicorp/http-echo") task.setDockerAuth("foo", "bar") self.assertEqual(task.Config.auth[0].username, "foo") self.assertEqual(task.Config.auth[0].password, "bar")
def test_add_task_group(self): job = Job("hello") task = DockerTask("helloworld", "hashicorp/http-echo") job.addTask(task) self.assertEqual(len(job.TaskGroups), 1) tg = job.TaskGroups[0] self.assertEqual(tg.Name, "servers") new_group_name = "myname" job.addTask(task, new_group_name) tg2 = job.TaskGroups[job.getIndexOrCreateTaskGroup(new_group_name)] self.assertEqual(tg2.Name, new_group_name)
class JobTestCase(unittest.TestCase): def setUp(self): self.task = DockerTask("hello", image="hashicorp/http-echo") pass def test_exec_task(self): task = ExecTask("hello") self.assertEqual(task.Driver, "exec") self.assertEqual(task.Name, "hello") def test_docker_task(self): task = DockerTask("hello", image="hashicorp/http-echo") self.assertEqual(task.Driver, "docker") self.assertEqual(task.Name, "hello") self.assertEqual(task.Config.image, "hashicorp/http-echo") task.setDockerAuth("foo", "bar") self.assertEqual(task.Config.auth[0].username, "foo") self.assertEqual(task.Config.auth[0].password, "bar") def test_add_template(self): self.task.addTemplate( self.task.makeTemplate("local/test.txt", "Hello World!")) my_template = self.task.Templates[0] self.assertEqual(my_template.DestPath, "local/test.txt") self.assertEqual(my_template.EmbeddedTmpl, "Hello World!") self.assertEqual(my_template.ChangeMode, self.task.change_mode) def test_add_service(self): self.task.addService("http", map_to=8080) my_service = self.task.Services[0] self.assertEqual(my_service.Name, "http") self.assertEqual(my_service.PortLabel, "http") self.assertTrue("http" in self.task.Config.port_map[0].keys()) self.assertEqual(self.task.Config.port_map[0]["http"], "8080") self.assertEqual(self.task.Resources.Networks[0].DynamicPorts[0].Label, "http")
#!/usr/bin/env nomadgen.pex from nomadgen.api import Job, DockerTask from nomadgen.util import export_if_last # Create a job from nomadgen.api.Job job = Job("consul") # Set the Datacenters where the job should run in. job.Datacenters = ["dc1"] # Set the amount of workers you need. It's recommended to use N + 3, when N is # the amount of workers required to serve at peak time. job.setWorkersCount(1) task = DockerTask("consul", "consul:1.3.0").setPort("http", 8500, 8500) task.Config.command_args = ["agent", "-dev"] # task.Config.network_mode = 'host' job.addTask(task) export_if_last(job)
def setUp(self): self.task = DockerTask("hello", image="hashicorp/http-echo") pass
#!/usr/bin/env nomadgen.pex from nomadgen.api import Job, DockerTask from nomadgen.util import export_if_last # Create a job from nomadgen.api.Job job = Job("redis") # Set the Datacenters where the job should run in. job.Datacenters = ["dc1"] # Set the amount of workers you need. It's recommended to use N + 3, when N is # the amount of workers required to serve at peak time. job.setWorkersCount(1) task = DockerTask("redis", "redis:3.2") job.addTask(task) if __name__ == "__main__": export_if_last(job)
def setUp(self): self.job = Job("hello") self.task = DockerTask("helloworld", "hashicorp/http-echo") self.job.addTask(self.task) pass
from nomadgen.jobspec.ttypes import Template from nomadgen.util import export_if_last # Create a job from nomadgen.api.Job job = Job("traefik") # Set the Datacenters where the job should run in. job.Datacenters = ["dc1"] # Set the amount of workers you need. It's recommended to use N + 3, when N is # the amount of workers required to serve at peak time. job.setWorkersCount(1) task = ( DockerTask("traefik", "traefik:latest") .setPort("http", 80) .setPort("traefik", 19999, map_to=19999) ) task.Leader = True task.Config.network_mode = "host" task.Config.command_args = ["-c", "/local/traefik.toml", "--api"] config_template = Template( DestPath="local/traefik.toml", EmbeddedTmpl=""" logLevel = "ERROR" defaultEntryPoints = ["http", "https"] [entryPoints] [entryPoints.http] address = ":{{env "NOMAD_PORT_http"}}"