Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix namespace flag parsing for podman build #8326

Merged
merged 2 commits into from
Nov 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 2 additions & 38 deletions cmd/podman/images/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/containers/podman/v2/cmd/podman/utils"
"github.com/containers/podman/v2/pkg/domain/entities"
"github.com/docker/go-units"
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -128,6 +127,7 @@ func buildFlags(flags *pflag.FlagSet) {
}
flags.AddFlagSet(&fromAndBudFlags)
_ = flags.MarkHidden("signature-policy")
flags.SetNormalizeFunc(buildahCLI.AliasFlags)
}

// build executes the build command.
Expand Down Expand Up @@ -314,22 +314,11 @@ func buildFlagsWrapperToOptions(c *cobra.Command, contextDir string, flags *buil
}
}

nsValues, err := getNsValues(flags)
nsValues, networkPolicy, err := parse.NamespaceOptions(c)
if err != nil {
return nil, err
}

networkPolicy := buildah.NetworkDefault
for _, ns := range nsValues {
if ns.Name == "none" {
networkPolicy = buildah.NetworkDisabled
break
} else if !filepath.IsAbs(ns.Path) {
networkPolicy = buildah.NetworkEnabled
break
}
}

// `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
Expand Down Expand Up @@ -450,28 +439,3 @@ func buildFlagsWrapperToOptions(c *cobra.Command, contextDir string, flags *buil

return &entities.BuildOptions{BuildOptions: opts}, nil
}

func getNsValues(flags *buildFlagsWrapper) ([]buildah.NamespaceOption, error) {
var ret []buildah.NamespaceOption
if flags.Network != "" {
switch {
case flags.Network == "host":
ret = append(ret, buildah.NamespaceOption{
Name: string(specs.NetworkNamespace),
Host: true,
})
case flags.Network == "container":
ret = append(ret, buildah.NamespaceOption{
Name: string(specs.NetworkNamespace),
})
case flags.Network[0] == '/':
ret = append(ret, buildah.NamespaceOption{
Name: string(specs.NetworkNamespace),
Path: flags.Network,
})
default:
return nil, errors.Errorf("unsupported configuration network=%s", flags.Network)
}
}
return ret, nil
}
2 changes: 1 addition & 1 deletion docs/source/markdown/podman-build.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ The format of `LIMIT` is `<number>[<unit>]`. Unit can be `b` (bytes),
`k` (kilobytes), `m` (megabytes), or `g` (gigabytes). If you don't specify a
unit, `b` is used. Set LIMIT to `-1` to enable unlimited swap.

#### **--network**=*mode*
#### **--network**=*mode*, **--net**

Sets the configuration for network namespaces when handling `RUN` instructions.

Expand Down