mirror of
https://github.com/containers/podman.git
synced 2025-06-24 03:08:13 +08:00
Merge pull request #2585 from giuseppe/build-honor-net
build: honor --net
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@ -11,6 +12,7 @@ import (
|
|||||||
"github.com/containers/libpod/cmd/podman/cliconfig"
|
"github.com/containers/libpod/cmd/podman/cliconfig"
|
||||||
"github.com/containers/libpod/pkg/adapter"
|
"github.com/containers/libpod/pkg/adapter"
|
||||||
"github.com/docker/go-units"
|
"github.com/docker/go-units"
|
||||||
|
"github.com/opencontainers/runtime-spec/specs-go"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -83,6 +85,26 @@ func getDockerfiles(files []string) []string {
|
|||||||
return dockerfiles
|
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 {
|
func buildCmd(c *cliconfig.BuildValues) error {
|
||||||
// The following was taken directly from containers/buildah/cmd/bud.go
|
// 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
|
// TODO Find a away to vendor more of this in rather than copy from bud
|
||||||
@ -227,6 +249,11 @@ func buildCmd(c *cliconfig.BuildValues) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsValues, err := getNsValues(c)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
buildOpts := buildah.CommonBuildOptions{
|
buildOpts := buildah.CommonBuildOptions{
|
||||||
AddHost: c.AddHost,
|
AddHost: c.AddHost,
|
||||||
CgroupParent: c.CgroupParent,
|
CgroupParent: c.CgroupParent,
|
||||||
@ -257,6 +284,7 @@ func buildCmd(c *cliconfig.BuildValues) error {
|
|||||||
IIDFile: c.Iidfile,
|
IIDFile: c.Iidfile,
|
||||||
Labels: c.Label,
|
Labels: c.Label,
|
||||||
Layers: layers,
|
Layers: layers,
|
||||||
|
NamespaceOptions: nsValues,
|
||||||
NoCache: c.NoCache,
|
NoCache: c.NoCache,
|
||||||
Out: stdout,
|
Out: stdout,
|
||||||
Output: output,
|
Output: output,
|
||||||
|
@ -848,6 +848,10 @@ func (c *Container) generateResolvConf() (string, error) {
|
|||||||
|
|
||||||
// Make a new resolv.conf
|
// Make a new resolv.conf
|
||||||
nameservers := resolvconf.GetNameservers(resolv.Content)
|
nameservers := resolvconf.GetNameservers(resolv.Content)
|
||||||
|
// slirp4netns has a built in DNS server.
|
||||||
|
if c.config.NetMode.IsSlirp4netns() {
|
||||||
|
nameservers = append(nameservers, "10.0.2.3")
|
||||||
|
}
|
||||||
if len(c.config.DNSServer) > 0 {
|
if len(c.config.DNSServer) > 0 {
|
||||||
// We store DNS servers as net.IP, so need to convert to string
|
// We store DNS servers as net.IP, so need to convert to string
|
||||||
nameservers = []string{}
|
nameservers = []string{}
|
||||||
|
Reference in New Issue
Block a user