From d1bdeca1463d09b8e95dd6c7260f5b2b24b8d651 Mon Sep 17 00:00:00 2001 From: Ramkumar Chinchani Date: Thu, 20 Apr 2023 17:09:40 +0000 Subject: [PATCH] refactor!: drop support for '->' artwork BREAKING CHANGE: '->' artwork syntax is dropped so older "bind:" directives will break, so users need to migrate/fix. stacker syntax uses a strange mix of yaml and artwork such as '->', for example in "bind:" directive. This PR makes it normal declarative yaml. Signed-off-by: Ramkumar Chinchani --- pkg/types/layer.go | 77 ---------------------------------------------- 1 file changed, 77 deletions(-) diff --git a/pkg/types/layer.go b/pkg/types/layer.go index ea597aa0..aa012c7b 100644 --- a/pkg/types/layer.go +++ b/pkg/types/layer.go @@ -1,7 +1,6 @@ package types import ( - "encoding/json" "fmt" "io/fs" "os" @@ -192,82 +191,6 @@ type Bind struct { type Binds []Bind -func (bs *Bind) MarshalJSON() ([]byte, error) { - var sb strings.Builder - if bs.Dest == "" { - sb.WriteString(fmt.Sprintf("%q", bs.Source)) - } else { - var sbt strings.Builder - sbt.WriteString(fmt.Sprintf("%s -> %s", bs.Source, bs.Dest)) - sb.WriteString(fmt.Sprintf("%q", sbt.String())) - } - - return []byte(sb.String()), nil -} - -func (bs *Binds) UnmarshalJSON(data []byte) error { - var rawBinds []string - - if err := json.Unmarshal(data, &rawBinds); err != nil { - return err - } - - *bs = Binds{} - for _, bind := range rawBinds { - parts := strings.Split(bind, "->") - if len(parts) != 1 && len(parts) != 2 { - return errors.Errorf("invalid bind mount %s", bind) - } - - source := strings.TrimSpace(parts[0]) - target := source - - if len(parts) == 2 { - target = strings.TrimSpace(parts[1]) - } - - *bs = append(*bs, Bind{Source: source, Dest: target}) - } - - return nil -} - -func (bs *Binds) UnmarshalYAML(unmarshal func(interface{}) error) error { - var data interface{} - err := unmarshal(&data) - if err != nil { - return errors.WithStack(err) - } - - xform := func(s string) ([]string, error) { - return []string{s}, nil - } - - rawBinds, err := getStringOrStringSlice(data, xform) - if err != nil { - return err - } - - *bs = Binds{} - for _, bind := range rawBinds { - parts := strings.Split(bind, "->") - if len(parts) != 1 && len(parts) != 2 { - return errors.Errorf("invalid bind mount %s", bind) - } - - source := strings.TrimSpace(parts[0]) - target := source - - if len(parts) == 2 { - target = strings.TrimSpace(parts[1]) - } - - *bs = append(*bs, Bind{Source: source, Dest: target}) - } - - return nil -} - type Layer struct { From ImageSource `yaml:"from" json:"from"` Imports Imports `yaml:"import" json:"import,omitempty"`