github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/client/allocrunner/taskrunner/getter/z_getter_cmd.go (about) 1 package getter 2 3 import ( 4 "os" 5 6 "github.com/hashicorp/nomad/helper/subproc" 7 ) 8 9 const ( 10 // SubCommand is the first argument to the clone of the nomad 11 // agent process for downloading artifacts. 12 SubCommand = "artifact-isolation" 13 ) 14 15 func init() { 16 subproc.Do(SubCommand, func() int { 17 18 // get client and artifact configuration from standard IO 19 env := new(parameters) 20 if err := env.read(os.Stdin); err != nil { 21 subproc.Print("failed to read configuration: %v", err) 22 return subproc.ExitFailure 23 } 24 25 // create context with the overall timeout 26 ctx, cancel := subproc.Context(env.deadline()) 27 defer cancel() 28 29 // force quit after maximum timeout exceeded 30 subproc.SetExpiration(ctx) 31 32 // sandbox the host filesystem for this process 33 if !env.DisableFilesystemIsolation { 34 if err := lockdown(env.TaskDir); err != nil { 35 subproc.Print("failed to sandbox %s process: %v", SubCommand, err) 36 return subproc.ExitFailure 37 } 38 } 39 40 // create the go-getter client 41 // options were already transformed into url query parameters 42 // headers were already replaced and are usable now 43 c := env.client(ctx) 44 45 // run the go-getter client 46 if err := c.Get(); err != nil { 47 subproc.Print("failed to download artifact: %v", err) 48 return subproc.ExitFailure 49 } 50 51 subproc.Print("artifact download was a success") 52 return subproc.ExitSuccess 53 }) 54 }