/
job_push.go
50 lines (39 loc) · 975 Bytes
/
job_push.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
package core
import (
"context"
"fmt"
"github.com/otiai10/daap"
"golang.org/x/sync/errgroup"
)
// Push uploads result files to cloud storage services according to
// specified "output" URLs of tasks file.
func (job *Job) Push() error {
eg := new(errgroup.Group)
for _, output := range job.Parameters.Outputs {
o := output
eg.Go(func() error { return job.push(o) })
}
return eg.Wait()
}
func (job *Job) push(output *Output) error {
ctx := context.Background()
push := &daap.Execution{
Inline: "/scripts/upload.sh",
Env: []string{
fmt.Sprintf("%s=%s", "SOURCE", output.DeployedPath),
fmt.Sprintf("%s=%s", "DEST", output.URL),
},
Inspect: true,
}
stream, err := job.Container.Routine.Exec(ctx, push)
if err != nil {
return err
}
for payload := range stream {
job.Stdio(payload.Type, PUSH, payload.Text())
}
if push.ExitCode != 0 {
return fmt.Errorf("failed to upload `%s` with %d", output.URL, push.ExitCode)
}
return nil
}