Skip to content

Commit

Permalink
build: honor --net
Browse files Browse the repository at this point in the history
when --net is specified, pass it down to Buildah.

Depends on: containers/buildah#1395

Closes: containers#2572

Signed-off-by: Giuseppe Scrivano <[email protected]>
  • Loading branch information
giuseppe committed Mar 11, 2019
1 parent 349e691 commit 06e4441
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions cmd/podman/build.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"os"
"path/filepath"
"strings"
Expand All @@ -11,6 +12,7 @@ import (
"github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/pkg/adapter"
"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 @@ -83,6 +85,26 @@ func getDockerfiles(files []string) []string {
return dockerfiles
}

func getNsValues(c *cliconfig.BuildValues) ([]buildah.NamespaceOption, error) {
var ret []buildah.NamespaceOption
if c.Network != "" {
if c.Network == "host" {
ret = append(ret, buildah.NamespaceOption{
Name: string(specs.NetworkNamespace),
Host: true,
})
} else if c.Network[0] == '/' {
ret = append(ret, buildah.NamespaceOption{
Name: string(specs.NetworkNamespace),
Path: c.Network,
})
} else {
return nil, fmt.Errorf("unsupported configuration network=%s", c.Network)
}
}
return ret, nil
}

func buildCmd(c *cliconfig.BuildValues) error {
// 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
Expand Down Expand Up @@ -227,6 +249,11 @@ func buildCmd(c *cliconfig.BuildValues) error {
}
}

nsValues, err := getNsValues(c)
if err != nil {
return err
}

buildOpts := buildah.CommonBuildOptions{
AddHost: c.AddHost,
CgroupParent: c.CgroupParent,
Expand Down Expand Up @@ -257,6 +284,7 @@ func buildCmd(c *cliconfig.BuildValues) error {
IIDFile: c.Iidfile,
Labels: c.Label,
Layers: layers,
NamespaceOptions: nsValues,
NoCache: c.NoCache,
Out: stdout,
Output: output,
Expand Down

0 comments on commit 06e4441

Please sign in to comment.