1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #21268 from calavera/remove_dockerfile_from_api

Remove dockerfile dependency from the API.
This commit is contained in:
Sebastiaan van Stijn 2016-03-23 19:34:21 -07:00
commit 5ef04b1c6d
7 changed files with 49 additions and 35 deletions

View file

@ -3,9 +3,9 @@ package image
import ( import (
"io" "io"
"github.com/docker/docker/api/types/backend"
"github.com/docker/docker/reference" "github.com/docker/docker/reference"
"github.com/docker/engine-api/types" "github.com/docker/engine-api/types"
"github.com/docker/engine-api/types/container"
"github.com/docker/engine-api/types/registry" "github.com/docker/engine-api/types/registry"
"golang.org/x/net/context" "golang.org/x/net/context"
) )
@ -20,7 +20,7 @@ type Backend interface {
} }
type containerBackend interface { type containerBackend interface {
Commit(name string, config *types.ContainerCommitConfig) (imageID string, err error) Commit(name string, config *backend.ContainerCommitConfig) (imageID string, err error)
} }
type imageBackend interface { type imageBackend interface {
@ -33,7 +33,7 @@ type imageBackend interface {
type importExportBackend interface { type importExportBackend interface {
LoadImage(inTar io.ReadCloser, outStream io.Writer, quiet bool) error LoadImage(inTar io.ReadCloser, outStream io.Writer, quiet bool) error
ImportImage(src string, newRef reference.Named, msg string, inConfig io.ReadCloser, outStream io.Writer, config *container.Config) error ImportImage(src string, newRef reference.Named, msg string, inConfig io.ReadCloser, outStream io.Writer, changes []string) error
ExportImage(names []string, outStream io.Writer) error ExportImage(names []string, outStream io.Writer) error
} }

View file

@ -13,7 +13,7 @@ import (
"github.com/docker/distribution/digest" "github.com/docker/distribution/digest"
"github.com/docker/distribution/registry/api/errcode" "github.com/docker/distribution/registry/api/errcode"
"github.com/docker/docker/api/server/httputils" "github.com/docker/docker/api/server/httputils"
"github.com/docker/docker/builder/dockerfile" "github.com/docker/docker/api/types/backend"
"github.com/docker/docker/pkg/ioutils" "github.com/docker/docker/pkg/ioutils"
"github.com/docker/docker/pkg/streamformatter" "github.com/docker/docker/pkg/streamformatter"
"github.com/docker/docker/reference" "github.com/docker/docker/reference"
@ -48,19 +48,17 @@ func (s *imageRouter) postCommit(ctx context.Context, w http.ResponseWriter, r *
c = &container.Config{} c = &container.Config{}
} }
newConfig, err := dockerfile.BuildFromConfig(c, r.Form["changes"]) commitCfg := &backend.ContainerCommitConfig{
if err != nil { ContainerCommitConfig: types.ContainerCommitConfig{
return err Pause: pause,
} Repo: r.Form.Get("repo"),
Tag: r.Form.Get("tag"),
commitCfg := &types.ContainerCommitConfig{ Author: r.Form.Get("author"),
Pause: pause, Comment: r.Form.Get("comment"),
Repo: r.Form.Get("repo"), Config: c,
Tag: r.Form.Get("tag"), MergeConfigs: true,
Author: r.Form.Get("author"), },
Comment: r.Form.Get("comment"), Changes: r.Form["changes"],
Config: newConfig,
MergeConfigs: true,
} }
imgID, err := s.backend.Commit(cname, commitCfg) imgID, err := s.backend.Commit(cname, commitCfg)
@ -160,17 +158,10 @@ func (s *imageRouter) postImagesCreate(ctx context.Context, w http.ResponseWrite
} }
src := r.Form.Get("fromSrc") src := r.Form.Get("fromSrc")
// 'err' MUST NOT be defined within this block, we need any error // 'err' MUST NOT be defined within this block, we need any error
// generated from the download to be available to the output // generated from the download to be available to the output
// stream processing below // stream processing below
var newConfig *container.Config err = s.backend.ImportImage(src, newRef, message, r.Body, output, r.Form["changes"])
newConfig, err = dockerfile.BuildFromConfig(&container.Config{}, r.Form["changes"])
if err != nil {
return err
}
err = s.backend.ImportImage(src, newRef, message, r.Body, output, newConfig)
} }
if err != nil { if err != nil {
if !output.Flushed() { if !output.Flushed() {

View file

@ -67,3 +67,11 @@ type ExecProcessConfig struct {
Privileged *bool `json:"privileged,omitempty"` Privileged *bool `json:"privileged,omitempty"`
User string `json:"user,omitempty"` User string `json:"user,omitempty"`
} }
// ContainerCommitConfig is a wrapper around
// types.ContainerCommitConfig that also
// transports configuration changes for a container.
type ContainerCommitConfig struct {
types.ContainerCommitConfig
Changes []string
}

View file

@ -9,6 +9,7 @@ import (
"os" "os"
"time" "time"
"github.com/docker/docker/api/types/backend"
"github.com/docker/docker/reference" "github.com/docker/docker/reference"
"github.com/docker/engine-api/types" "github.com/docker/engine-api/types"
"github.com/docker/engine-api/types/container" "github.com/docker/engine-api/types/container"
@ -118,7 +119,7 @@ type Backend interface {
// ContainerRm removes a container specified by `id`. // ContainerRm removes a container specified by `id`.
ContainerRm(name string, config *types.ContainerRmConfig) error ContainerRm(name string, config *types.ContainerRmConfig) error
// Commit creates a new Docker image from an existing Docker container. // Commit creates a new Docker image from an existing Docker container.
Commit(string, *types.ContainerCommitConfig) (string, error) Commit(string, *backend.ContainerCommitConfig) (string, error)
// Kill stops the container execution abruptly. // Kill stops the container execution abruptly.
ContainerKill(containerID string, sig uint64) error ContainerKill(containerID string, sig uint64) error
// Start starts a new container // Start starts a new container

View file

@ -19,6 +19,7 @@ import (
"time" "time"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/docker/docker/api/types/backend"
"github.com/docker/docker/builder" "github.com/docker/docker/builder"
"github.com/docker/docker/builder/dockerfile/parser" "github.com/docker/docker/builder/dockerfile/parser"
"github.com/docker/docker/pkg/archive" "github.com/docker/docker/pkg/archive"
@ -84,10 +85,12 @@ func (b *Builder) commit(id string, autoCmd strslice.StrSlice, comment string) e
autoConfig := *b.runConfig autoConfig := *b.runConfig
autoConfig.Cmd = autoCmd autoConfig.Cmd = autoCmd
commitCfg := &types.ContainerCommitConfig{ commitCfg := &backend.ContainerCommitConfig{
Author: b.maintainer, ContainerCommitConfig: types.ContainerCommitConfig{
Pause: true, Author: b.maintainer,
Config: &autoConfig, Pause: true,
Config: &autoConfig,
},
} }
// Commit the container // Commit the container

View file

@ -7,6 +7,8 @@ import (
"strings" "strings"
"time" "time"
"github.com/docker/docker/api/types/backend"
"github.com/docker/docker/builder/dockerfile"
"github.com/docker/docker/container" "github.com/docker/docker/container"
"github.com/docker/docker/dockerversion" "github.com/docker/docker/dockerversion"
"github.com/docker/docker/image" "github.com/docker/docker/image"
@ -14,7 +16,6 @@ import (
"github.com/docker/docker/pkg/archive" "github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/ioutils" "github.com/docker/docker/pkg/ioutils"
"github.com/docker/docker/reference" "github.com/docker/docker/reference"
"github.com/docker/engine-api/types"
containertypes "github.com/docker/engine-api/types/container" containertypes "github.com/docker/engine-api/types/container"
"github.com/docker/go-connections/nat" "github.com/docker/go-connections/nat"
) )
@ -98,7 +99,7 @@ func merge(userConf, imageConf *containertypes.Config) error {
// Commit creates a new filesystem image from the current state of a container. // Commit creates a new filesystem image from the current state of a container.
// The image can optionally be tagged into a repository. // The image can optionally be tagged into a repository.
func (daemon *Daemon) Commit(name string, c *types.ContainerCommitConfig) (string, error) { func (daemon *Daemon) Commit(name string, c *backend.ContainerCommitConfig) (string, error) {
container, err := daemon.GetContainer(name) container, err := daemon.GetContainer(name)
if err != nil { if err != nil {
return "", err return "", err
@ -114,8 +115,13 @@ func (daemon *Daemon) Commit(name string, c *types.ContainerCommitConfig) (strin
defer daemon.containerUnpause(container) defer daemon.containerUnpause(container)
} }
newConfig, err := dockerfile.BuildFromConfig(c.Config, c.Changes)
if err != nil {
return "", err
}
if c.MergeConfigs { if c.MergeConfigs {
if err := merge(c.Config, container.Config); err != nil { if err := merge(newConfig, container.Config); err != nil {
return "", err return "", err
} }
} }
@ -166,7 +172,7 @@ func (daemon *Daemon) Commit(name string, c *types.ContainerCommitConfig) (strin
config, err := json.Marshal(&image.Image{ config, err := json.Marshal(&image.Image{
V1Image: image.V1Image{ V1Image: image.V1Image{
DockerVersion: dockerversion.Version, DockerVersion: dockerversion.Version,
Config: c.Config, Config: newConfig,
Architecture: runtime.GOARCH, Architecture: runtime.GOARCH,
OS: runtime.GOOS, OS: runtime.GOOS,
Container: container.ID, Container: container.ID,

View file

@ -8,6 +8,7 @@ import (
"runtime" "runtime"
"time" "time"
"github.com/docker/docker/builder/dockerfile"
"github.com/docker/docker/dockerversion" "github.com/docker/docker/dockerversion"
"github.com/docker/docker/image" "github.com/docker/docker/image"
"github.com/docker/docker/layer" "github.com/docker/docker/layer"
@ -23,13 +24,17 @@ import (
// inConfig (if src is "-"), or from a URI specified in src. Progress output is // inConfig (if src is "-"), or from a URI specified in src. Progress output is
// written to outStream. Repository and tag names can optionally be given in // written to outStream. Repository and tag names can optionally be given in
// the repo and tag arguments, respectively. // the repo and tag arguments, respectively.
func (daemon *Daemon) ImportImage(src string, newRef reference.Named, msg string, inConfig io.ReadCloser, outStream io.Writer, config *container.Config) error { func (daemon *Daemon) ImportImage(src string, newRef reference.Named, msg string, inConfig io.ReadCloser, outStream io.Writer, changes []string) error {
var ( var (
sf = streamformatter.NewJSONStreamFormatter() sf = streamformatter.NewJSONStreamFormatter()
rc io.ReadCloser rc io.ReadCloser
resp *http.Response resp *http.Response
) )
config, err := dockerfile.BuildFromConfig(&container.Config{}, changes)
if err != nil {
return err
}
if src == "-" { if src == "-" {
rc = inConfig rc = inConfig
} else { } else {