Skip to content

Commit

Permalink
refactor!: drop support for '->' artwork
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
rchincha committed Apr 20, 2023
1 parent 479fca8 commit d1bdeca
Showing 1 changed file with 0 additions and 77 deletions.
77 changes: 0 additions & 77 deletions pkg/types/layer.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package types

import (
"encoding/json"
"fmt"
"io/fs"
"os"
Expand Down Expand Up @@ -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"`
Expand Down

0 comments on commit d1bdeca

Please sign in to comment.