summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2019-10-15 12:21:17 +0200
committerGitHub <noreply@github.com>2019-10-15 12:21:17 +0200
commit935802575b78bb26d0cd9be1ce87562de62570ee (patch)
tree10bd2fbe3078696e947e31fcabce1181e7a2915a
parent25572cefa8f16580c4a61af86cf2c41281e0300f (diff)
parentbeadd2694b048f939cad1f4d32676fca4c84d0bd (diff)
downloadpodman-935802575b78bb26d0cd9be1ce87562de62570ee.tar.gz
podman-935802575b78bb26d0cd9be1ce87562de62570ee.tar.bz2
podman-935802575b78bb26d0cd9be1ce87562de62570ee.zip
Merge pull request #4215 from TomSweeneyRedHat/dev/tsweeney/fixsquash
Add squash-all, fix squash option in build
-rw-r--r--cmd/podman/build.go42
-rw-r--r--cmd/podman/cliconfig/create.go9
-rw-r--r--completions/bash/podman1
-rw-r--r--docs/podman-build.1.md5
4 files changed, 55 insertions, 2 deletions
diff --git a/cmd/podman/build.go b/cmd/podman/build.go
index 4ea4d3825..f4efea544 100644
--- a/cmd/podman/build.go
+++ b/cmd/podman/build.go
@@ -17,6 +17,7 @@ import (
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
+ "github.com/spf13/pflag"
)
var (
@@ -27,6 +28,7 @@ var (
fromAndBudValues buildahcli.FromAndBudResults
userNSValues buildahcli.UserNSResults
namespaceValues buildahcli.NameSpaceResults
+ podBuildValues cliconfig.PodmanBuildResults
_buildCommand = &cobra.Command{
Use: "build [flags] CONTEXT",
@@ -40,6 +42,7 @@ var (
buildCommand.FromAndBudResults = &fromAndBudValues
buildCommand.LayerResults = &layerValues
buildCommand.NameSpaceResults = &namespaceValues
+ buildCommand.PodmanBuildResults = &podBuildValues
buildCommand.Remote = remoteclient
return buildCmd(&buildCommand)
},
@@ -73,15 +76,30 @@ func init() {
logrus.Error("unable to set force-rm flag to true")
}
flag.DefValue = "true"
+ podmanBuildFlags := GetPodmanBuildFlags(&podBuildValues)
+ flag = podmanBuildFlags.Lookup("squash-all")
+ if err := flag.Value.Set("false"); err != nil {
+ logrus.Error("unable to set squash-all flag to false")
+ }
+ flag.DefValue = "true"
fromAndBugFlags := buildahcli.GetFromAndBudFlags(&fromAndBudValues, &userNSValues, &namespaceValues)
flags.AddFlagSet(&budFlags)
- flags.AddFlagSet(&layerFlags)
flags.AddFlagSet(&fromAndBugFlags)
+ flags.AddFlagSet(&layerFlags)
+ flags.AddFlagSet(&podmanBuildFlags)
markFlagHidden(flags, "signature-policy")
}
+// GetPodmanBuildFlags flags used only by `podman build` and not by
+// `buildah bud`.
+func GetPodmanBuildFlags(flags *cliconfig.PodmanBuildResults) pflag.FlagSet {
+ fs := pflag.FlagSet{}
+ fs.BoolVar(&flags.SquashAll, "squash-all", false, "Squash all layers into a single layer.")
+ return fs
+}
+
func getContainerfiles(files []string) []string {
var containerfiles []string
for _, f := range files {
@@ -119,6 +137,12 @@ func getNsValues(c *cliconfig.BuildValues) ([]buildah.NamespaceOption, error) {
}
func buildCmd(c *cliconfig.BuildValues) error {
+ if (c.Flags().Changed("squash") && c.Flags().Changed("layers")) ||
+ (c.Flags().Changed("squash-all") && c.Flags().Changed("layers")) ||
+ (c.Flags().Changed("squash-all") && c.Flags().Changed("squash")) {
+ return fmt.Errorf("cannot specify squash, squash-all and layers options together")
+ }
+
// The following was taken directly from containers/buildah/cmd/bud.go
// TODO Find a away to vendor more of this in rather than copy from bud
output := ""
@@ -293,6 +317,22 @@ func buildCmd(c *cliconfig.BuildValues) error {
Volumes: c.Volumes,
}
+ // `buildah bud --layers=false` acts like `docker build --squash` does.
+ // That is all of the new layers created during the build process are
+ // condensed into one, any layers present prior to this build are retained
+ // without condensing. `buildah bud --squash` squashes both new and old
+ // layers down into one. Translate Podman commands into Buildah.
+ // Squash invoked, retain old layers, squash new layers into one.
+ if c.Flags().Changed("squash") && c.Squash {
+ c.Squash = false
+ layers = false
+ }
+ // Squash-all invoked, squash both new and old layers into one.
+ if c.Flags().Changed("squash-all") {
+ c.Squash = true
+ layers = false
+ }
+
options := imagebuildah.BuildOptions{
CommonBuildOpts: &buildOpts,
AdditionalTags: tags,
diff --git a/cmd/podman/cliconfig/create.go b/cmd/podman/cliconfig/create.go
index 5fb2eed10..c27dfbbee 100644
--- a/cmd/podman/cliconfig/create.go
+++ b/cmd/podman/cliconfig/create.go
@@ -12,13 +12,20 @@ type RunValues struct {
PodmanCommand
}
+// PodmanBuildResults represents the results for Podman Build flags
+// that are unique to Podman.
+type PodmanBuildResults struct {
+ SquashAll bool
+}
+
type BuildValues struct {
PodmanCommand
*buildahcli.BudResults
*buildahcli.UserNSResults
*buildahcli.FromAndBudResults
- *buildahcli.NameSpaceResults
*buildahcli.LayerResults
+ *buildahcli.NameSpaceResults
+ *PodmanBuildResults
}
type CpValues struct {
diff --git a/completions/bash/podman b/completions/bash/podman
index 4bc387871..2a55183bd 100644
--- a/completions/bash/podman
+++ b/completions/bash/podman
@@ -1246,6 +1246,7 @@ _podman_build() {
-q
--rm
--squash
+ --squash-all
--tls-verify
"
diff --git a/docs/podman-build.1.md b/docs/podman-build.1.md
index c16d964a9..567d0ead3 100644
--- a/docs/podman-build.1.md
+++ b/docs/podman-build.1.md
@@ -405,6 +405,11 @@ If you omit the unit, the system uses bytes. If you omit the size entirely, the
**--squash**
+Squash all of the image's new layers into a single new layer; any preexisting layers
+are not squashed.
+
+**--squash-all**
+
Squash all of the new image's layers (including those inherited from a base image) into a single new layer.
**--tag**, **-t**=*imageName*