build: enhance warning message when no output specified

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2022-06-03 19:26:16 +02:00
parent 66a764f9c1
commit 1cb1ee018b
No known key found for this signature in database
GPG Key ID: 3248E46B6BB8C7F7
2 changed files with 23 additions and 4 deletions

View File

@ -332,6 +332,7 @@ func (c Config) loadLinks(name string, t *Target, m map[string]*Target, o map[st
return err
}
t2.Outputs = nil
t2.linked = true
m[target] = t2
}
if err := c.loadLinks(target, t2, m, o, visited); err != nil {
@ -528,6 +529,9 @@ type Target struct {
NetworkMode *string `json:"-" hcl:"-"`
NoCacheFilter []string `json:"no-cache-filter,omitempty" hcl:"no-cache-filter,optional"`
// IMPORTANT: if you add more fields here, do not forget to update newOverrides and README.
// linked is a private field to mark a target used as a linked one
linked bool
}
func (t *Target) normalize() {
@ -869,6 +873,7 @@ func toBuildOpt(t *Target, inp *Input) (*build.Options, error) {
NoCacheFilter: t.NoCacheFilter,
Pull: pull,
NetworkMode: networkMode,
Linked: t.linked,
}
platforms, err := platformutil.Parse(t.Platforms)

View File

@ -2,6 +2,7 @@ package build
import (
"bufio"
"bytes"
"context"
"crypto/rand"
"encoding/hex"
@ -75,6 +76,9 @@ type Options struct {
Tags []string
Target string
Ulimits *opts.UlimitOpt
// Linked marks this target as exclusively linked (not requested by the user).
Linked bool
}
type Inputs struct {
@ -630,12 +634,22 @@ func Build(ctx context.Context, drivers []DriverInfo, opt map[string]Options, do
}
if noMobyDriver != nil && !noDefaultLoad() {
for _, opt := range opt {
if len(opt.Exports) == 0 {
logrus.Warnf("No output specified for %s driver. Build result will only remain in the build cache. To push result image into registry use --push or to load image into docker use --load", noMobyDriver.Factory().Name())
break
var noOutputTargets []string
for name, opt := range opt {
if !opt.Linked && len(opt.Exports) == 0 {
noOutputTargets = append(noOutputTargets, name)
}
}
if len(noOutputTargets) > 0 {
var warnNoOutputBuf bytes.Buffer
warnNoOutputBuf.WriteString("No output specified ")
if len(noOutputTargets) == 1 && noOutputTargets[0] == "default" {
warnNoOutputBuf.WriteString(fmt.Sprintf("with %s driver", noMobyDriver.Factory().Name()))
} else {
warnNoOutputBuf.WriteString(fmt.Sprintf("for %s target(s) with %s driver", strings.Join(noOutputTargets, ", "), noMobyDriver.Factory().Name()))
}
logrus.Warnf("%s. Build result will only remain in the build cache. To push result image into registry use --push or to load image into docker use --load", warnNoOutputBuf.String())
}
}
m, clients, err := resolveDrivers(ctx, drivers, opt, w)