summaryrefslogtreecommitdiff
path: root/pkg/bindings/images/images.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/bindings/images/images.go')
-rw-r--r--pkg/bindings/images/images.go159
1 files changed, 2 insertions, 157 deletions
diff --git a/pkg/bindings/images/images.go b/pkg/bindings/images/images.go
index a80c94025..a78e7f4c6 100644
--- a/pkg/bindings/images/images.go
+++ b/pkg/bindings/images/images.go
@@ -1,7 +1,6 @@
package images
import (
- "bytes"
"context"
"fmt"
"io"
@@ -9,14 +8,11 @@ import (
"net/url"
"strconv"
- "github.com/containers/buildah"
"github.com/containers/image/v5/types"
"github.com/containers/podman/v2/pkg/api/handlers"
"github.com/containers/podman/v2/pkg/auth"
"github.com/containers/podman/v2/pkg/bindings"
"github.com/containers/podman/v2/pkg/domain/entities"
- "github.com/docker/go-units"
- jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
)
@@ -242,112 +238,6 @@ func Untag(ctx context.Context, nameOrID, tag, repo string) error {
return response.Process(nil)
}
-// Build creates an image using a containerfile reference
-func Build(ctx context.Context, containerFiles []string, options entities.BuildOptions, tarfile io.Reader) (*entities.BuildReport, error) {
- var (
- platform string
- report entities.BuildReport
- )
- conn, err := bindings.GetClient(ctx)
- if err != nil {
- return nil, err
- }
- params := url.Values{}
- params.Set("dockerfile", containerFiles[0])
- if t := options.Output; len(t) > 0 {
- params.Set("t", t)
- }
- for _, tag := range options.AdditionalTags {
- params.Add("t", tag)
- }
- // TODO Remote, Quiet
- if options.NoCache {
- params.Set("nocache", "1")
- }
- // TODO cachefrom
- if options.PullPolicy == buildah.PullAlways {
- params.Set("pull", "1")
- }
- if options.RemoveIntermediateCtrs {
- params.Set("rm", "1")
- }
- if options.ForceRmIntermediateCtrs {
- params.Set("forcerm", "1")
- }
- if mem := options.CommonBuildOpts.Memory; mem > 0 {
- params.Set("memory", strconv.Itoa(int(mem)))
- }
- if memSwap := options.CommonBuildOpts.MemorySwap; memSwap > 0 {
- params.Set("memswap", strconv.Itoa(int(memSwap)))
- }
- if cpuShares := options.CommonBuildOpts.CPUShares; cpuShares > 0 {
- params.Set("cpushares", strconv.Itoa(int(cpuShares)))
- }
- if cpuSetCpus := options.CommonBuildOpts.CPUSetCPUs; len(cpuSetCpus) > 0 {
- params.Set("cpusetcpues", cpuSetCpus)
- }
- if cpuPeriod := options.CommonBuildOpts.CPUPeriod; cpuPeriod > 0 {
- params.Set("cpuperiod", strconv.Itoa(int(cpuPeriod)))
- }
- if cpuQuota := options.CommonBuildOpts.CPUQuota; cpuQuota > 0 {
- params.Set("cpuquota", strconv.Itoa(int(cpuQuota)))
- }
- if buildArgs := options.Args; len(buildArgs) > 0 {
- bArgs, err := jsoniter.MarshalToString(buildArgs)
- if err != nil {
- return nil, err
- }
- params.Set("buildargs", bArgs)
- }
- if shmSize := options.CommonBuildOpts.ShmSize; len(shmSize) > 0 {
- shmBytes, err := units.RAMInBytes(shmSize)
- if err != nil {
- return nil, err
- }
- params.Set("shmsize", strconv.Itoa(int(shmBytes)))
- }
- if options.Squash {
- params.Set("squash", "1")
- }
- if labels := options.Labels; len(labels) > 0 {
- l, err := jsoniter.MarshalToString(labels)
- if err != nil {
- return nil, err
- }
- params.Set("labels", l)
- }
-
- // TODO network?
- if OS := options.OS; len(OS) > 0 {
- platform += OS
- }
- if arch := options.Architecture; len(arch) > 0 {
- platform += "/" + arch
- }
- if len(platform) > 0 {
- params.Set("platform", platform)
- }
- // TODO outputs?
-
- response, err := conn.DoRequest(tarfile, http.MethodPost, "/build", params, nil)
- if err != nil {
- return nil, err
- }
- var streamReponse []byte
- bb := bytes.NewBuffer(streamReponse)
- if _, err = io.Copy(bb, response.Body); err != nil {
- return nil, err
- }
- var s struct {
- Stream string `json:"stream"`
- }
- if err := jsoniter.UnmarshalFromString(bb.String(), &s); err != nil {
- return nil, err
- }
- fmt.Print(s.Stream)
- return &report, nil
-}
-
// Imports adds the given image to the local image store. This can be done by file and the given reader
// or via the url parameter. Additional metadata can be associated with the image by using the changes and
// message parameters. The image can also be tagged given a reference. One of url OR r must be provided.
@@ -380,51 +270,6 @@ func Import(ctx context.Context, changes []string, message, reference, u *string
return &report, response.Process(&report)
}
-// Pull is the binding for libpod's v2 endpoints for pulling images. Note that
-// `rawImage` must be a reference to a registry (i.e., of docker transport or be
-// normalized to one). Other transports are rejected as they do not make sense
-// in a remote context.
-func Pull(ctx context.Context, rawImage string, options entities.ImagePullOptions) ([]string, error) {
- conn, err := bindings.GetClient(ctx)
- if err != nil {
- return nil, err
- }
- params := url.Values{}
- params.Set("reference", rawImage)
- params.Set("overrideArch", options.OverrideArch)
- params.Set("overrideOS", options.OverrideOS)
- params.Set("overrideVariant", options.OverrideVariant)
- if options.SkipTLSVerify != types.OptionalBoolUndefined {
- // Note: we have to verify if skipped is false.
- verifyTLS := bool(options.SkipTLSVerify == types.OptionalBoolFalse)
- params.Set("tlsVerify", strconv.FormatBool(verifyTLS))
- }
- params.Set("allTags", strconv.FormatBool(options.AllTags))
-
- // TODO: have a global system context we can pass around (1st argument)
- header, err := auth.Header(nil, options.Authfile, options.Username, options.Password)
- if err != nil {
- return nil, err
- }
-
- response, err := conn.DoRequest(nil, http.MethodPost, "/images/pull", params, header)
- if err != nil {
- return nil, err
- }
-
- reports := []handlers.LibpodImagesPullReport{}
- if err := response.Process(&reports); err != nil {
- return nil, err
- }
-
- pulledImages := []string{}
- for _, r := range reports {
- pulledImages = append(pulledImages, r.ID)
- }
-
- return pulledImages, nil
-}
-
// Push is the binding for libpod's v2 endpoints for push images. Note that
// `source` must be a referring to an image in the remote's container storage.
// The destination must be a reference to a registry (i.e., of docker transport
@@ -437,7 +282,7 @@ func Push(ctx context.Context, source string, destination string, options entiti
}
// TODO: have a global system context we can pass around (1st argument)
- header, err := auth.Header(nil, options.Authfile, options.Username, options.Password)
+ header, err := auth.Header(nil, auth.XRegistryAuthHeader, options.Authfile, options.Username, options.Password)
if err != nil {
return err
}
@@ -480,7 +325,7 @@ func Search(ctx context.Context, term string, opts entities.ImageSearchOptions)
}
// TODO: have a global system context we can pass around (1st argument)
- header, err := auth.Header(nil, opts.Authfile, "", "")
+ header, err := auth.Header(nil, auth.XRegistryAuthHeader, opts.Authfile, "", "")
if err != nil {
return nil, err
}