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