github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/client/allocrunner/taskrunner/getter/sandbox.go (about) 1 package getter 2 3 import ( 4 "github.com/hashicorp/go-hclog" 5 "github.com/hashicorp/nomad/client/config" 6 "github.com/hashicorp/nomad/client/interfaces" 7 "github.com/hashicorp/nomad/nomad/structs" 8 ) 9 10 // New creates a Sandbox with the given ArtifactConfig. 11 func New(ac *config.ArtifactConfig, logger hclog.Logger) *Sandbox { 12 return &Sandbox{ 13 logger: logger.Named("artifact"), 14 ac: ac, 15 } 16 } 17 18 // A Sandbox is used to download artifacts. 19 type Sandbox struct { 20 logger hclog.Logger 21 ac *config.ArtifactConfig 22 } 23 24 func (s *Sandbox) Get(env interfaces.EnvReplacer, artifact *structs.TaskArtifact) error { 25 s.logger.Debug("get", "source", artifact.GetterSource, "destination", artifact.RelativeDest) 26 27 source, err := getURL(env, artifact) 28 if err != nil { 29 return err 30 } 31 32 destination, err := getDestination(env, artifact) 33 if err != nil { 34 return err 35 } 36 37 mode := getMode(artifact) 38 headers := getHeaders(env, artifact) 39 dir := getTaskDir(env) 40 41 params := ¶meters{ 42 // downloader configuration 43 HTTPReadTimeout: s.ac.HTTPReadTimeout, 44 HTTPMaxBytes: s.ac.HTTPMaxBytes, 45 GCSTimeout: s.ac.GCSTimeout, 46 GitTimeout: s.ac.GitTimeout, 47 HgTimeout: s.ac.HgTimeout, 48 S3Timeout: s.ac.S3Timeout, 49 DisableFilesystemIsolation: s.ac.DisableFilesystemIsolation, 50 SetEnvironmentVariables: s.ac.SetEnvironmentVariables, 51 52 // artifact configuration 53 Mode: mode, 54 Source: source, 55 Destination: destination, 56 Headers: headers, 57 58 // task environment 59 TaskDir: dir, 60 } 61 62 if err = s.runCmd(params); err != nil { 63 return err 64 } 65 return nil 66 }