Make image field optional for bake with compose
Signed-off-by: Kyle McRae <kylemcrae770@gmail.com>
This commit is contained in:
@@ -360,6 +360,15 @@ func toRepoOnly(in string) (string, error) {
|
|||||||
return strings.Join(out, ","), nil
|
return strings.Join(out, ","), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isBake() bool {
|
||||||
|
for _, i := range os.Args {
|
||||||
|
if i == "bake" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func toSolveOpt(ctx context.Context, node builder.Node, multiDriver bool, opt Options, bopts gateway.BuildOpts, configDir string, pw progress.Writer, dl dockerLoadCallback) (solveOpt *client.SolveOpt, release func(), err error) {
|
func toSolveOpt(ctx context.Context, node builder.Node, multiDriver bool, opt Options, bopts gateway.BuildOpts, configDir string, pw progress.Writer, dl dockerLoadCallback) (solveOpt *client.SolveOpt, release func(), err error) {
|
||||||
nodeDriver := node.Driver
|
nodeDriver := node.Driver
|
||||||
defers := make([]func(), 0, 2)
|
defers := make([]func(), 0, 2)
|
||||||
@@ -499,12 +508,19 @@ func toSolveOpt(ctx context.Context, node builder.Node, multiDriver bool, opt Op
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
skipped := []string{}
|
||||||
for _, e := range opt.Exports {
|
for _, e := range opt.Exports {
|
||||||
if e.Type == "image" && e.Attrs["name"] == "" && e.Attrs["push"] != "" {
|
if e.Type == "image" && e.Attrs["name"] == "" && e.Attrs["push"] != "" {
|
||||||
|
if ! isBake() {
|
||||||
if ok, _ := strconv.ParseBool(e.Attrs["push"]); ok {
|
if ok, _ := strconv.ParseBool(e.Attrs["push"]); ok {
|
||||||
return nil, nil, errors.Errorf("tag is needed when pushing to registry")
|
return nil, nil, errors.Errorf("tag is needed when pushing to registry")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
skipped = append(skipped, opt.Inputs.ContextPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(skipped) > 0 {
|
||||||
|
logrus.Warnf("Build will remain in cache for %+v. Image field not found", skipped)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -973,8 +989,10 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
|
|||||||
if ok, _ := strconv.ParseBool(e.Attrs["push"]); ok {
|
if ok, _ := strconv.ParseBool(e.Attrs["push"]); ok {
|
||||||
pushNames = e.Attrs["name"]
|
pushNames = e.Attrs["name"]
|
||||||
if pushNames == "" {
|
if pushNames == "" {
|
||||||
|
if isBake() {
|
||||||
return errors.Errorf("tag is needed when pushing to registry")
|
return errors.Errorf("tag is needed when pushing to registry")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
names, err := toRepoOnly(e.Attrs["name"])
|
names, err := toRepoOnly(e.Attrs["name"])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -1093,11 +1111,14 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
|
|||||||
for _, e := range so.Exports {
|
for _, e := range so.Exports {
|
||||||
if e.Type == "moby" && e.Attrs["push"] != "" {
|
if e.Type == "moby" && e.Attrs["push"] != "" {
|
||||||
if ok, _ := strconv.ParseBool(e.Attrs["push"]); ok {
|
if ok, _ := strconv.ParseBool(e.Attrs["push"]); ok {
|
||||||
|
pw := progress.ResetTime(pw)
|
||||||
pushNames = e.Attrs["name"]
|
pushNames = e.Attrs["name"]
|
||||||
if pushNames == "" {
|
if pushNames == "" {
|
||||||
return errors.Errorf("tag is needed when pushing to registry")
|
if isBake() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return errors.Errorf("tag is needed when pushing to registry %+v", opt)
|
||||||
}
|
}
|
||||||
pw := progress.ResetTime(pw)
|
|
||||||
pushList := strings.Split(pushNames, ",")
|
pushList := strings.Split(pushNames, ",")
|
||||||
for _, name := range pushList {
|
for _, name := range pushList {
|
||||||
if err := progress.Wrap(fmt.Sprintf("pushing %s with docker", name), pw.Write, func(l progress.SubLogger) error {
|
if err := progress.Wrap(fmt.Sprintf("pushing %s with docker", name), pw.Write, func(l progress.SubLogger) error {
|
||||||
|
|||||||
Reference in New Issue
Block a user