-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow downloading many artifacts and support unarchiving #921
Changes from 10 commits
a5896d0
a154419
2d9a83d
afc9b6a
bdc7fde
4c1be8e
dc6531c
317915b
2db5b29
a71540a
a70820d
996c2df
edab031
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ import ( | |
"log" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"runtime" | ||
"strings" | ||
"sync" | ||
|
@@ -151,11 +150,10 @@ func (e *UniversalExecutor) LaunchCmd(command *ExecCommand, ctx *ExecutorContext | |
e.cmd.Env = ctx.TaskEnv.EnvList() | ||
e.cmd.Path = ctx.TaskEnv.ReplaceEnv(command.Cmd) | ||
e.cmd.Args = append([]string{e.cmd.Path}, ctx.TaskEnv.ParseAndReplace(command.Args)...) | ||
if filepath.Base(command.Cmd) == command.Cmd { | ||
if lp, err := exec.LookPath(command.Cmd); err != nil { | ||
} else { | ||
e.cmd.Path = lp | ||
} | ||
|
||
// Ensure that the binary being started is executable. | ||
if err := e.makeExecutable(e.cmd.Path); err != nil { | ||
return nil, err | ||
} | ||
|
||
// starting the process | ||
|
@@ -280,3 +278,24 @@ func (e *UniversalExecutor) configureTaskDir() error { | |
e.cmd.Dir = taskDir | ||
return nil | ||
} | ||
|
||
// makeExecutablePosix makes the given file executable for root,group,others. | ||
func (e *UniversalExecutor) makeExecutablePosix(binPath string) error { | ||
fi, err := os.Stat(binPath) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would this work if the binPath is not absolute? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah it would be relative to Nomads cwd tho |
||
if err != nil { | ||
if os.IsNotExist(err) { | ||
return fmt.Errorf("binary %q does not exist", binPath) | ||
} | ||
return fmt.Errorf("specified binary is invalid: %v", err) | ||
} | ||
|
||
// If it is not executable, make it so. | ||
perm := fi.Mode().Perm() | ||
req := os.FileMode(0555) | ||
if perm&req != req { | ||
if err := os.Chmod(binPath, perm|req); err != nil { | ||
return fmt.Errorf("error making %q executable: %s", binPath, err) | ||
} | ||
} | ||
return nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,6 @@ import ( | |
"github.com/hashicorp/nomad/client/driver/executor" | ||
cstructs "github.com/hashicorp/nomad/client/driver/structs" | ||
"github.com/hashicorp/nomad/client/fingerprint" | ||
"github.com/hashicorp/nomad/client/getter" | ||
"github.com/hashicorp/nomad/helper/discover" | ||
"github.com/hashicorp/nomad/nomad/structs" | ||
) | ||
|
@@ -34,10 +33,9 @@ type JavaDriver struct { | |
} | ||
|
||
type JavaDriverConfig struct { | ||
JvmOpts []string `mapstructure:"jvm_options"` | ||
ArtifactSource string `mapstructure:"artifact_source"` | ||
Checksum string `mapstructure:"checksum"` | ||
Args []string `mapstructure:"args"` | ||
JarPath string `mapstructure:"jar_path"` | ||
JvmOpts []string `mapstructure:"jvm_options"` | ||
Args []string `mapstructure:"args"` | ||
} | ||
|
||
// javaHandle is returned from Start/Open as a handle to the PID | ||
|
@@ -124,19 +122,10 @@ func (d *JavaDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle, | |
return nil, fmt.Errorf("Could not find task directory for task: %v", d.DriverContext.taskName) | ||
} | ||
|
||
// Proceed to download an artifact to be executed. | ||
path, err := getter.GetArtifact( | ||
taskDir, | ||
driverConfig.ArtifactSource, | ||
driverConfig.Checksum, | ||
d.logger, | ||
) | ||
if err != nil { | ||
return nil, err | ||
if driverConfig.JarPath == "" { | ||
return nil, fmt.Errorf("jar_path must be specified") | ||
} | ||
|
||
jarName := filepath.Base(path) | ||
|
||
args := []string{} | ||
// Look for jvm options | ||
if len(driverConfig.JvmOpts) != 0 { | ||
|
@@ -145,7 +134,7 @@ func (d *JavaDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle, | |
} | ||
|
||
// Build the argument list. | ||
args = append(args, "-jar", jarName) | ||
args = append(args, "-jar", driverConfig.JarPath) | ||
if len(driverConfig.Args) != 0 { | ||
args = append(args, driverConfig.Args...) | ||
} | ||
|
@@ -160,7 +149,7 @@ func (d *JavaDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle, | |
Cmd: exec.Command(bin, "executor", pluginLogFile), | ||
} | ||
|
||
exec, pluginClient, err := createExecutor(pluginConfig, d.config.LogOutput, d.config) | ||
execImpl, pluginClient, err := createExecutor(pluginConfig, d.config.LogOutput, d.config) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We get an interface back not an impl. |
||
if err != nil { | ||
return nil, err | ||
} | ||
|
@@ -175,7 +164,12 @@ func (d *JavaDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle, | |
ResourceLimits: true, | ||
} | ||
|
||
ps, err := exec.LaunchCmd(&executor.ExecCommand{Cmd: "java", Args: args}, executorCtx) | ||
absPath, err := GetAbsolutePath("java") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
ps, err := execImpl.LaunchCmd(&executor.ExecCommand{Cmd: absPath, Args: args}, executorCtx) | ||
if err != nil { | ||
pluginClient.Kill() | ||
return nil, fmt.Errorf("error starting process via the plugin: %v", err) | ||
|
@@ -186,7 +180,7 @@ func (d *JavaDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle, | |
maxKill := d.DriverContext.config.MaxKillTimeout | ||
h := &javaHandle{ | ||
pluginClient: pluginClient, | ||
executor: exec, | ||
executor: execImpl, | ||
userPid: ps.Pid, | ||
isolationConfig: ps.IsolationConfig, | ||
taskDir: taskDir, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment?