fix 99: support string and map variants of container

This commit is contained in:
Casey Lee
2020-02-24 22:35:08 -08:00
parent dadf8918be
commit 51b6167606
5 changed files with 63 additions and 5 deletions

View File

@@ -61,9 +61,9 @@ type Job struct {
If string `yaml:"if"`
Steps []*Step `yaml:"steps"`
TimeoutMinutes int64 `yaml:"timeout-minutes"`
Container *ContainerSpec `yaml:"container"`
Services map[string]*ContainerSpec `yaml:"services"`
Strategy *Strategy `yaml:"strategy"`
RawContainer yaml.Node `yaml:"container"`
}
// Strategy for the job
@@ -73,6 +73,26 @@ type Strategy struct {
Matrix map[string][]interface{} `yaml:"matrix"`
}
// Container details for the job
func (j *Job) Container() *ContainerSpec {
var val *ContainerSpec
switch j.RawContainer.Kind {
case yaml.ScalarNode:
val = new(ContainerSpec)
err := j.RawContainer.Decode(&val.Image)
if err != nil {
log.Fatal(err)
}
case yaml.MappingNode:
val = new(ContainerSpec)
err := j.RawContainer.Decode(val)
if err != nil {
log.Fatal(err)
}
}
return val
}
// Needs list for Job
func (j *Job) Needs() []string {