allow podman to build a client for windows

the podman remote-client for windows pulls in some buildah code for
things like commit and build.  we need to perform some slight
refactoring of buildah code to accomodate that build.

Signed-off-by: baude <bbaude@redhat.com>

Closes: #1551
Approved by: rhatdan
This commit is contained in:
baude 2019-04-25 14:39:49 -05:00 committed by Atomic Bot
parent 031fd8877c
commit 34e7eba408
12 changed files with 2124 additions and 2063 deletions

View File

@ -4,7 +4,6 @@ import (
"context"
"fmt"
"os"
"syscall"
"time"
"github.com/containers/buildah"
@ -12,10 +11,9 @@ import (
is "github.com/containers/image/storage"
"github.com/containers/image/types"
"github.com/containers/storage"
digest "github.com/opencontainers/go-digest"
"github.com/opencontainers/go-digest"
imgspecv1 "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
@ -99,10 +97,7 @@ func getStore(c *cobra.Command) (storage.Store, error) {
options.GIDMap = gidmap
}
oldUmask := syscall.Umask(0022)
if (oldUmask & ^0022) != 0 {
logrus.Debugf("umask value too restrictive. Forcing it to 022")
}
checkUmask()
store, err := storage.GetStore(options)
if store != nil {

View File

@ -0,0 +1,16 @@
// +build linux darwin
package main
import (
"syscall"
"github.com/sirupsen/logrus"
)
func checkUmask() {
oldUmask := syscall.Umask(0022)
if (oldUmask & ^0022) != 0 {
logrus.Debugf("umask value too restrictive. Forcing it to 022")
}
}

View File

@ -0,0 +1,5 @@
// +build !linux,!darwin
package main
func checkUmask() {}

View File

@ -24,6 +24,22 @@ func init() {
reexec.Register(symlinkModifiedTime, resolveSymlinkTimeModified)
}
// resolveSymlink uses a child subprocess to resolve any symlinks in filename
// in the context of rootdir.
func resolveSymlink(rootdir, filename string) (string, error) {
// The child process expects a chroot and one path that
// will be consulted relative to the chroot directory and evaluated
// for any symbolic links present.
cmd := reexec.Command(symlinkChrootedCommand, rootdir, filename)
output, err := cmd.CombinedOutput()
if err != nil {
return "", errors.Wrapf(err, string(output))
}
// Hand back the resolved symlink, will be filename if a symlink is not found
return string(output), nil
}
// main() for resolveSymlink()'s subprocess.
func resolveChrootedSymlinks() {
status := 0
@ -55,22 +71,6 @@ func resolveChrootedSymlinks() {
os.Exit(status)
}
// resolveSymlink uses a child subprocess to resolve any symlinks in filename
// in the context of rootdir.
func resolveSymlink(rootdir, filename string) (string, error) {
// The child process expects a chroot and one path that
// will be consulted relative to the chroot directory and evaluated
// for any symbolic links present.
cmd := reexec.Command(symlinkChrootedCommand, rootdir, filename)
output, err := cmd.CombinedOutput()
if err != nil {
return "", errors.Wrapf(err, string(output))
}
// Hand back the resolved symlink, will be filename if a symlink is not found
return string(output), nil
}
// main() for grandparent subprocess. Its main job is to shuttle stdio back
// and forth, managing a pseudo-terminal if we want one, for our child, the
// parent subprocess.

View File

@ -0,0 +1,13 @@
// +build !linux
package imagebuildah
import "github.com/pkg/errors"
func resolveSymlink(rootdir, filename string) (string, error) {
return "", errors.New("function not supported on non-linux systems")
}
func resolveModifiedTime(rootdir, filename, historyTime string) (bool, error) {
return false, errors.New("function not supported on non-linux systems")
}

View File

@ -22,7 +22,6 @@ import (
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"golang.org/x/crypto/ssh/terminal"
"golang.org/x/sys/unix"
)
const (
@ -39,14 +38,9 @@ func CommonBuildOptions(c *cobra.Command) (*buildah.CommonBuildOptions, error) {
memorySwap int64
err error
)
rlim := unix.Rlimit{Cur: 1048576, Max: 1048576}
defaultLimits := []string{}
if err := unix.Setrlimit(unix.RLIMIT_NOFILE, &rlim); err == nil {
defaultLimits = append(defaultLimits, fmt.Sprintf("nofile=%d:%d", rlim.Cur, rlim.Max))
}
if err := unix.Setrlimit(unix.RLIMIT_NPROC, &rlim); err == nil {
defaultLimits = append(defaultLimits, fmt.Sprintf("nproc=%d:%d", rlim.Cur, rlim.Max))
}
defaultLimits := getDefaultProcessLimits()
memVal, _ := c.Flags().GetString("memory")
if memVal != "" {
memoryLimit, err = units.RAMInBytes(memVal)

20
pkg/parse/parse_unix.go Normal file
View File

@ -0,0 +1,20 @@
// +build linux darwin
package parse
import (
"fmt"
"golang.org/x/sys/unix"
)
func getDefaultProcessLimits() []string {
rlim := unix.Rlimit{Cur: 1048576, Max: 1048576}
defaultLimits := []string{}
if err := unix.Setrlimit(unix.RLIMIT_NOFILE, &rlim); err == nil {
defaultLimits = append(defaultLimits, fmt.Sprintf("nofile=%d:%d", rlim.Cur, rlim.Max))
}
if err := unix.Setrlimit(unix.RLIMIT_NPROC, &rlim); err == nil {
defaultLimits = append(defaultLimits, fmt.Sprintf("nproc=%d:%d", rlim.Cur, rlim.Max))
}
return defaultLimits
}

View File

@ -0,0 +1,7 @@
// +build !linux,!darwin
package parse
func getDefaultProcessLimits() []string {
return []string{}
}

2020
run.go

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +0,0 @@
// +build !linux
package buildah
import (
"github.com/pkg/errors"
)
func setChildProcess() error {
return errors.New("function not supported on non-linux systems")
}

20
run_unsupported.go Normal file
View File

@ -0,0 +1,20 @@
// +build !linux
package buildah
import (
"github.com/pkg/errors"
)
func setChildProcess() error {
return errors.New("function not supported on non-linux systems")
}
func runUsingRuntimeMain() {}
func (b *Builder) Run(command []string, options RunOptions) error {
return errors.New("function not supported on non-linux systems")
}
func DefaultNamespaceOptions() (NamespaceOptions, error) {
return NamespaceOptions{}, errors.New("function not supported on non-linux systems")
}