Skip to content

Commit

Permalink
implement yaml transformation during parsing
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <[email protected]>
  • Loading branch information
ndeloof committed Sep 26, 2023
1 parent 09fd935 commit dbdd10b
Show file tree
Hide file tree
Showing 21 changed files with 1,445 additions and 503 deletions.
12 changes: 0 additions & 12 deletions loader/include.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/compose-spec/compose-go/dotenv"
interp "github.com/compose-spec/compose-go/interpolation"
"github.com/compose-spec/compose-go/types"
"github.com/pkg/errors"
)

// LoadIncludeConfig parse the require config from raw yaml
Expand All @@ -34,17 +33,6 @@ func LoadIncludeConfig(source []interface{}) ([]types.IncludeConfig, error) {
return requires, err
}

var transformIncludeConfig TransformerFunc = func(data interface{}) (interface{}, error) {
switch value := data.(type) {
case string:
return map[string]interface{}{"path": value}, nil
case map[string]interface{}:
return value, nil
default:
return data, errors.Errorf("invalid type %T for `include` configuration", value)
}
}

func loadInclude(ctx context.Context, filename string, configDetails types.ConfigDetails, model *types.Config, options *Options, loaded []string) (*types.Config, map[string][]types.IncludeConfig, error) {
included := make(map[string][]types.IncludeConfig)
for _, r := range model.Include {
Expand Down
8 changes: 2 additions & 6 deletions loader/interpolate.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

interp "github.com/compose-spec/compose-go/interpolation"
"github.com/compose-spec/compose-go/tree"
"github.com/docker/go-units"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -60,7 +61,6 @@ var interpolateTypeCastMapping = map[tree.Path]interp.Cast{
servicePath("secrets", tree.PathMatchList, "mode"): toInt,
servicePath("shm_size"): toUnitBytes,
servicePath("stdin_open"): toBoolean,
servicePath("stop_grace_period"): toDuration,
servicePath("tty"): toBoolean,
servicePath("ulimits", tree.PathMatchAll): toInt,
servicePath("ulimits", tree.PathMatchAll, "hard"): toInt,
Expand Down Expand Up @@ -94,11 +94,7 @@ func toInt64(value string) (interface{}, error) {
}

func toUnitBytes(value string) (interface{}, error) {
return transformSize(value)
}

func toDuration(value string) (interface{}, error) {
return transformStringToDuration(value)
return units.RAMInBytes(value)
}

func toFloat(value string) (interface{}, error) {
Expand Down
Loading

0 comments on commit dbdd10b

Please sign in to comment.