Vendor in latest projectatomic/buildah

This will help document the defaults in podman build.

podman build --help will now show the defaults and mention
the environment variables that can be set to change them.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>

Closes: #1364
Approved by: mheon
This commit is contained in:
Daniel J Walsh
2018-08-28 09:39:47 -04:00
committed by Atomic Bot
parent 6a46af571e
commit eb5fdebc84
11 changed files with 101 additions and 34 deletions

View File

@ -77,16 +77,9 @@ func buildCmd(c *cli.Context) error {
}
dockerfiles := getDockerfiles(c.StringSlice("file"))
format := "oci"
if c.IsSet("format") {
format = strings.ToLower(c.String("format"))
}
if strings.HasPrefix(format, "oci") {
format = imagebuildah.OCIv1ImageFormat
} else if strings.HasPrefix(format, "docker") {
format = imagebuildah.Dockerv2ImageFormat
} else {
return errors.Errorf("unrecognized image type %q", format)
format, err := getFormat(c)
if err != nil {
return nil
}
contextDir := ""
cliArgs := c.Args()

View File

@ -10,6 +10,7 @@ import (
"github.com/containers/storage"
"github.com/fatih/camelcase"
"github.com/pkg/errors"
"github.com/projectatomic/buildah"
"github.com/urfave/cli"
)
@ -406,3 +407,15 @@ var createFlags = []cli.Flag{
Usage: "Working `directory inside the container",
},
}
func getFormat(c *cli.Context) (string, error) {
format := strings.ToLower(c.String("format"))
if strings.HasPrefix(format, buildah.OCI) {
return buildah.OCIv1ImageManifest, nil
}
if strings.HasPrefix(format, buildah.DOCKER) {
return buildah.Dockerv2ImageManifest, nil
}
return "", errors.Errorf("unrecognized image type %q", format)
}

View File

@ -194,6 +194,9 @@ Control the format for the built image's manifest and configuration data.
Recognized formats include *oci* (OCI image-spec v1.0, the default) and
*docker* (version 2, using schema format 2 for the manifest).
Note: You can also override the default format by setting the BUILDAH\_FORMAT
environment variable. `export BUILDAH_FORMAT=docker`
**--iidfile** *ImageIDfile*
Write the image ID to the file.
@ -229,7 +232,7 @@ Add an image *label* (e.g. label=*value*) to the image metadata. Can be used mul
Cache intermediate images during the build process (Default is `false`).
Note: You can also override the default value of layers by setting the BUILDAH_LAYERS
Note: You can also override the default value of layers by setting the BUILDAH\_LAYERS
environment variable. `export BUILDAH_LAYERS=true`
**--logfile** *filename*
@ -305,11 +308,15 @@ Remove intermediate containers after a successful build (default true).
The *path* to an alternate OCI-compatible runtime, which will be used to run
commands specified by the **RUN** instruction.
Note: You can also override the default runtime by setting the BUILDAH\_RUNTIME
environment variable. `export BUILDAH_RUNTIME=/usr/local/bin/runc`
**--runtime-flag** *flag*
Adds global flags for the container rutime. To list the supported flags, please
consult the manpages of the selected container runtime (`runc` is the default
runtime, the manpage to consult is `runc(8)`).
Note: Do not pass the leading `--` to the flag. To pass the runc flag `--log-format json`
to podman build, the option given would be `--runtime-flag log-format=json`.
@ -536,13 +543,13 @@ podman build -f Dockerfile.simple .
cat ~/Dockerfile | podman build -f - .
podman build -f Dockerfile.simple -f Dockerfile.notsosimple
podman build -f Dockerfile.simple -f Dockerfile.notsosimple .
podman build -f Dockerfile.in ~
podman build -t imageName .
podman build --tls-verify=true -t imageName -f Dockerfile.simple
podman build --tls-verify=true -t imageName -f Dockerfile.simple .
podman build --tls-verify=false -t imageName .
@ -550,7 +557,7 @@ podman build --runtime-flag log-format=json .
podman build --runtime-flag debug .
podman build --authfile /tmp/auths/myauths.json --cert-dir ~/auth --tls-verify=true --creds=username:password -t imageName -f Dockerfile.simple
podman build --authfile /tmp/auths/myauths.json --cert-dir ~/auth --tls-verify=true --creds=username:password -t imageName -f Dockerfile.simple .
podman build --memory 40m --cpu-period 10000 --cpu-quota 50000 --ulimit nofile=1024:1028 -t imageName .

View File

@ -133,9 +133,9 @@ func (i *LibpodAPI) BuildImage(call iopodman.VarlinkCall, config iopodman.BuildI
}
if strings.HasPrefix(manifestType, "oci") {
manifestType = imagebuildah.OCIv1ImageFormat
manifestType = buildah.OCIv1ImageManifest
} else if strings.HasPrefix(manifestType, "docker") {
manifestType = imagebuildah.Dockerv2ImageFormat
manifestType = buildah.Dockerv2ImageManifest
} else {
return call.ReplyErrorOccurred(fmt.Sprintf("unrecognized image type %q", manifestType))
}

