From 63d7c4c1aaa40807bbb95429d40c8488c4edaec8 Mon Sep 17 00:00:00 2001 From: Renan DelValle Date: Wed, 24 Jul 2019 16:43:00 -0700 Subject: [PATCH] Adding support for creating jobs which use executorless docker containers.Note, that this feature must be enabled on the aurora-scheduler manually. --- cmd/create.go | 29 ++++++++++++++++++++++++++--- hello_world_docker.yaml | 12 ++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 hello_world_docker.yaml diff --git a/cmd/create.go b/cmd/create.go index 5be3035..54033bd 100644 --- a/cmd/create.go +++ b/cmd/create.go @@ -16,6 +16,7 @@ package cmd import ( "os" + "strings" yaml "gopkg.in/yaml.v2" @@ -51,6 +52,15 @@ type ThermosProcess struct { Cmd string `yaml:"cmd"` } +type DockerContainer struct { + Name string `yaml:"name"` + Tag string `yaml:"tag"` +} + +type Container struct { + Docker *DockerContainer `yaml:"docker"` +} + type Job struct { Environment string `yaml:"environment"` Role string `yaml:"role"` @@ -63,7 +73,8 @@ type Job struct { URIs []URI `yaml:"uris"` Metadata map[string]string `yaml:"labels"` Service bool `yaml:"service"` - Thermos []ThermosProcess `yaml:",flow"` + Thermos []ThermosProcess `yaml:",flow,omitempty"` + Container *Container `yaml:"container,omitempty"` } func (j *Job) Validate() bool { @@ -152,14 +163,26 @@ func createJob(cmd *cobra.Command, args []string) { thermosExec.AddProcess(realis.NewThermosProcess(process.Name, process.Cmd)) } auroraJob.ThermosExecutor(thermosExec) - } else { + } else if job.Executor.Name != "" { // Non-Thermos executor if job.Executor.Name == "" { - log.Fatal("no executor provided") + log.Fatal("no executor name provided") } auroraJob.ExecutorName(job.Executor.Name) auroraJob.ExecutorData(job.Executor.Data) + } else if job.Container != nil { + if job.Container.Docker == nil { + log.Fatal("no container specified") + } + + if job.Container.Docker.Tag != "" && !strings.ContainsRune(job.Container.Docker.Name, ':') { + job.Container.Docker.Name += ":" + job.Container.Docker.Tag + } + auroraJob.Container(realis.NewDockerContainer().Image(job.Container.Docker.Name)) + + } else { + log.Fatal("task does not contain a thermos definition, a custom executor name, or a container to launch") } if err := client.CreateJob(auroraJob); err != nil { diff --git a/hello_world_docker.yaml b/hello_world_docker.yaml new file mode 100644 index 0000000..8fdaf26 --- /dev/null +++ b/hello_world_docker.yaml @@ -0,0 +1,12 @@ +--- +environment: "prod" +role: "vagrant" +name: "cryptography" +cpu: 2.00 +ram: 256 +disk: 128 +instances: 1 +container: + docker: + name: "rdelvalle/phoronix" + tag: cryptography