mirror of
https://github.com/containers/podman.git
synced 2025-07-04 10:10:32 +08:00
varlink build fixes
the varlink build was not working as designed and required some touch-ups: * return a struct that includes logs and the new image ID * pass namespaceoption so that networking in buildah works Signed-off-by: baude <bbaude@redhat.com> Closes: #903 Approved by: rhatdan
This commit is contained in:
17
API.md
17
API.md
@ -5,7 +5,7 @@ in the [API.md](https://github.com/projectatomic/libpod/blob/master/API.md) file
|
|||||||
|
|
||||||
[func AttachToContainer() NotImplemented](#AttachToContainer)
|
[func AttachToContainer() NotImplemented](#AttachToContainer)
|
||||||
|
|
||||||
[func BuildImage(build: BuildInfo) []string](#BuildImage)
|
[func BuildImage(build: BuildInfo) BuildResponse](#BuildImage)
|
||||||
|
|
||||||
[func Commit(name: string, image_name: string, changes: []string, author: string, message: string, pause: bool) string](#Commit)
|
[func Commit(name: string, image_name: string, changes: []string, author: string, message: string, pause: bool) string](#Commit)
|
||||||
|
|
||||||
@ -87,6 +87,8 @@ in the [API.md](https://github.com/projectatomic/libpod/blob/master/API.md) file
|
|||||||
|
|
||||||
[type BuildInfo](#BuildInfo)
|
[type BuildInfo](#BuildInfo)
|
||||||
|
|
||||||
|
[type BuildResponse](#BuildResponse)
|
||||||
|
|
||||||
[type ContainerChanges](#ContainerChanges)
|
[type ContainerChanges](#ContainerChanges)
|
||||||
|
|
||||||
[type ContainerMount](#ContainerMount)
|
[type ContainerMount](#ContainerMount)
|
||||||
@ -148,10 +150,10 @@ This method has not be implemented yet.
|
|||||||
### <a name="BuildImage"></a>func BuildImage
|
### <a name="BuildImage"></a>func BuildImage
|
||||||
<div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;">
|
<div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;">
|
||||||
|
|
||||||
method BuildImage(build: [BuildInfo](#BuildInfo)) [[]string](#[]string)</div>
|
method BuildImage(build: [BuildInfo](#BuildInfo)) [BuildResponse](#BuildResponse)</div>
|
||||||
BuildImage takes a [BuildInfo](#BuildInfo) structure and builds an image. At a minimum, you must provide the
|
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
|
'dockerfile' and 'tags' options in the BuildInfo structure. It will return a [BuildResponse](#BuildResponse) structure
|
||||||
return the ID of the container.
|
that contains the build logs and resulting image ID.
|
||||||
### <a name="Commit"></a>func Commit
|
### <a name="Commit"></a>func Commit
|
||||||
<div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;">
|
<div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;">
|
||||||
|
|
||||||
@ -557,6 +559,13 @@ annotations [[]string](#[]string)
|
|||||||
build_args [map[string]](#map[string])
|
build_args [map[string]](#map[string])
|
||||||
|
|
||||||
image_format [string](https://godoc.org/builtin#string)
|
image_format [string](https://godoc.org/builtin#string)
|
||||||
|
### <a name="BuildResponse"></a>type BuildResponse
|
||||||
|
|
||||||
|
BuildResponse is used to describe the responses for building images
|
||||||
|
|
||||||
|
logs [[]string](#[]string)
|
||||||
|
|
||||||
|
id [string](https://godoc.org/builtin#string)
|
||||||
### <a name="ContainerChanges"></a>type ContainerChanges
|
### <a name="ContainerChanges"></a>type ContainerChanges
|
||||||
|
|
||||||
ContainerChanges describes the return struct for ListContainerChanges
|
ContainerChanges describes the return struct for ListContainerChanges
|
||||||
|
@ -5,7 +5,9 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/opencontainers/runtime-spec/specs-go"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"github.com/projectatomic/buildah"
|
||||||
"github.com/projectatomic/buildah/imagebuildah"
|
"github.com/projectatomic/buildah/imagebuildah"
|
||||||
buildahcli "github.com/projectatomic/buildah/pkg/cli"
|
buildahcli "github.com/projectatomic/buildah/pkg/cli"
|
||||||
"github.com/projectatomic/buildah/pkg/parse"
|
"github.com/projectatomic/buildah/pkg/parse"
|
||||||
@ -30,6 +32,8 @@ var (
|
|||||||
func buildCmd(c *cli.Context) error {
|
func buildCmd(c *cli.Context) error {
|
||||||
// The following was taken directly from projectatomic/buildah/cmd/bud.go
|
// The following was taken directly from projectatomic/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
|
||||||
|
|
||||||
|
var namespace []buildah.NamespaceOption
|
||||||
output := ""
|
output := ""
|
||||||
tags := []string{}
|
tags := []string{}
|
||||||
if c.IsSet("tag") || c.IsSet("t") {
|
if c.IsSet("tag") || c.IsSet("t") {
|
||||||
@ -151,6 +155,13 @@ func buildCmd(c *cli.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hostNetwork := buildah.NamespaceOption{
|
||||||
|
Name: specs.NetworkNamespace,
|
||||||
|
Host: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace = append(namespace, hostNetwork)
|
||||||
|
|
||||||
options := imagebuildah.BuildOptions{
|
options := imagebuildah.BuildOptions{
|
||||||
ContextDirectory: contextDir,
|
ContextDirectory: contextDir,
|
||||||
PullPolicy: pullPolicy,
|
PullPolicy: pullPolicy,
|
||||||
@ -170,6 +181,7 @@ func buildCmd(c *cli.Context) error {
|
|||||||
Squash: c.Bool("squash"),
|
Squash: c.Bool("squash"),
|
||||||
Labels: c.StringSlice("label"),
|
Labels: c.StringSlice("label"),
|
||||||
Annotations: c.StringSlice("annotation"),
|
Annotations: c.StringSlice("annotation"),
|
||||||
|
NamespaceOptions: namespace,
|
||||||
}
|
}
|
||||||
|
|
||||||
if !c.Bool("quiet") {
|
if !c.Bool("quiet") {
|
||||||
|
@ -320,6 +320,12 @@ type BuildInfo (
|
|||||||
image_format: string
|
image_format: string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# BuildResponse is used to describe the responses for building images
|
||||||
|
type BuildResponse (
|
||||||
|
logs: []string,
|
||||||
|
id: string
|
||||||
|
)
|
||||||
|
|
||||||
# Ping provides a response for developers to ensure their varlink setup is working.
|
# Ping provides a response for developers to ensure their varlink setup is working.
|
||||||
# #### Example
|
# #### Example
|
||||||
# ~~~
|
# ~~~
|
||||||
@ -525,9 +531,9 @@ method ListImages() -> (images: []ImageInList)
|
|||||||
method GetImage(name: string) -> (image: ImageInList)
|
method GetImage(name: string) -> (image: ImageInList)
|
||||||
|
|
||||||
# BuildImage takes a [BuildInfo](#BuildInfo) structure and builds an image. At a minimum, you must provide the
|
# 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
|
# 'dockerfile' and 'tags' options in the BuildInfo structure. It will return a [BuildResponse](#BuildResponse) structure
|
||||||
# return the ID of the container.
|
# that contains the build logs and resulting image ID.
|
||||||
method BuildImage(build: BuildInfo) -> (image: []string)
|
method BuildImage(build: BuildInfo) -> (image: BuildResponse)
|
||||||
|
|
||||||
# This function is not implemented yet.
|
# This function is not implemented yet.
|
||||||
method CreateImage() -> (notimplemented: NotImplemented)
|
method CreateImage() -> (notimplemented: NotImplemented)
|
||||||
|
@ -13,6 +13,7 @@ import (
|
|||||||
"github.com/containers/image/types"
|
"github.com/containers/image/types"
|
||||||
"github.com/docker/go-units"
|
"github.com/docker/go-units"
|
||||||
"github.com/opencontainers/image-spec/specs-go/v1"
|
"github.com/opencontainers/image-spec/specs-go/v1"
|
||||||
|
"github.com/opencontainers/runtime-spec/specs-go"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/projectatomic/buildah"
|
"github.com/projectatomic/buildah"
|
||||||
"github.com/projectatomic/buildah/imagebuildah"
|
"github.com/projectatomic/buildah/imagebuildah"
|
||||||
@ -99,6 +100,7 @@ func (i *LibpodAPI) BuildImage(call ioprojectatomicpodman.VarlinkCall, config io
|
|||||||
var (
|
var (
|
||||||
memoryLimit int64
|
memoryLimit int64
|
||||||
memorySwap int64
|
memorySwap int64
|
||||||
|
namespace []buildah.NamespaceOption
|
||||||
)
|
)
|
||||||
|
|
||||||
runtime, err := libpodruntime.GetRuntime(i.Cli)
|
runtime, err := libpodruntime.GetRuntime(i.Cli)
|
||||||
@ -181,6 +183,13 @@ func (i *LibpodAPI) BuildImage(call ioprojectatomicpodman.VarlinkCall, config io
|
|||||||
Volumes: config.Volume,
|
Volumes: config.Volume,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hostNetwork := buildah.NamespaceOption{
|
||||||
|
Name: specs.NetworkNamespace,
|
||||||
|
Host: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace = append(namespace, hostNetwork)
|
||||||
|
|
||||||
options := imagebuildah.BuildOptions{
|
options := imagebuildah.BuildOptions{
|
||||||
ContextDirectory: contextDir,
|
ContextDirectory: contextDir,
|
||||||
PullPolicy: pullPolicy,
|
PullPolicy: pullPolicy,
|
||||||
@ -192,13 +201,14 @@ func (i *LibpodAPI) BuildImage(call ioprojectatomicpodman.VarlinkCall, config io
|
|||||||
AdditionalTags: config.Tags,
|
AdditionalTags: config.Tags,
|
||||||
//Runtime: runtime.
|
//Runtime: runtime.
|
||||||
//RuntimeArgs: ,
|
//RuntimeArgs: ,
|
||||||
OutputFormat: format,
|
OutputFormat: format,
|
||||||
SystemContext: &systemContext,
|
SystemContext: &systemContext,
|
||||||
CommonBuildOpts: commonOpts,
|
CommonBuildOpts: commonOpts,
|
||||||
Squash: config.Squash,
|
Squash: config.Squash,
|
||||||
Labels: config.Label,
|
Labels: config.Label,
|
||||||
Annotations: config.Annotations,
|
Annotations: config.Annotations,
|
||||||
ReportWriter: output,
|
ReportWriter: output,
|
||||||
|
NamespaceOptions: namespace,
|
||||||
}
|
}
|
||||||
|
|
||||||
if call.WantsMore() {
|
if call.WantsMore() {
|
||||||
@ -225,7 +235,10 @@ func (i *LibpodAPI) BuildImage(call ioprojectatomicpodman.VarlinkCall, config io
|
|||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
call.ReplyBuildImage(log)
|
br := ioprojectatomicpodman.BuildResponse{
|
||||||
|
Logs: log,
|
||||||
|
}
|
||||||
|
call.ReplyBuildImage(br)
|
||||||
log = []string{}
|
log = []string{}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -236,7 +249,15 @@ func (i *LibpodAPI) BuildImage(call ioprojectatomicpodman.VarlinkCall, config io
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
call.Continues = false
|
call.Continues = false
|
||||||
return call.ReplyBuildImage(log)
|
newImage, err := runtime.ImageRuntime().NewFromLocal(config.Tags[0])
|
||||||
|
if err != nil {
|
||||||
|
return call.ReplyErrorOccurred(err.Error())
|
||||||
|
}
|
||||||
|
br := ioprojectatomicpodman.BuildResponse{
|
||||||
|
Logs: log,
|
||||||
|
Id: newImage.ID(),
|
||||||
|
}
|
||||||
|
return call.ReplyBuildImage(br)
|
||||||
}
|
}
|
||||||
|
|
||||||
func build(runtime *libpod.Runtime, options imagebuildah.BuildOptions, dockerfiles []string) chan error {
|
func build(runtime *libpod.Runtime, options imagebuildah.BuildOptions, dockerfiles []string) chan error {
|
||||||
|
Reference in New Issue
Block a user