View File

@ -90,7 +90,7 @@ k8s.io/kube-openapi 275e2ce91dec4c05a4094a7b1daee5560b555ac9 https://github.com/
k8s.io/utils 258e2a2fa64568210fbd6267cf1d8fd87c3cb86e https://github.com/kubernetes/utils
github.com/mrunalp/fileutils master
github.com/varlink/go master
github.com/projectatomic/buildah 745bf7e56bda740ce7cfc55318da08529e5ed519
github.com/projectatomic/buildah 2423a90e23ced88c72e30664631af18c9af75148
github.com/Nvveen/Gotty master
github.com/fsouza/go-dockerclient master
github.com/openshift/imagebuilder master

View File

@ -178,6 +178,8 @@ type Builder struct {
CommonBuildOpts *CommonBuildOptions
// TopLayer is the top layer of the image
TopLayer string
// Format for the build Image
Format string
}
// BuilderInfo are used as objects to display container information
@ -360,6 +362,8 @@ type BuilderOptions struct {
DropCapabilities []string
CommonBuildOpts *CommonBuildOptions
// Format for the container image
Format string
}
// ImportOptions are used to initialize a Builder from an existing container

View File

@ -7,6 +7,13 @@ import (
"github.com/containers/image/types"
)
const (
// OCI used to define the "oci" image format
OCI = "oci"
// DOCKER used to define the "docker" image format
DOCKER = "docker"
)
func getCopyOptions(reportWriter io.Writer, sourceSystemContext *types.SystemContext, destinationSystemContext *types.SystemContext, manifestType string) *cp.Options {
return &cp.Options{
ReportWriter: reportWriter,

View File

@ -4,7 +4,6 @@ import (
"context"
"encoding/json"
"os"
"path/filepath"
"runtime"
"strings"
"time"
@ -12,9 +11,11 @@ import (
"github.com/containers/image/manifest"
"github.com/containers/image/transports"
"github.com/containers/image/types"
"github.com/containers/storage/pkg/stringid"
ociv1 "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
"github.com/projectatomic/buildah/docker"
"github.com/sirupsen/logrus"
)
// unmarshalConvertedConfig obtains the config blob of img valid for the wantedManifestMIMEType format
@ -107,8 +108,8 @@ func (b *Builder) fixupConfig() {
if b.Architecture() == "" {
b.SetArchitecture(runtime.GOARCH)
}
if b.WorkDir() == "" {
b.SetWorkDir(string(filepath.Separator))
if b.Format == Dockerv2ImageManifest && b.Hostname() == "" {
b.SetHostname(stringid.TruncateID(stringid.GenerateRandomID()))
}
}
@ -218,6 +219,9 @@ func (b *Builder) ClearOnBuild() {
// Note: this setting is not present in the OCIv1 image format, so it is
// discarded when writing images using OCIv1 formats.
func (b *Builder) SetOnBuild(onBuild string) {
if onBuild != "" && b.Format != Dockerv2ImageManifest {
logrus.Errorf("ONBUILD is not supported for OCI Image formats, %s will be ignored. Must use `docker` format", onBuild)
}
b.Docker.Config.OnBuild = append(b.Docker.Config.OnBuild, onBuild)
}
@ -247,6 +251,10 @@ func (b *Builder) Shell() []string {
// Note: this setting is not present in the OCIv1 image format, so it is
// discarded when writing images using OCIv1 formats.
func (b *Builder) SetShell(shell []string) {
if len(shell) > 0 && b.Format != Dockerv2ImageManifest {
logrus.Errorf("SHELL is not supported for OCI Image format, %s will be ignored. Must use `docker` format", shell)
}
b.Docker.Config.Shell = copyStringSlice(shell)
}
@ -327,7 +335,10 @@ func (b *Builder) SetCmd(cmd []string) {
// Entrypoint returns the command to be run for containers built from images
// built from this container.
func (b *Builder) Entrypoint() []string {
return copyStringSlice(b.OCIv1.Config.Entrypoint)
if len(b.OCIv1.Config.Entrypoint) > 0 {
return copyStringSlice(b.OCIv1.Config.Entrypoint)
}
return nil
}
// SetEntrypoint sets the command to be run for in containers built from images
@ -416,7 +427,10 @@ func (b *Builder) Volumes() []string {
for k := range b.OCIv1.Config.Volumes {
v = append(v, k)
}
return v
if len(v) > 0 {
return v
}
return nil
}
// AddVolume adds a location to the image's list of locations which should be
@ -460,6 +474,9 @@ func (b *Builder) Hostname() string {
// Note: this setting is not present in the OCIv1 image format, so it is
// discarded when writing images using OCIv1 formats.
func (b *Builder) SetHostname(name string) {
if name != "" && b.Format != Dockerv2ImageManifest {
logrus.Errorf("HOSTNAME is not supported for OCI Image format, hostname %s will be ignored. Must use `docker` format", name)
}
b.Docker.Config.Hostname = name
}
@ -474,6 +491,9 @@ func (b *Builder) Domainname() string {
// Note: this setting is not present in the OCIv1 image format, so it is
// discarded when writing images using OCIv1 formats.
func (b *Builder) SetDomainname(name string) {
if name != "" && b.Format != Dockerv2ImageManifest {
logrus.Errorf("DOMAINNAME is not supported for OCI Image format, domainname %s will be ignored. Must use `docker` format", name)
}
b.Docker.Config.Domainname = name
}
@ -493,6 +513,9 @@ func (b *Builder) Comment() string {
// Note: this setting is not present in the OCIv1 image format, so it is
// discarded when writing images using OCIv1 formats.
func (b *Builder) SetComment(comment string) {
if comment != "" && b.Format != Dockerv2ImageManifest {
logrus.Errorf("COMMENT is not supported for OCI Image format, comment %s will be ignored. Must use `docker` format", comment)
}
b.Docker.Comment = comment
}

View File

@ -34,11 +34,9 @@ import (
)
const (
PullIfMissing = buildah.PullIfMissing
PullAlways = buildah.PullAlways
PullNever = buildah.PullNever
OCIv1ImageFormat = buildah.OCIv1ImageManifest
Dockerv2ImageFormat = buildah.Dockerv2ImageManifest
PullIfMissing = buildah.PullIfMissing
PullAlways = buildah.PullAlways
PullNever = buildah.PullNever
Gzip = archive.Gzip
Bzip2 = archive.Bzip2
@ -114,7 +112,7 @@ type BuildOptions struct {
ReportWriter io.Writer
// OutputFormat is the format of the output image's manifest and
// configuration data.
// Accepted values are OCIv1ImageFormat and Dockerv2ImageFormat.
// Accepted values are buildah.OCIv1ImageManifest and buildah.Dockerv2ImageManifest.
OutputFormat string
// SystemContext holds parameters used for authentication.
SystemContext *types.SystemContext
@ -640,6 +638,7 @@ func (b *Executor) Prepare(ctx context.Context, ib *imagebuilder.Builder, node *
IDMappingOptions: b.idmappingOptions,
CommonBuildOpts: b.commonBuildOptions,
DefaultMountsFilePath: b.defaultMountsFilePath,
Format: b.outputFormat,
}
builder, err := buildah.NewBuilder(ctx, b.store, builderOptions)
if err != nil {

View File

@ -339,6 +339,7 @@ func newBuilder(ctx context.Context, store storage.Store, options BuilderOptions
CommonBuildOpts: options.CommonBuildOpts,
TopLayer: topLayer,
Args: options.Args,
Format: options.Format,
}
if options.Mount {

View File

@ -10,12 +10,12 @@ import (
"strings"
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/projectatomic/buildah"
"github.com/projectatomic/buildah/util"
"github.com/urfave/cli"
)
var (
runtime = util.Runtime()
usernsFlags = []cli.Flag{
cli.StringFlag{
Name: "userns",
@ -113,7 +113,8 @@ var (
},
cli.StringFlag{
Name: "format",
Usage: "`format` of the built image's manifest and metadata",
Usage: "`format` of the built image's manifest and metadata. Use BUILDAH_FORMAT environment variable to override.",
Value: DefaultFormat(),
},
cli.StringFlag{
Name: "iidfile",
@ -121,7 +122,8 @@ var (
},
cli.StringFlag{
Name: "isolation",
Usage: "`type` of process isolation to use",
Usage: "`type` of process isolation to use. Use BUILDAH_ISOLATION environment variable to override.",
Value: DefaultIsolation(),
},
cli.StringSliceFlag{
Name: "label",
@ -129,7 +131,7 @@ var (
},
cli.BoolFlag{
Name: "layers",
Usage: fmt.Sprintf("cache intermediate layers during build (default %t)", UseLayers()),
Usage: fmt.Sprintf("cache intermediate layers during build. Use BUILDAH_LAYERS environment variable to override. (default %t)", UseLayers()),
},
cli.BoolFlag{
Name: "no-cache",
@ -161,8 +163,8 @@ var (
},
cli.StringFlag{
Name: "runtime",
Usage: "`path` to an alternate runtime",
Value: runtime,
Usage: "`path` to an alternate runtime. Use BUILDAH_RUNTIME environment variable to override.",
Value: util.Runtime(),
},
cli.StringSliceFlag{
Name: "runtime-flag",
@ -260,3 +262,21 @@ func UseLayers() bool {
}
return false
}
// DefaultFormat returns the default image format
func DefaultFormat() string {
format := os.Getenv("BUILDAH_FORMAT")
if format != "" {
return format
}
return buildah.OCI
}
// DefaultIsolation returns the default image format
func DefaultIsolation() string {
isolation := os.Getenv("BUILDAH_ISOLATION")
if isolation != "" {
return isolation
}
return buildah.OCI
}