Skip to content

Commit 795be65

Browse files
HACK: Add --push and --load support to build cmd
Well, actually... We're not "fully" supporting these capabilities, instead we are changing the least amount of code to give a "close enough" experience. The reason of such clumsy approach is that we are aiming for fully migrate into docker buildx + remote buildkit, since img is no longer maitained. Signed-off-by: Jonnatan Jossemar Cordero <[email protected]>
1 parent 5b90868 commit 795be65

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

build.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ func newBuildCommand() *cobra.Command {
7272
fs.Var(build.labels, "label", "Set metadata for an image")
7373
fs.BoolVar(&build.noConsole, "no-console", false, "Use non-console progress UI")
7474
fs.BoolVar(&build.noCache, "no-cache", false, "Do not use cache when building the image")
75+
fs.BoolVar(&build.push, "push", false, "Shorthand for \"--output=type=registry\"")
76+
fs.BoolVar(&build.load, "load", false, "Shorthand for \"--output=type=docker\"") // no-op flag
7577
fs.StringVarP(&build.output, "output", "o", "", "BuildKit output specification (e.g. type=tar,dest=build.tar)")
7678
fs.Var(build.cacheFrom, "cache-from", "Buildkit import-cache or Buildx cache-from specification")
7779
fs.Var(build.cacheTo, "cache-to", "Buildx cache-to specification")
@@ -93,6 +95,8 @@ type buildCommand struct {
9395
contextDir string
9496
noConsole bool
9597
noCache bool
98+
push bool
99+
load bool // no-op
96100
}
97101

98102
// validateTag checks if the given image name can be resolved, and ensures the latest tag is added if it is missing.
@@ -125,6 +129,10 @@ func (cmd *buildCommand) ValidateArgs(c *cobra.Command, args []string) error {
125129
}
126130
out[0].Attrs["name"] = validated
127131
}
132+
if out[0].Type == "registry" {
133+
cmd.push = true
134+
return nil
135+
}
128136
cmd.bkoutput = out[0]
129137
} else if cmd.tags.Len() < 1 {
130138
return errors.New("please specify an image tag with `-t` or an output spec with `-o`")
@@ -343,6 +351,15 @@ func (cmd *buildCommand) Run(args []string) (err error) {
343351
}
344352
fmt.Fprintf(os.Stderr, "Successfully built %s\n", initialTag)
345353

354+
// HACK: Mimic buildx --push behavior
355+
if cmd.push {
356+
for _, image := range cmd.tags.values {
357+
pushCmd := pushCommand{}
358+
if err := pushCmd.Run([]string{image}); err != nil {
359+
return err
360+
}
361+
}
362+
}
346363
return nil
347364
}
348365

0 commit comments

Comments
 (0)