mirror of
https://github.com/kemko/nomad.git
synced 2026-01-04 01:15:43 +03:00
Rebase
This commit is contained in:
@@ -35,7 +35,7 @@ type DockerDriverAuth struct {
|
||||
type DockerDriverConfig struct {
|
||||
ImageName string `mapstructure:"image"` // Container's Image Name
|
||||
Command string `mapstructure:"command"` // The Command/Entrypoint to run when the container starts up
|
||||
Args string `mapstructure:"args"` // The arguments to the Command/Entrypoint
|
||||
Args []string `mapstructure:"args"` // The arguments to the Command/Entrypoint
|
||||
NetworkMode string `mapstructure:"network_mode"` // The network mode of the container - host, net and none
|
||||
PortMap []map[string]int `mapstructure:"port_map"` // A map of host port labels and the ports exposed on the container
|
||||
Privileged bool `mapstructure:"privileged"` // Flag to run the container in priviledged mode
|
||||
@@ -302,12 +302,12 @@ func (d *DockerDriver) createContainer(ctx *ExecContext, task *structs.Task, dri
|
||||
// inject it here.
|
||||
if driverConfig.Command != "" {
|
||||
cmd := []string{driverConfig.Command}
|
||||
if driverConfig.Args != "" {
|
||||
if len(driverConfig.Args) != 0 {
|
||||
cmd = append(cmd, parsedArgs...)
|
||||
}
|
||||
d.logger.Printf("[DEBUG] driver.docker: setting container startup command to: %s", strings.Join(cmd, " "))
|
||||
config.Cmd = cmd
|
||||
} else if driverConfig.Args != "" {
|
||||
} else if len(driverConfig.Args) != 0 {
|
||||
d.logger.Println("[DEBUG] driver.docker: ignoring command arguments because command is not specified")
|
||||
}
|
||||
|
||||
|
||||
@@ -137,7 +137,7 @@ func TestDockerDriver_Start_Wait(t *testing.T) {
|
||||
Config: map[string]interface{}{
|
||||
"image": "redis",
|
||||
"command": "redis-server",
|
||||
"args": "-v",
|
||||
"args": []string{"-v"},
|
||||
},
|
||||
Resources: &structs.Resources{
|
||||
MemoryMB: 256,
|
||||
@@ -190,7 +190,11 @@ func TestDockerDriver_Start_Wait_AllocDir(t *testing.T) {
|
||||
Config: map[string]interface{}{
|
||||
"image": "redis",
|
||||
"command": "/bin/bash",
|
||||
"args": fmt.Sprintf(`-c "sleep 1; echo -n %s > $%s/%s"`, string(exp), environment.AllocDir, file),
|
||||
"args": []string{
|
||||
"-c",
|
||||
fmt.Sprintf(`"sleep 1; echo -n %s > $%s/%s"`,
|
||||
string(exp), environment.AllocDir, file),
|
||||
},
|
||||
},
|
||||
Resources: &structs.Resources{
|
||||
MemoryMB: 256,
|
||||
@@ -243,7 +247,7 @@ func TestDockerDriver_Start_Kill_Wait(t *testing.T) {
|
||||
Config: map[string]interface{}{
|
||||
"image": "redis",
|
||||
"command": "/bin/sleep",
|
||||
"args": "10",
|
||||
"args": []string{"10"},
|
||||
},
|
||||
Resources: basicResources,
|
||||
}
|
||||
|
||||
@@ -24,10 +24,10 @@ type ExecDriver struct {
|
||||
fingerprint.StaticFingerprinter
|
||||
}
|
||||
type ExecDriverConfig struct {
|
||||
ArtifactSource string `mapstructure:"artifact_source"`
|
||||
Checksum string `mapstructure:"checksum"`
|
||||
Command string `mapstructure:"command"`
|
||||
Args string `mapstructure:"args"`
|
||||
ArtifactSource string `mapstructure:"artifact_source"`
|
||||
Checksum string `mapstructure:"checksum"`
|
||||
Command string `mapstructure:"command"`
|
||||
Args []string `mapstructure:"args"`
|
||||
}
|
||||
|
||||
// execHandle is returned from Start/Open as a handle to the PID
|
||||
@@ -91,14 +91,8 @@ func (d *ExecDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle,
|
||||
// Get the environment variables.
|
||||
envVars := TaskEnvironmentVariables(ctx, task)
|
||||
|
||||
// Look for arguments
|
||||
var args []string
|
||||
if driverConfig.Args != "" {
|
||||
args = append(args, driverConfig.Args)
|
||||
}
|
||||
|
||||
// Setup the command
|
||||
cmd := executor.Command(command, args...)
|
||||
cmd := executor.Command(command, driverConfig.Args...)
|
||||
if err := cmd.Limit(task.Resources); err != nil {
|
||||
return nil, fmt.Errorf("failed to constrain resources: %s", err)
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ func TestExecDriver_StartOpen_Wait(t *testing.T) {
|
||||
Name: "sleep",
|
||||
Config: map[string]interface{}{
|
||||
"command": "/bin/sleep",
|
||||
"args": "5",
|
||||
"args": []string{"5"},
|
||||
},
|
||||
Resources: basicResources,
|
||||
}
|
||||
@@ -73,7 +73,7 @@ func TestExecDriver_Start_Wait(t *testing.T) {
|
||||
Name: "sleep",
|
||||
Config: map[string]interface{}{
|
||||
"command": "/bin/sleep",
|
||||
"args": "2",
|
||||
"args": []string{"2"},
|
||||
},
|
||||
Resources: basicResources,
|
||||
}
|
||||
@@ -161,7 +161,10 @@ func TestExecDriver_Start_Artifact_expanded(t *testing.T) {
|
||||
Config: map[string]interface{}{
|
||||
"artifact_source": fmt.Sprintf("https://dl.dropboxusercontent.com/u/47675/jar_thing/%s", file),
|
||||
"command": "/bin/bash",
|
||||
"args": fmt.Sprintf("-c '/bin/sleep 1 && %s'", filepath.Join("$NOMAD_TASK_DIR", file)),
|
||||
"args": []string{
|
||||
"-c",
|
||||
fmt.Sprintf(`'/bin/sleep 1 && %s'`, filepath.Join("$NOMAD_TASK_DIR", file)),
|
||||
},
|
||||
},
|
||||
Resources: basicResources,
|
||||
}
|
||||
@@ -204,7 +207,10 @@ func TestExecDriver_Start_Wait_AllocDir(t *testing.T) {
|
||||
Name: "sleep",
|
||||
Config: map[string]interface{}{
|
||||
"command": "/bin/bash",
|
||||
"args": fmt.Sprintf("-c \"sleep 1; echo -n %s > $%s/%s\"", string(exp), environment.AllocDir, file),
|
||||
"args": []string{
|
||||
"-c",
|
||||
fmt.Sprintf(`"sleep 1; echo -n %s > $%s/%s"`, string(exp), environment.AllocDir, file),
|
||||
},
|
||||
},
|
||||
Resources: basicResources,
|
||||
}
|
||||
@@ -250,7 +256,7 @@ func TestExecDriver_Start_Kill_Wait(t *testing.T) {
|
||||
Name: "sleep",
|
||||
Config: map[string]interface{}{
|
||||
"command": "/bin/sleep",
|
||||
"args": "1",
|
||||
"args": []string{"1"},
|
||||
},
|
||||
Resources: basicResources,
|
||||
}
|
||||
|
||||
@@ -63,8 +63,7 @@ func (e *BasicExecutor) Start() error {
|
||||
}
|
||||
|
||||
e.cmd.Path = args.ReplaceEnv(e.cmd.Path, envVars.Map())
|
||||
combined := strings.Join(e.cmd.Args, " ")
|
||||
parsed, err := args.ParseAndReplace(combined, envVars.Map())
|
||||
parsed, err := args.ParseAndReplace(e.cmd.Args, envVars.Map())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -167,8 +167,7 @@ func (e *LinuxExecutor) Start() error {
|
||||
}
|
||||
|
||||
e.cmd.Path = args.ReplaceEnv(e.cmd.Path, envVars.Map())
|
||||
combined := strings.Join(e.cmd.Args, " ")
|
||||
parsed, err := args.ParseAndReplace(combined, envVars.Map())
|
||||
parsed, err := args.ParseAndReplace(e.cmd.Args, envVars.Map())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -28,10 +28,10 @@ type JavaDriver struct {
|
||||
}
|
||||
|
||||
type JavaDriverConfig struct {
|
||||
JvmOpts string `mapstructure:"jvm_options"`
|
||||
ArtifactSource string `mapstructure:"artifact_source"`
|
||||
Checksum string `mapstructure:"checksum"`
|
||||
Args string `mapstructure:"args"`
|
||||
JvmOpts string `mapstructure:"jvm_options"`
|
||||
ArtifactSource string `mapstructure:"artifact_source"`
|
||||
Checksum string `mapstructure:"checksum"`
|
||||
Args []string `mapstructure:"args"`
|
||||
}
|
||||
|
||||
// javaHandle is returned from Start/Open as a handle to the PID
|
||||
@@ -133,8 +133,8 @@ func (d *JavaDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle,
|
||||
|
||||
// Build the argument list.
|
||||
args = append(args, "-jar", filepath.Join(allocdir.TaskLocal, jarName))
|
||||
if driverConfig.Args != "" {
|
||||
args = append(args, driverConfig.Args)
|
||||
if len(driverConfig.Args) != 0 {
|
||||
args = append(args, driverConfig.Args...)
|
||||
}
|
||||
|
||||
// Setup the command
|
||||
|
||||
@@ -93,15 +93,9 @@ func (d *RawExecDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandl
|
||||
// Get the environment variables.
|
||||
envVars := TaskEnvironmentVariables(ctx, task)
|
||||
|
||||
// Look for arguments
|
||||
var args []string
|
||||
if driverConfig.Args != "" {
|
||||
args = append(args, driverConfig.Args)
|
||||
}
|
||||
|
||||
// Setup the command
|
||||
cmd := executor.NewBasicExecutor()
|
||||
executor.SetCommand(cmd, command, args)
|
||||
executor.SetCommand(cmd, command, driverConfig.Args)
|
||||
if err := cmd.Limit(task.Resources); err != nil {
|
||||
return nil, fmt.Errorf("failed to constrain resources: %s", err)
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ func TestRawExecDriver_StartOpen_Wait(t *testing.T) {
|
||||
Name: "sleep",
|
||||
Config: map[string]interface{}{
|
||||
"command": "/bin/sleep",
|
||||
"args": "1",
|
||||
"args": []string{"1"},
|
||||
},
|
||||
Resources: basicResources,
|
||||
}
|
||||
@@ -151,7 +151,10 @@ func TestRawExecDriver_Start_Artifact_expanded(t *testing.T) {
|
||||
Config: map[string]interface{}{
|
||||
"artifact_source": fmt.Sprintf("https://dl.dropboxusercontent.com/u/47675/jar_thing/%s", file),
|
||||
"command": "/bin/bash",
|
||||
"args": fmt.Sprintf("-c '/bin/sleep 1 && %s'", filepath.Join("$NOMAD_TASK_DIR", file)),
|
||||
"args": []string{
|
||||
"-c",
|
||||
fmt.Sprintf(`'/bin/sleep 1 && %s'`, filepath.Join("$NOMAD_TASK_DIR", file)),
|
||||
},
|
||||
},
|
||||
Resources: basicResources,
|
||||
}
|
||||
@@ -190,7 +193,7 @@ func TestRawExecDriver_Start_Wait(t *testing.T) {
|
||||
Name: "sleep",
|
||||
Config: map[string]interface{}{
|
||||
"command": "/bin/sleep",
|
||||
"args": "1",
|
||||
"args": []string{"1"},
|
||||
},
|
||||
Resources: basicResources,
|
||||
}
|
||||
@@ -232,7 +235,10 @@ func TestRawExecDriver_Start_Wait_AllocDir(t *testing.T) {
|
||||
Name: "sleep",
|
||||
Config: map[string]interface{}{
|
||||
"command": "/bin/bash",
|
||||
"args": fmt.Sprintf(`-c "sleep 1; echo -n %s > $%s/%s"`, string(exp), environment.AllocDir, file),
|
||||
"args": []string{
|
||||
"-c",
|
||||
fmt.Sprintf(`"sleep 1; echo -n %s > $%s/%s"`, string(exp), environment.AllocDir, file),
|
||||
},
|
||||
},
|
||||
Resources: basicResources,
|
||||
}
|
||||
@@ -277,7 +283,7 @@ func TestRawExecDriver_Start_Kill_Wait(t *testing.T) {
|
||||
Name: "sleep",
|
||||
Config: map[string]interface{}{
|
||||
"command": "/bin/sleep",
|
||||
"args": "1",
|
||||
"args": []string{"1"},
|
||||
},
|
||||
Resources: basicResources,
|
||||
}
|
||||
|
||||
@@ -37,8 +37,8 @@ type RktDriver struct {
|
||||
}
|
||||
|
||||
type RktDriverConfig struct {
|
||||
ImageName string `mapstructure:"image"`
|
||||
Args string `mapstructure:"args"`
|
||||
ImageName string `mapstructure:"image"`
|
||||
Args []string `mapstructure:"args"`
|
||||
}
|
||||
|
||||
// rktHandle is returned from Start/Open as a handle to the PID
|
||||
@@ -150,7 +150,7 @@ func (d *RktDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle, e
|
||||
}
|
||||
|
||||
// Add user passed arguments.
|
||||
if driverConfig.Args != "" {
|
||||
if len(driverConfig.Args) != 0 {
|
||||
parsed, err := args.ParseAndReplace(driverConfig.Args, envVars.Map())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -119,7 +119,7 @@ func TestRktDriver_Start_Wait(t *testing.T) {
|
||||
"trust_prefix": "coreos.com/etcd",
|
||||
"image": "coreos.com/etcd:v2.0.4",
|
||||
"command": "/etcd",
|
||||
"args": "--version",
|
||||
"args": []string{"--version"},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ func TestRktDriver_Start_Wait_Skip_Trust(t *testing.T) {
|
||||
Config: map[string]interface{}{
|
||||
"image": "coreos.com/etcd:v2.0.4",
|
||||
"command": "/etcd",
|
||||
"args": "--version",
|
||||
"args": []string{"--version"},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ func TestRktDriver_Start_Wait_Logs(t *testing.T) {
|
||||
"trust_prefix": "coreos.com/etcd",
|
||||
"image": "coreos.com/etcd:v2.0.4",
|
||||
"command": "/etcd",
|
||||
"args": "--version",
|
||||
"args": []string{"--version"},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user