diff options
-rwxr-xr-x | API.md | 90 | ||||
-rw-r--r-- | cmd/podman/commit.go | 4 | ||||
-rw-r--r-- | cmd/podman/varlink/io.projectatomic.podman.varlink | 60 | ||||
-rw-r--r-- | docs/podman-commit.1.md | 4 | ||||
-rw-r--r-- | libpod/container_commit.go | 5 | ||||
-rw-r--r-- | libpod/runtime.go | 1 | ||||
-rw-r--r-- | pkg/varlinkapi/containers.go | 3 | ||||
-rw-r--r-- | pkg/varlinkapi/containers_create.go | 10 | ||||
-rw-r--r-- | pkg/varlinkapi/images.go | 208 | ||||
-rw-r--r-- | vendor.conf | 2 | ||||
-rw-r--r-- | vendor/github.com/projectatomic/buildah/commit.go | 3 | ||||
-rw-r--r-- | vendor/github.com/projectatomic/buildah/config.go | 22 | ||||
-rw-r--r-- | vendor/github.com/projectatomic/buildah/imagebuildah/build.go | 8 | ||||
-rw-r--r-- | vendor/github.com/projectatomic/buildah/imagebuildah/chroot_symlink.go | 2 | ||||
-rw-r--r-- | vendor/github.com/projectatomic/buildah/pkg/cli/common.go | 4 |
15 files changed, 387 insertions, 39 deletions
@@ -5,7 +5,7 @@ in the [API.md](https://github.com/projectatomic/libpod/blob/master/API.md) file [func AttachToContainer() NotImplemented](#AttachToContainer) -[func BuildImage() NotImplemented](#BuildImage) +[func BuildImage(build: BuildInfo) []string](#BuildImage) [func Commit(name: string, image_name: string, changes: []string, author: string, message: string, pause: bool) string](#Commit) @@ -29,6 +29,8 @@ in the [API.md](https://github.com/projectatomic/libpod/blob/master/API.md) file [func GetContainerStats(name: string) ContainerStats](#GetContainerStats) +[func GetImage(name: string) ImageInList](#GetImage) + [func GetInfo() PodmanInfo](#GetInfo) [func GetVersion() Version](#GetVersion) @@ -83,6 +85,8 @@ in the [API.md](https://github.com/projectatomic/libpod/blob/master/API.md) file [func WaitContainer(name: string) int](#WaitContainer) +[type BuildInfo](#BuildInfo) + [type ContainerChanges](#ContainerChanges) [type ContainerMount](#ContainerMount) @@ -144,8 +148,10 @@ This method has not be implemented yet. ### <a name="BuildImage"></a>func BuildImage <div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;"> -method BuildImage() [NotImplemented](#NotImplemented)</div> -This function is not implemented yet. +method BuildImage(build: [BuildInfo](#BuildInfo)) [[]string](#[]string)</div> +BuildImage takes a [BuildInfo](#BuildInfo) structure and builds an image. At a minimum, you must provide the +'dockerfile' and 'tags' options in the BuildInfo structure. Upon a successful build, it will +return the ID of the container. ### <a name="Commit"></a>func Commit <div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;"> @@ -153,7 +159,7 @@ method Commit(name: [string](https://godoc.org/builtin#string), image_name: [str Commit, creates an image from an existing container. It requires the name or ID of the container as well as the resulting image name. Optionally, you can define an author and message to be added to the resulting image. You can also define changes to the resulting image for the following -attributes: _CMD, ENTRYPOINT, ENV, EXPOSE, LABEL, STOPSIGNAL, USER, VOLUME, and WORKDIR_. To pause the +attributes: _CMD, ENTRYPOINT, ENV, EXPOSE, LABEL, ONBUILD, STOPSIGNAL, USER, VOLUME, and WORKDIR_. To pause the container while it is being committed, pass a _true_ bool for the pause argument. If the container cannot be found by the ID or name provided, a (ContainerNotFound)[#ContainerNotFound] error will be returned; otherwise, the resulting image's ID will be returned as a string. @@ -161,7 +167,16 @@ the resulting image's ID will be returned as a string. <div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;"> method CreateContainer(create: [Create](#Create)) [string](https://godoc.org/builtin#string)</div> -CreateContainer creates a new container from an image. It uses a (Create)[#Create] type for input. +CreateContainer creates a new container from an image. It uses a [Create](#Create) type for input. The minimum +input required for CreateContainer is an image name. If the image name is not found, an [ImageNotFound](#ImageNotFound) +error will be returned. Otherwise, the ID of the newly created container will be returned. +#### Example +~~~ +$ varlink call unix:/run/podman/io.projectatomic.podman/io.projectatomic.podman.CreateContainer '{"create": {"image": "alpine"}}' +{ + "container": "8759dafbc0a4dc3bcfb57eeb72e4331eb73c5cc09ab968e65ce45b9ad5c4b6bb" +} +~~~ ### <a name="CreateImage"></a>func CreateImage <div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;"> @@ -221,7 +236,7 @@ $ varlink call -m unix:/run/io.projectatomic.podman/io.projectatomic.podman.GetA method GetContainer(name: [string](https://godoc.org/builtin#string)) [ListContainerData](#ListContainerData)</div> GetContainer takes a name or ID of a container and returns single ListContainerData structure. A [ContainerNotFound](#ContainerNotFound) error will be returned if the container cannot be found. -See also [ListContainers](ListContainers) and [InspectContainer](InspectContainer). +See also [ListContainers](ListContainers) and [InspectContainer](#InspectContainer). ### <a name="GetContainerLogs"></a>func GetContainerLogs <div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;"> @@ -258,6 +273,12 @@ $ varlink call -m unix:/run/podman/io.projectatomic.podman/io.projectatomic.podm } } ~~~ +### <a name="GetImage"></a>func GetImage +<div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;"> + +method GetImage(name: [string](https://godoc.org/builtin#string)) [ImageInList](#ImageInList)</div> +GetImage returns a single image in an [ImageInList](#ImageInList) struct. You must supply an image name as a string. +If the image cannot be found, an [ImageNotFound](#ImageNotFound) error will be returned. ### <a name="GetInfo"></a>func GetInfo <div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;"> @@ -349,7 +370,7 @@ an image currently in storage. See also [InspectImage](InspectImage). method PauseContainer(name: [string](https://godoc.org/builtin#string)) [string](https://godoc.org/builtin#string)</div> PauseContainer takes the name or ID of container and pauses it. If the container cannot be found, a [ContainerNotFound](#ContainerNotFound) error will be returned; otherwise the ID of the container is returned. -See also [UnpauseContainer](UnpauseContainer). +See also [UnpauseContainer](#UnpauseContainer). ### <a name="Ping"></a>func Ping <div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;"> @@ -471,7 +492,7 @@ be found, an [ImageNotFound](#ImageNotFound) error will be returned; otherwise, method UnpauseContainer(name: [string](https://godoc.org/builtin#string)) [string](https://godoc.org/builtin#string)</div> UnpauseContainer takes the name or ID of container and unpauses a paused container. If the container cannot be found, a [ContainerNotFound](#ContainerNotFound) error will be returned; otherwise the ID of the container is returned. -See also [PauseContainer](PauseContainer). +See also [PauseContainer](#PauseContainer). ### <a name="UpdateContainer"></a>func UpdateContainer <div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;"> @@ -485,6 +506,57 @@ WaitContainer takes the name or ID of a container and waits until the container code of the container is returned. If the container container cannot be found by ID or name, a [ContainerNotFound](#ContainerNotFound) error is returned. ## Types +### <a name="BuildInfo"></a>type BuildInfo + +BuildInfo is used to describe user input for building images + +dockerfile [[]string](#[]string) + +tags [[]string](#[]string) + +add_hosts [[]string](#[]string) + +cgroup_parent [string](https://godoc.org/builtin#string) + +cpu_period [int](https://godoc.org/builtin#int) + +cpu_quota [int](https://godoc.org/builtin#int) + +cpu_shares [int](https://godoc.org/builtin#int) + +cpuset_cpus [string](https://godoc.org/builtin#string) + +cpuset_mems [string](https://godoc.org/builtin#string) + +memory [string](https://godoc.org/builtin#string) + +memory_swap [string](https://godoc.org/builtin#string) + +security_opts [[]string](#[]string) + +shm_size [string](https://godoc.org/builtin#string) + +ulimit [[]string](#[]string) + +volume [[]string](#[]string) + +squash [bool](https://godoc.org/builtin#bool) + +pull [bool](https://godoc.org/builtin#bool) + +pull_always [bool](https://godoc.org/builtin#bool) + +force_rm [bool](https://godoc.org/builtin#bool) + +rm [bool](https://godoc.org/builtin#bool) + +label [[]string](#[]string) + +annotations [[]string](#[]string) + +build_args [map[string]](#map[string]) + +image_format [string](https://godoc.org/builtin#string) ### <a name="ContainerChanges"></a>type ContainerChanges ContainerChanges describes the return struct for ListContainerChanges @@ -695,7 +767,7 @@ security_opts [[]string](#[]string) ### <a name="CreateResourceConfig"></a>type CreateResourceConfig CreateResourceConfig is an input structure used to describe host attributes during -container creation. It is only valid inside a (Create)[#Create] type. +container creation. It is only valid inside a [Create](#Create) type. blkio_weight [int](https://godoc.org/builtin#int) diff --git a/cmd/podman/commit.go b/cmd/podman/commit.go index ce8e99dd4..90a003e8e 100644 --- a/cmd/podman/commit.go +++ b/cmd/podman/commit.go @@ -19,7 +19,7 @@ var ( commitFlags = []cli.Flag{ cli.StringSliceFlag{ Name: "change, c", - Usage: "Apply the following possible instructions to the created image (default []): CMD | ENTRYPOINT | ENV | EXPOSE | LABEL | STOPSIGNAL | USER | VOLUME | WORKDIR", + Usage: fmt.Sprintf("Apply the following possible instructions to the created image (default []): %s", strings.Join(libpod.ChangeCmds, " | ")), }, cli.StringFlag{ Name: "format, f", @@ -92,7 +92,7 @@ func commitCmd(c *cli.Context) error { if c.IsSet("change") { for _, change := range c.StringSlice("change") { splitChange := strings.Split(strings.ToUpper(change), "=") - if !util.StringInSlice(splitChange[0], []string{"CMD", "ENTRYPOINT", "ENV", "EXPOSE", "LABEL", "STOPSIGNAL", "USER", "VOLUME", "WORKDIR"}) { + if !util.StringInSlice(splitChange[0], libpod.ChangeCmds) { return errors.Errorf("invalid syntax for --change ", change) } } diff --git a/cmd/podman/varlink/io.projectatomic.podman.varlink b/cmd/podman/varlink/io.projectatomic.podman.varlink index b120edfa2..0066e6fb2 100644 --- a/cmd/podman/varlink/io.projectatomic.podman.varlink +++ b/cmd/podman/varlink/io.projectatomic.podman.varlink @@ -248,7 +248,7 @@ type Create ( ) # CreateResourceConfig is an input structure used to describe host attributes during -# container creation. It is only valid inside a (Create)[#Create] type. +# container creation. It is only valid inside a [Create](#Create) type. type CreateResourceConfig ( blkio_weight: int, blkio_weight_device: []string, @@ -291,6 +291,35 @@ type IDMap ( size: int ) +# BuildInfo is used to describe user input for building images +type BuildInfo ( + # paths to one or more dockerfiles + dockerfile: []string, + tags: []string, + add_hosts: []string, + cgroup_parent: string, + cpu_period: int, + cpu_quota: int, + cpu_shares: int, + cpuset_cpus: string, + cpuset_mems: string, + memory: string, + memory_swap: string, + security_opts: []string, + shm_size: string, + ulimit: []string, + volume: []string, + squash: bool, + pull: bool, + pull_always: bool, + force_rm: bool, + rm: bool, + label: []string, + annotations: []string, + build_args: [string]string, + image_format: string +) + # Ping provides a response for developers to ensure their varlink setup is working. # #### Example # ~~~ @@ -317,10 +346,19 @@ method ListContainers() -> (containers: []ListContainerData) # GetContainer takes a name or ID of a container and returns single ListContainerData # structure. A [ContainerNotFound](#ContainerNotFound) error will be returned if the container cannot be found. -# See also [ListContainers](ListContainers) and [InspectContainer](InspectContainer). +# See also [ListContainers](ListContainers) and [InspectContainer](#InspectContainer). method GetContainer(name: string) -> (container: ListContainerData) -# CreateContainer creates a new container from an image. It uses a (Create)[#Create] type for input. +# CreateContainer creates a new container from an image. It uses a [Create](#Create) type for input. The minimum +# input required for CreateContainer is an image name. If the image name is not found, an [ImageNotFound](#ImageNotFound) +# error will be returned. Otherwise, the ID of the newly created container will be returned. +# #### Example +# ~~~ +# $ varlink call unix:/run/podman/io.projectatomic.podman/io.projectatomic.podman.CreateContainer '{"create": {"image": "alpine"}}' +# { +# "container": "8759dafbc0a4dc3bcfb57eeb72e4331eb73c5cc09ab968e65ce45b9ad5c4b6bb" +# } +# ~~~ method CreateContainer(create: Create) -> (container: string) # InspectContainer data takes a name or ID of a container returns the inspection @@ -429,12 +467,12 @@ method RenameContainer() -> (notimplemented: NotImplemented) # PauseContainer takes the name or ID of container and pauses it. If the container cannot be found, # a [ContainerNotFound](#ContainerNotFound) error will be returned; otherwise the ID of the container is returned. -# See also [UnpauseContainer](UnpauseContainer). +# See also [UnpauseContainer](#UnpauseContainer). method PauseContainer(name: string) -> (container: string) # UnpauseContainer takes the name or ID of container and unpauses a paused container. If the container cannot be # found, a [ContainerNotFound](#ContainerNotFound) error will be returned; otherwise the ID of the container is returned. -# See also [PauseContainer](PauseContainer). +# See also [PauseContainer](#PauseContainer). method UnpauseContainer(name: string) -> (container: string) # This method has not be implemented yet. @@ -482,8 +520,14 @@ method DeleteStoppedContainers() -> (containers: []string) # an image currently in storage. See also [InspectImage](InspectImage). method ListImages() -> (images: []ImageInList) -# This function is not implemented yet. -method BuildImage() -> (notimplemented: NotImplemented) +# GetImage returns a single image in an [ImageInList](#ImageInList) struct. You must supply an image name as a string. +# If the image cannot be found, an [ImageNotFound](#ImageNotFound) error will be returned. +method GetImage(name: string) -> (image: ImageInList) + +# BuildImage takes a [BuildInfo](#BuildInfo) structure and builds an image. At a minimum, you must provide the +# 'dockerfile' and 'tags' options in the BuildInfo structure. Upon a successful build, it will +# return the ID of the container. +method BuildImage(build: BuildInfo) -> (image: []string) # This function is not implemented yet. method CreateImage() -> (notimplemented: NotImplemented) @@ -531,7 +575,7 @@ method DeleteUnusedImages() -> (images: []string) # Commit, creates an image from an existing container. It requires the name or # ID of the container as well as the resulting image name. Optionally, you can define an author and message # to be added to the resulting image. You can also define changes to the resulting image for the following -# attributes: _CMD, ENTRYPOINT, ENV, EXPOSE, LABEL, STOPSIGNAL, USER, VOLUME, and WORKDIR_. To pause the +# attributes: _CMD, ENTRYPOINT, ENV, EXPOSE, LABEL, ONBUILD, STOPSIGNAL, USER, VOLUME, and WORKDIR_. To pause the # container while it is being committed, pass a _true_ bool for the pause argument. If the container cannot # be found by the ID or name provided, a (ContainerNotFound)[#ContainerNotFound] error will be returned; otherwise, # the resulting image's ID will be returned as a string. diff --git a/docs/podman-commit.1.md b/docs/podman-commit.1.md index 1ae83f10e..6416a4c69 100644 --- a/docs/podman-commit.1.md +++ b/docs/podman-commit.1.md @@ -24,7 +24,9 @@ Set the author for the committed image **--change, -c** Apply the following possible instructions to the created image: -**CMD** | **ENTRYPOINT** | **ENV** | **EXPOSE** | **LABEL** | **STOPSIGNAL** | **USER** | **VOLUME** | **WORKDIR** +**CMD** | **ENTRYPOINT** | **ENV** | **EXPOSE** | **LABEL** | **ONBUILD** | **STOPSIGNAL** | **USER** | **VOLUME** | **WORKDIR** + + Can be set multiple times **--format, -f** diff --git a/libpod/container_commit.go b/libpod/container_commit.go index 8cb04ec1a..2872012b8 100644 --- a/libpod/container_commit.go +++ b/libpod/container_commit.go @@ -24,6 +24,9 @@ type ContainerCommitOptions struct { Changes []string } +// ChangeCmds is the list of valid Changes commands to passed to the Commit call +var ChangeCmds = []string{"CMD", "ENTRYPOINT", "ENV", "EXPOSE", "LABEL", "ONBUILD", "STOPSIGNAL", "USER", "VOLUME", "WORKDIR"} + // Commit commits the changes between a container and its image, creating a new // image func (c *Container) Commit(ctx context.Context, destImage string, options ContainerCommitOptions) (*image.Image, error) { @@ -138,6 +141,8 @@ func (c *Container) Commit(ctx context.Context, destImage string, options Contai isLabelCleared = true } importBuilder.SetLabel(splitChange[1], splitChange[2]) + case "ONBUILD": + importBuilder.SetOnBuild(splitChange[1]) case "STOPSIGNAL": // No Set StopSignal case "USER": diff --git a/libpod/runtime.go b/libpod/runtime.go index 52a2653b3..b208bc718 100644 --- a/libpod/runtime.go +++ b/libpod/runtime.go @@ -151,6 +151,7 @@ var ( "/usr/lib/cri-o-runc/sbin/runc", }, ConmonPath: []string{ + "/usr/libexec/podman/conmon", "/usr/libexec/crio/conmon", "/usr/local/libexec/crio/conmon", "/usr/bin/conmon", diff --git a/pkg/varlinkapi/containers.go b/pkg/varlinkapi/containers.go index 41263b52b..2b84151a9 100644 --- a/pkg/varlinkapi/containers.go +++ b/pkg/varlinkapi/containers.go @@ -182,6 +182,9 @@ func (i *LibpodAPI) GetContainerLogs(call ioprojectatomicpodman.VarlinkCall, nam logs = append(logs, line) } } + + call.Continues = false + return call.ReplyGetContainerLogs(logs) } diff --git a/pkg/varlinkapi/containers_create.go b/pkg/varlinkapi/containers_create.go index 24edb05b8..40bd92e9a 100644 --- a/pkg/varlinkapi/containers_create.go +++ b/pkg/varlinkapi/containers_create.go @@ -22,14 +22,6 @@ import ( // CreateContainer ... func (i *LibpodAPI) CreateContainer(call ioprojectatomicpodman.VarlinkCall, config ioprojectatomicpodman.Create) error { - //mappings, err := util.ParseIDMapping(config.Uidmap, config.Gidmap, config.Subuidmap, config.Subgidmap) - //if err != nil { - // return err - //} - //storageOpts := storage.DefaultStoreOptions - //storageOpts.UIDMap = mappings.UIDMap - //storageOpts.GIDMap = mappings.GIDMap - runtime, err := libpodruntime.GetRuntime(i.Cli) if err != nil { return call.ReplyRuntimeError(err.Error()) @@ -120,7 +112,7 @@ func varlinkCreateToCreateConfig(ctx context.Context, create ioprojectatomicpodm if len(inputCommand) > 0 { // User command overrides data CMD command = append(command, inputCommand...) - } else if len(data.ContainerConfig.Cmd) > 0 && len(create.Entrypoint) > 0 { + } else if len(data.ContainerConfig.Cmd) > 0 && len(command) == 0 { // If not user command, add CMD command = append(command, data.ContainerConfig.Cmd...) } diff --git a/pkg/varlinkapi/images.go b/pkg/varlinkapi/images.go index c536e856a..551eb781c 100644 --- a/pkg/varlinkapi/images.go +++ b/pkg/varlinkapi/images.go @@ -3,12 +3,21 @@ package varlinkapi import ( "encoding/json" "fmt" + "io" + "path/filepath" + "strings" + "time" + "bytes" "github.com/containers/image/docker" + "github.com/containers/image/types" + "github.com/docker/go-units" "github.com/opencontainers/image-spec/specs-go/v1" + "github.com/pkg/errors" "github.com/projectatomic/buildah" + "github.com/projectatomic/buildah/imagebuildah" "github.com/projectatomic/libpod/cmd/podman/libpodruntime" - ioprojectatomicpodman "github.com/projectatomic/libpod/cmd/podman/varlink" + "github.com/projectatomic/libpod/cmd/podman/varlink" "github.com/projectatomic/libpod/libpod" "github.com/projectatomic/libpod/libpod/image" sysreg "github.com/projectatomic/libpod/pkg/registries" @@ -28,9 +37,9 @@ func (i *LibpodAPI) ListImages(call ioprojectatomicpodman.VarlinkCall) error { } var imageList []ioprojectatomicpodman.ImageInList for _, image := range images { - //size, _:= image.Size(getContext()) labels, _ := image.Labels(getContext()) containers, _ := image.Containers() + size, _ := image.Size(getContext()) i := ioprojectatomicpodman.ImageInList{ Id: image.ID(), @@ -38,7 +47,7 @@ func (i *LibpodAPI) ListImages(call ioprojectatomicpodman.VarlinkCall) error { RepoTags: image.Names(), RepoDigests: image.RepoDigests(), Created: image.Created().String(), - //Size: size, + Size: int64(*size), VirtualSize: image.VirtualSize, Containers: int64(len(containers)), Labels: labels, @@ -48,10 +57,197 @@ func (i *LibpodAPI) ListImages(call ioprojectatomicpodman.VarlinkCall) error { return call.ReplyListImages(imageList) } +// GetImage returns a single image in the form of a ImageInList +func (i *LibpodAPI) GetImage(call ioprojectatomicpodman.VarlinkCall, name string) error { + runtime, err := libpodruntime.GetRuntime(i.Cli) + if err != nil { + return call.ReplyRuntimeError(err.Error()) + } + newImage, err := runtime.ImageRuntime().NewFromLocal(name) + if err != nil { + return call.ReplyErrorOccurred(err.Error()) + } + labels, err := newImage.Labels(getContext()) + if err != nil { + return err + } + containers, err := newImage.Containers() + if err != nil { + return err + } + size, err := newImage.Size(getContext()) + if err != nil { + return err + } + + il := ioprojectatomicpodman.ImageInList{ + Id: newImage.ID(), + ParentId: newImage.Parent, + RepoTags: newImage.Names(), + RepoDigests: newImage.RepoDigests(), + Created: newImage.Created().String(), + Size: int64(*size), + VirtualSize: newImage.VirtualSize, + Containers: int64(len(containers)), + Labels: labels, + } + return call.ReplyGetImage(il) +} + // BuildImage ... -// TODO Waiting for buildah to be vendored into libpod to do this only one -func (i *LibpodAPI) BuildImage(call ioprojectatomicpodman.VarlinkCall) error { - return call.ReplyMethodNotImplemented("BuildImage") +func (i *LibpodAPI) BuildImage(call ioprojectatomicpodman.VarlinkCall, config ioprojectatomicpodman.BuildInfo) error { + var ( + memoryLimit int64 + memorySwap int64 + ) + + runtime, err := libpodruntime.GetRuntime(i.Cli) + if err != nil { + return call.ReplyRuntimeError(err.Error()) + } + defer runtime.Shutdown(false) + + systemContext := types.SystemContext{} + dockerfiles := config.Dockerfile + contextDir := "" + + for i := range dockerfiles { + if strings.HasPrefix(dockerfiles[i], "http://") || + strings.HasPrefix(dockerfiles[i], "https://") || + strings.HasPrefix(dockerfiles[i], "git://") || + strings.HasPrefix(dockerfiles[i], "github.com/") { + continue + } + absFile, err := filepath.Abs(dockerfiles[i]) + if err != nil { + return errors.Wrapf(err, "error determining path to file %q", dockerfiles[i]) + } + contextDir = filepath.Dir(absFile) + dockerfiles[i], err = filepath.Rel(contextDir, absFile) + if err != nil { + return errors.Wrapf(err, "error determining path to file %q", dockerfiles[i]) + } + break + } + + pullPolicy := imagebuildah.PullNever + if config.Pull { + pullPolicy = imagebuildah.PullIfMissing + } + + if config.Pull_always { + pullPolicy = imagebuildah.PullAlways + } + + format := "oci" + if config.Image_format != "" { + format = config.Image_format + } + + if strings.HasPrefix(format, "oci") { + format = imagebuildah.OCIv1ImageFormat + } else if strings.HasPrefix(format, "docker") { + format = imagebuildah.Dockerv2ImageFormat + } else { + return call.ReplyErrorOccurred(fmt.Sprintf("unrecognized image type %q", format)) + } + + if config.Memory != "" { + memoryLimit, err = units.RAMInBytes(config.Memory) + if err != nil { + return call.ReplyErrorOccurred(err.Error()) + } + } + + if config.Memory_swap != "" { + memorySwap, err = units.RAMInBytes(config.Memory_swap) + if err != nil { + return call.ReplyErrorOccurred(err.Error()) + } + } + + output := bytes.NewBuffer([]byte{}) + commonOpts := &buildah.CommonBuildOptions{ + AddHost: config.Add_hosts, + CgroupParent: config.Cgroup_parent, + CPUPeriod: uint64(config.Cpu_period), + CPUQuota: config.Cpu_quota, + CPUSetCPUs: config.Cpuset_cpus, + CPUSetMems: config.Cpuset_mems, + Memory: memoryLimit, + MemorySwap: memorySwap, + ShmSize: config.Shm_size, + Ulimit: config.Ulimit, + Volumes: config.Volume, + } + + options := imagebuildah.BuildOptions{ + ContextDirectory: contextDir, + PullPolicy: pullPolicy, + Compression: imagebuildah.Gzip, + Quiet: false, + //SignaturePolicyPath: + Args: config.Build_args, + //Output: + AdditionalTags: config.Tags, + //Runtime: runtime. + //RuntimeArgs: , + OutputFormat: format, + SystemContext: &systemContext, + CommonBuildOpts: commonOpts, + Squash: config.Squash, + Labels: config.Label, + Annotations: config.Annotations, + ReportWriter: output, + } + + if call.WantsMore() { + call.Continues = true + } + + c := build(runtime, options, config.Dockerfile) + var log []string + done := false + for { + line, err := output.ReadString('\n') + if err == nil { + log = append(log, line) + continue + } else if err == io.EOF { + select { + case err := <-c: + if err != nil { + return call.ReplyErrorOccurred(err.Error()) + } + done = true + default: + if !call.WantsMore() { + time.Sleep(1 * time.Second) + break + } + call.ReplyBuildImage(log) + log = []string{} + } + } else { + return call.ReplyErrorOccurred(err.Error()) + } + if done { + break + } + } + call.Continues = false + return call.ReplyBuildImage(log) +} + +func build(runtime *libpod.Runtime, options imagebuildah.BuildOptions, dockerfiles []string) chan error { + c := make(chan error) + go func() { + err := runtime.Build(getContext(), options, dockerfiles...) + c <- err + close(c) + }() + + return c } // CreateImage ... diff --git a/vendor.conf b/vendor.conf index 6f20bc1e5..e53d04523 100644 --- a/vendor.conf +++ b/vendor.conf @@ -88,7 +88,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 25f4e8ec639044bff4ab393188d083782f07b61c +github.com/projectatomic/buildah b66e8531456e2986ffc409f591c9005813589a34 github.com/Nvveen/Gotty master github.com/fsouza/go-dockerclient master github.com/openshift/imagebuilder master diff --git a/vendor/github.com/projectatomic/buildah/commit.go b/vendor/github.com/projectatomic/buildah/commit.go index 75d2626f5..ab46a0643 100644 --- a/vendor/github.com/projectatomic/buildah/commit.go +++ b/vendor/github.com/projectatomic/buildah/commit.go @@ -52,6 +52,9 @@ type CommitOptions struct { // Squash tells the builder to produce an image with a single layer // instead of with possibly more than one layer. Squash bool + + // OnBuild is a list of commands to be run by images based on this image + OnBuild []string } // PushOptions can be used to alter how an image is copied somewhere. diff --git a/vendor/github.com/projectatomic/buildah/config.go b/vendor/github.com/projectatomic/buildah/config.go index c5fabdec6..3d67895da 100644 --- a/vendor/github.com/projectatomic/buildah/config.go +++ b/vendor/github.com/projectatomic/buildah/config.go @@ -331,6 +331,24 @@ func (b *Builder) SetUser(spec string) { b.Docker.Config.User = spec } +// OnBuild returns the OnBuild value from the container. +func (b *Builder) OnBuild() []string { + return copyStringSlice(b.Docker.Config.OnBuild) +} + +// ClearOnBuild removes all values from the OnBuild structure +func (b *Builder) ClearOnBuild() { + b.Docker.Config.OnBuild = []string{} +} + +// SetOnBuild sets a trigger instruction to be executed when the image is used +// as the base of another image. +// 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) { + b.Docker.Config.OnBuild = append(b.Docker.Config.OnBuild, onBuild) +} + // WorkDir returns the default working directory for running commands in the // container, or in a container built using an image built from this container. func (b *Builder) WorkDir() string { @@ -348,7 +366,7 @@ func (b *Builder) SetWorkDir(there string) { // Shell returns the default shell for running commands in the // container, or in a container built using an image built from this container. func (b *Builder) Shell() []string { - return b.Docker.Config.Shell + return copyStringSlice(b.Docker.Config.Shell) } // SetShell sets the default shell for running @@ -357,7 +375,7 @@ 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) { - b.Docker.Config.Shell = shell + b.Docker.Config.Shell = copyStringSlice(shell) } // Env returns a list of key-value pairs to be set when running commands in the diff --git a/vendor/github.com/projectatomic/buildah/imagebuildah/build.go b/vendor/github.com/projectatomic/buildah/imagebuildah/build.go index a2e2912e3..f3d28510a 100644 --- a/vendor/github.com/projectatomic/buildah/imagebuildah/build.go +++ b/vendor/github.com/projectatomic/buildah/imagebuildah/build.go @@ -138,6 +138,8 @@ type BuildOptions struct { Labels []string // Annotation metadata for an image Annotations []string + // OnBuild commands to be run by images based on this image + OnBuild []string } // Executor is a buildah-based implementation of the imagebuilder.Executor @@ -183,6 +185,7 @@ type Executor struct { squash bool labels []string annotations []string + onbuild []string } // withName creates a new child executor that will be used whenever a COPY statement uses --from=NAME. @@ -598,6 +601,7 @@ func (b *Executor) Prepare(ctx context.Context, ib *imagebuilder.Builder, node * Labels: builder.Labels(), Shell: builder.Shell(), StopSignal: builder.StopSignal(), + OnBuild: builder.OnBuild(), } var rootfs *docker.RootFS if builder.Docker.RootFS != nil { @@ -714,6 +718,10 @@ func (b *Executor) Commit(ctx context.Context, ib *imagebuilder.Builder) (err er for v := range config.Volumes { b.builder.AddVolume(v) } + b.builder.ClearOnBuild() + for _, onBuildSpec := range config.OnBuild { + b.builder.SetOnBuild(onBuildSpec) + } b.builder.SetWorkDir(config.WorkingDir) b.builder.SetEntrypoint(config.Entrypoint) b.builder.SetShell(config.Shell) diff --git a/vendor/github.com/projectatomic/buildah/imagebuildah/chroot_symlink.go b/vendor/github.com/projectatomic/buildah/imagebuildah/chroot_symlink.go index b2452b61c..f1fec7f70 100644 --- a/vendor/github.com/projectatomic/buildah/imagebuildah/chroot_symlink.go +++ b/vendor/github.com/projectatomic/buildah/imagebuildah/chroot_symlink.go @@ -37,7 +37,7 @@ func resolveChrootedSymlinks() { os.Exit(1) } - // Our second paramter is the path name to evaluate for symbolic links + // Our second parameter is the path name to evaluate for symbolic links symLink, err := getSymbolicLink(flag.Arg(0), flag.Arg(1)) if err != nil { fmt.Fprintf(os.Stderr, "error getting symbolic links: %v\n", err) diff --git a/vendor/github.com/projectatomic/buildah/pkg/cli/common.go b/vendor/github.com/projectatomic/buildah/pkg/cli/common.go index e4a30a315..a7b61d561 100644 --- a/vendor/github.com/projectatomic/buildah/pkg/cli/common.go +++ b/vendor/github.com/projectatomic/buildah/pkg/cli/common.go @@ -152,6 +152,10 @@ var ( Name: "squash", Usage: "Squash newly built layers into a single new layer. Buildah does not currently support caching so this is a NOOP.", }, + cli.BoolTFlag{ + Name: "stream", + Usage: "There is no daemon in use, so this command is a NOOP.", + }, cli.StringSliceFlag{ Name: "tag, t", Usage: "tagged `name` to apply to the built image", |