@@ -2,16 +2,16 @@ package driver
22
33import (
44 "fmt"
5- "log"
6- "os/exec"
7- "path"
8- "path/filepath"
5+ "log"
6+ "os/exec"
7+ "path"
8+ "path/filepath"
99 "runtime"
1010 "syscall"
1111 "time"
1212
13- "github.com/hashicorp/go-getter"
14- "github.com/hashicorp/nomad/client/allocdir"
13+ "github.com/hashicorp/go-getter"
14+ "github.com/hashicorp/nomad/client/allocdir"
1515 "github.com/hashicorp/nomad/client/config"
1616 "github.com/hashicorp/nomad/client/executor"
1717 "github.com/hashicorp/nomad/nomad/structs"
@@ -47,40 +47,40 @@ func (d *ExecDriver) Fingerprint(cfg *config.Config, node *structs.Node) (bool,
4747}
4848
4949func (d * ExecDriver ) Start (ctx * ExecContext , task * structs.Task ) (DriverHandle , error ) {
50- // Get the command to be ran, or if omitted, download an artifact for
51- // execution. Currently a supplied command takes precedence, and an artifact
52- // is only downloaded if no command is supplied
50+ // Get the command to be ran, or if omitted, download an artifact for
51+ // execution. Currently a supplied command takes precedence, and an artifact
52+ // is only downloaded if no command is supplied
5353 command , ok := task .Config ["command" ]
5454 if ! ok || command == "" {
55- source , sok := task .Config ["artifact_source" ]
56- if ! sok || source == "" {
57- return nil , fmt .Errorf ("missing command or source for exec driver" )
58- }
59-
60- // Proceed to download an artifact to be executed.
61- // We use go-getter to support a variety of protocols, but need to change
62- // file permissions of the resulted download to be executable
63- taskDir , ok := ctx .AllocDir .TaskDirs [d .DriverContext .taskName ]
64- if ! ok {
65- return nil , fmt .Errorf ("[Err] driver.Exec: Could not find task directory for task: %v" , d .DriverContext .taskName )
66- }
67-
68- destDir := filepath .Join (taskDir , allocdir .TaskLocal )
69-
70- // Create a location to download the artifact.
71- artifactName := path .Base (source )
72- command = filepath .Join (destDir , artifactName )
73- if err := getter .GetFile (command , source ); err != nil {
74- return nil , fmt .Errorf ("[Err] driver.Exec: Error downloading source for Exec driver: %s" , err )
75- }
76-
77- cmd := exec .Command ("chmod" , "+x" , command )
78- if err := cmd .Run (); err != nil {
79- log .Printf ("[Err] driver.Exec: Error making artifact executable: %s" , err )
80- }
81-
82- // re-assign the command to be the local execution path
83- command = filepath .Join (allocdir .TaskLocal , artifactName )
55+ source , sok := task .Config ["artifact_source" ]
56+ if ! sok || source == "" {
57+ return nil , fmt .Errorf ("missing command or source for exec driver" )
58+ }
59+
60+ // Proceed to download an artifact to be executed.
61+ // We use go-getter to support a variety of protocols, but need to change
62+ // file permissions of the resulted download to be executable
63+ taskDir , ok := ctx .AllocDir .TaskDirs [d .DriverContext .taskName ]
64+ if ! ok {
65+ return nil , fmt .Errorf ("[Err] driver.Exec: Could not find task directory for task: %v" , d .DriverContext .taskName )
66+ }
67+
68+ destDir := filepath .Join (taskDir , allocdir .TaskLocal )
69+
70+ // Create a location to download the artifact.
71+ artifactName := path .Base (source )
72+ command = filepath .Join (destDir , artifactName )
73+ if err := getter .GetFile (command , source ); err != nil {
74+ return nil , fmt .Errorf ("[Err] driver.Exec: Error downloading source for Exec driver: %s" , err )
75+ }
76+
77+ cmd := exec .Command ("chmod" , "+x" , command )
78+ if err := cmd .Run (); err != nil {
79+ log .Printf ("[Err] driver.Exec: Error making artifact executable: %s" , err )
80+ }
81+
82+ // re-assign the command to be the local execution path
83+ command = filepath .Join (allocdir .TaskLocal , artifactName )
8484 }
8585
8686 // Get the environment variables.
0 commit comments