8
8
"io"
9
9
"io/ioutil"
10
10
11
- "github.com/deislabs/porter/pkg/config"
11
+ "github.com/pkg/errors"
12
+
12
13
"github.com/deislabs/porter/pkg/context"
13
14
"github.com/gobuffalo/packr/v2"
14
15
yaml "gopkg.in/yaml.v2"
@@ -18,22 +19,52 @@ import (
18
19
type Mixin struct {
19
20
* context.Context
20
21
21
- Step Step
22
+ Action Action
22
23
23
24
schemas * packr.Box
24
25
}
25
26
27
+ type Action struct {
28
+ Steps []Step // using UnmarshalYAML so that we don't need a custom type per action
29
+ }
30
+
31
+ // UnmarshalYAML takes any yaml in this form
32
+ // ACTION:
33
+ // - exec: ...
34
+ // and puts the steps into the Action.Steps field
35
+ func (a * Action ) UnmarshalYAML (unmarshal func (interface {}) error ) error {
36
+ actionMap := map [interface {}][]interface {}{}
37
+ err := unmarshal (& actionMap )
38
+ if err != nil {
39
+ return errors .Wrap (err , "could not unmarshal yaml into an action map of exec steps" )
40
+ }
41
+
42
+ for _ , stepMaps := range actionMap {
43
+ b , err := yaml .Marshal (stepMaps )
44
+ if err != nil {
45
+ return err
46
+ }
47
+
48
+ var steps []Step
49
+ err = yaml .Unmarshal (b , & steps )
50
+ if err != nil {
51
+ return err
52
+ }
53
+
54
+ a .Steps = append (a .Steps , steps ... )
55
+ }
56
+
57
+ return nil
58
+ }
59
+
26
60
type Step struct {
27
- Description string `yaml:"description"`
28
- Outputs []config.StepOutput `yaml:"outputs"`
29
- Instruction Instruction `yaml:"exec"`
61
+ Instruction `yaml:"exec"`
30
62
}
31
63
32
64
type Instruction struct {
33
- Name string `yaml:"name"`
34
- Command string `yaml:"command"`
35
- Arguments []string `yaml:"arguments"`
36
- Parameters map [string ]string `yaml:"parameters"`
65
+ Description string `yaml:"description"`
66
+ Command string `yaml:"command"`
67
+ Arguments []string `yaml:"arguments"`
37
68
}
38
69
39
70
// New exec mixin client, initialized with useful defaults.
@@ -48,16 +79,30 @@ func NewSchemaBox() *packr.Box {
48
79
return packr .New ("github.com/deislabs/porter/pkg/exec/schema" , "./schema" )
49
80
}
50
81
51
- func (m * Mixin ) LoadInstruction (commandFile string ) error {
82
+ func (m * Mixin ) loadAction (commandFile string ) error {
52
83
contents , err := m .getCommandFile (commandFile , m .Out )
53
84
if err != nil {
54
- return fmt .Errorf ("there was an error getting commands: %s" , err )
85
+ source := "STDIN"
86
+ if commandFile == "" {
87
+ source = commandFile
88
+ }
89
+ return errors .Wrapf (err , "could not load input from %s" , source )
55
90
}
56
- return yaml .Unmarshal (contents , & m .Step )
91
+
92
+ err = yaml .Unmarshal (contents , & m .Action )
93
+ if m .Debug {
94
+ fmt .Fprintf (m .Err , "DEBUG Parsed Input:\n %#v\n " , m .Action )
95
+ }
96
+ return errors .Wrapf (err , "could unmarshal input:\n %s" , string (contents ))
57
97
}
58
98
59
99
func (m * Mixin ) Execute () error {
60
- cmd := m .NewCommand (m .Step .Instruction .Command , m .Step .Instruction .Arguments ... )
100
+ if len (m .Action .Steps ) != 1 {
101
+ return errors .Errorf ("expected a single step, but got %d" , len (m .Action .Steps ))
102
+ }
103
+ step := m .Action .Steps [0 ]
104
+
105
+ cmd := m .NewCommand (step .Command , step .Arguments ... )
61
106
cmd .Stdout = m .Out
62
107
cmd .Stderr = m .Err
63
108
0 commit comments