2017-03-05 09:56:08 +02:00
|
|
|
package yaml
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
libcompose "github.com/docker/libcompose/yaml"
|
2019-11-14 21:16:03 +02:00
|
|
|
"gopkg.in/yaml.v3"
|
2017-03-05 09:56:08 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
|
|
|
// Config defines a pipeline configuration.
|
|
|
|
Config struct {
|
2017-06-03 17:29:02 +02:00
|
|
|
Cache libcompose.Stringorslice
|
2017-03-05 09:56:08 +02:00
|
|
|
Platform string
|
|
|
|
Branches Constraint
|
|
|
|
Workspace Workspace
|
|
|
|
Clone Containers
|
|
|
|
Pipeline Containers
|
|
|
|
Services Containers
|
|
|
|
Networks Networks
|
|
|
|
Volumes Volumes
|
|
|
|
Labels libcompose.SliceorMap
|
2019-06-12 11:03:59 +02:00
|
|
|
DependsOn []string `yaml:"depends_on,omitempty"`
|
2019-06-17 09:06:36 +02:00
|
|
|
RunsOn []string `yaml:"runs_on,omitempty"`
|
2019-06-24 11:19:12 +02:00
|
|
|
SkipClone bool `yaml:"skip_clone"`
|
2017-03-05 09:56:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Workspace defines a pipeline workspace.
|
|
|
|
Workspace struct {
|
|
|
|
Base string
|
|
|
|
Path string
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
// Parse parses the configuration from bytes b.
|
|
|
|
func Parse(r io.Reader) (*Config, error) {
|
|
|
|
out, err := ioutil.ReadAll(r)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return ParseBytes(out)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ParseBytes parses the configuration from bytes b.
|
|
|
|
func ParseBytes(b []byte) (*Config, error) {
|
|
|
|
out := new(Config)
|
|
|
|
err := yaml.Unmarshal(b, out)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return out, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ParseString parses the configuration from string s.
|
|
|
|
func ParseString(s string) (*Config, error) {
|
|
|
|
return ParseBytes(
|
|
|
|
[]byte(s),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ParseFile parses the configuration from path p.
|
|
|
|
func ParseFile(p string) (*Config, error) {
|
|
|
|
f, err := os.Open(p)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer f.Close()
|
|
|
|
return Parse(f)
|
|
|
|
}
|