Skip to content

Commit 6d9d9fe

Browse files
Merge pull request #8326 from Luap99/fix-build-namespace
Fix namespace flag parsing for podman build
2 parents 0b1a60e + eab0905 commit 6d9d9fe

File tree

2 files changed

+3
-39
lines changed

2 files changed

+3
-39
lines changed

cmd/podman/images/build.go

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"github.com/containers/podman/v2/cmd/podman/utils"
1515
"github.com/containers/podman/v2/pkg/domain/entities"
1616
"github.com/docker/go-units"
17-
"github.com/opencontainers/runtime-spec/specs-go"
1817
"github.com/pkg/errors"
1918
"github.com/sirupsen/logrus"
2019
"github.com/spf13/cobra"
@@ -128,6 +127,7 @@ func buildFlags(flags *pflag.FlagSet) {
128127
}
129128
flags.AddFlagSet(&fromAndBudFlags)
130129
_ = flags.MarkHidden("signature-policy")
130+
flags.SetNormalizeFunc(buildahCLI.AliasFlags)
131131
}
132132

133133
// build executes the build command.
@@ -314,22 +314,11 @@ func buildFlagsWrapperToOptions(c *cobra.Command, contextDir string, flags *buil
314314
}
315315
}
316316

317-
nsValues, err := getNsValues(flags)
317+
nsValues, networkPolicy, err := parse.NamespaceOptions(c)
318318
if err != nil {
319319
return nil, err
320320
}
321321

322-
networkPolicy := buildah.NetworkDefault
323-
for _, ns := range nsValues {
324-
if ns.Name == "none" {
325-
networkPolicy = buildah.NetworkDisabled
326-
break
327-
} else if !filepath.IsAbs(ns.Path) {
328-
networkPolicy = buildah.NetworkEnabled
329-
break
330-
}
331-
}
332-
333322
// `buildah bud --layers=false` acts like `docker build --squash` does.
334323
// That is all of the new layers created during the build process are
335324
// condensed into one, any layers present prior to this build are retained
@@ -450,28 +439,3 @@ func buildFlagsWrapperToOptions(c *cobra.Command, contextDir string, flags *buil
450439

451440
return &entities.BuildOptions{BuildOptions: opts}, nil
452441
}
453-
454-
func getNsValues(flags *buildFlagsWrapper) ([]buildah.NamespaceOption, error) {
455-
var ret []buildah.NamespaceOption
456-
if flags.Network != "" {
457-
switch {
458-
case flags.Network == "host":
459-
ret = append(ret, buildah.NamespaceOption{
460-
Name: string(specs.NetworkNamespace),
461-
Host: true,
462-
})
463-
case flags.Network == "container":
464-
ret = append(ret, buildah.NamespaceOption{
465-
Name: string(specs.NetworkNamespace),
466-
})
467-
case flags.Network[0] == '/':
468-
ret = append(ret, buildah.NamespaceOption{
469-
Name: string(specs.NetworkNamespace),
470-
Path: flags.Network,
471-
})
472-
default:
473-
return nil, errors.Errorf("unsupported configuration network=%s", flags.Network)
474-
}
475-
}
476-
return ret, nil
477-
}

docs/source/markdown/podman-build.1.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ The format of `LIMIT` is `<number>[<unit>]`. Unit can be `b` (bytes),
394394
`k` (kilobytes), `m` (megabytes), or `g` (gigabytes). If you don't specify a
395395
unit, `b` is used. Set LIMIT to `-1` to enable unlimited swap.
396396

397-
#### **--network**=*mode*
397+
#### **--network**=*mode*, **--net**
398398

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

0 commit comments

Comments
 (0)