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

Remove API codepaths < 1.12

Signed-off-by: Antonio Murdaca <me@runcom.ninja>
This commit is contained in:
Antonio Murdaca 2015-05-11 23:53:52 +02:00
parent c9821d8dd6
commit 7284b08204
10 changed files with 64 additions and 220 deletions

View file

@ -353,28 +353,7 @@ func (s *Server) getImagesJSON(version version.Version, w http.ResponseWriter, r
return err
}
if version.GreaterThanOrEqualTo("1.7") {
return writeJSON(w, http.StatusOK, images)
}
legacyImages := []types.LegacyImage{}
for _, image := range images {
for _, repoTag := range image.RepoTags {
repo, tag := parsers.ParseRepositoryTag(repoTag)
legacyImage := types.LegacyImage{
Repository: repo,
Tag: tag,
ID: image.ID,
Created: image.Created,
Size: image.Size,
VirtualSize: image.VirtualSize,
}
legacyImages = append(legacyImages, legacyImage)
}
}
return writeJSON(w, http.StatusOK, legacyImages)
return writeJSON(w, http.StatusOK, images)
}
func (s *Server) getInfo(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
@ -520,10 +499,6 @@ func (s *Server) getContainersChanges(version version.Version, w http.ResponseWr
}
func (s *Server) getContainersTop(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
if version.LessThan("1.4") {
return fmt.Errorf("top was improved a lot since 1.3, Please upgrade your docker client.")
}
if vars == nil {
return fmt.Errorf("Missing parameter")
}
@ -706,14 +681,11 @@ func (s *Server) postImagesCreate(version version.Version, w http.ResponseWriter
}
var (
err error
useJSON = version.GreaterThan("1.0")
output = ioutils.NewWriteFlusher(w)
err error
output = ioutils.NewWriteFlusher(w)
)
if useJSON {
w.Header().Set("Content-Type", "application/json")
}
w.Header().Set("Content-Type", "application/json")
if image != "" { //pull
if tag == "" {
@ -727,15 +699,12 @@ func (s *Server) postImagesCreate(version version.Version, w http.ResponseWriter
}
imagePullConfig := &graph.ImagePullConfig{
Parallel: version.GreaterThan("1.3"),
MetaHeaders: metaHeaders,
AuthConfig: authConfig,
OutStream: output,
Json: useJSON,
}
err = s.daemon.Repositories().Pull(image, tag, imagePullConfig)
} else { //import
if tag == "" {
repo, tag = parsers.ParseRepositoryTag(repo)
@ -746,7 +715,6 @@ func (s *Server) postImagesCreate(version version.Version, w http.ResponseWriter
Changes: r.Form["changes"],
InConfig: r.Body,
OutStream: output,
Json: useJSON,
}
newConfig, err := builder.BuildFromConfig(s.daemon, &runconfig.Config{}, imageImportConfig.Changes)
@ -762,7 +730,7 @@ func (s *Server) postImagesCreate(version version.Version, w http.ResponseWriter
if !output.Flushed() {
return err
}
sf := streamformatter.NewStreamFormatter(useJSON)
sf := streamformatter.NewStreamFormatter(true)
output.Write(sf.FormatError(err))
}
@ -831,26 +799,22 @@ func (s *Server) postImagesPush(version version.Version, w http.ResponseWriter,
}
}
useJSON := version.GreaterThan("1.0")
name := vars["name"]
output := ioutils.NewWriteFlusher(w)
imagePushConfig := &graph.ImagePushConfig{
MetaHeaders: metaHeaders,
AuthConfig: authConfig,
Tag: r.Form.Get("tag"),
OutStream: output,
Json: useJSON,
}
if useJSON {
w.Header().Set("Content-Type", "application/json")
}
w.Header().Set("Content-Type", "application/json")
if err := s.daemon.Repositories().Push(name, imagePushConfig); err != nil {
if !output.Flushed() {
return err
}
sf := streamformatter.NewStreamFormatter(useJSON)
sf := streamformatter.NewStreamFormatter(true)
output.Write(sf.FormatError(err))
}
return nil
@ -865,10 +829,7 @@ func (s *Server) getImagesGet(version version.Version, w http.ResponseWriter, r
return err
}
useJSON := version.GreaterThan("1.0")
if useJSON {
w.Header().Set("Content-Type", "application/x-tar")
}
w.Header().Set("Content-Type", "application/x-tar")
output := ioutils.NewWriteFlusher(w)
imageExportConfig := &graph.ImageExportConfig{Outstream: output}
@ -882,7 +843,7 @@ func (s *Server) getImagesGet(version version.Version, w http.ResponseWriter, r
if !output.Flushed() {
return err
}
sf := streamformatter.NewStreamFormatter(useJSON)
sf := streamformatter.NewStreamFormatter(true)
output.Write(sf.FormatError(err))
}
return nil
@ -1169,16 +1130,7 @@ func (s *Server) getContainersByName(version version.Version, w http.ResponseWri
return fmt.Errorf("Missing parameter")
}
name := vars["name"]
if version.LessThan("1.12") {
containerJSONRaw, err := s.daemon.ContainerInspectRaw(name)
if err != nil {
return err
}
return writeJSON(w, http.StatusOK, containerJSONRaw)
}
containerJSON, err := s.daemon.ContainerInspect(name)
containerJSON, err := s.daemon.ContainerInspect(vars["name"])
if err != nil {
return err
}
@ -1203,17 +1155,7 @@ func (s *Server) getImagesByName(version version.Version, w http.ResponseWriter,
return fmt.Errorf("Missing parameter")
}
name := vars["name"]
if version.LessThan("1.12") {
imageInspectRaw, err := s.daemon.Repositories().LookupRaw(name)
if err != nil {
return err
}
return writeJSON(w, http.StatusOK, imageInspectRaw)
}
imageInspect, err := s.daemon.Repositories().Lookup(name)
imageInspect, err := s.daemon.Repositories().Lookup(vars["name"])
if err != nil {
return err
}
@ -1222,30 +1164,13 @@ func (s *Server) getImagesByName(version version.Version, w http.ResponseWriter,
}
func (s *Server) postBuild(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
if version.LessThan("1.3") {
return fmt.Errorf("Multipart upload for build is no longer supported. Please upgrade your docker client.")
}
var (
authEncoded = r.Header.Get("X-Registry-Auth")
authConfig = &cliconfig.AuthConfig{}
configFileEncoded = r.Header.Get("X-Registry-Config")
configFile = &cliconfig.ConfigFile{}
buildConfig = builder.NewBuildConfig()
)
// This block can be removed when API versions prior to 1.9 are deprecated.
// Both headers will be parsed and sent along to the daemon, but if a non-empty
// ConfigFile is present, any value provided as an AuthConfig directly will
// be overridden. See BuildFile::CmdFrom for details.
if version.LessThan("1.9") && authEncoded != "" {
authJson := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authEncoded))
if err := json.NewDecoder(authJson).Decode(authConfig); err != nil {
// for a pull it is not an error if no auth was given
// to increase compatibility with the existing api it is defaulting to be empty
authConfig = &cliconfig.AuthConfig{}
}
}
if configFileEncoded != "" {
configFileJson := base64.NewDecoder(base64.URLEncoding, strings.NewReader(configFileEncoded))
if err := json.NewDecoder(configFileJson).Decode(configFile); err != nil {
@ -1255,10 +1180,7 @@ func (s *Server) postBuild(version version.Version, w http.ResponseWriter, r *ht
}
}
if version.GreaterThanOrEqualTo("1.8") {
w.Header().Set("Content-Type", "application/json")
buildConfig.JSONFormat = true
}
w.Header().Set("Content-Type", "application/json")
if boolValue(r, "forcerm") && version.GreaterThanOrEqualTo("1.12") {
buildConfig.Remove = true
@ -1312,7 +1234,7 @@ func (s *Server) postBuild(version version.Version, w http.ResponseWriter, r *ht
if !output.Flushed() {
return err
}
sf := streamformatter.NewStreamFormatter(version.GreaterThanOrEqualTo("1.8"))
sf := streamformatter.NewStreamFormatter(true)
w.Write(sf.FormatError(err))
}
return nil
@ -1418,12 +1340,11 @@ func (s *Server) postContainerExecStart(version version.Version, w http.Response
fmt.Fprintf(outStream, "HTTP/1.1 200 OK\r\nContent-Type: application/vnd.docker.raw-stream\r\n\r\n")
}
if !execStartCheck.Tty && version.GreaterThanOrEqualTo("1.6") {
if !execStartCheck.Tty {
errStream = stdcopy.NewStdWriter(outStream, stdcopy.Stderr)
outStream = stdcopy.NewStdWriter(outStream, stdcopy.Stdout)
} else {
errStream = outStream
}
stdin = inStream
stdout = outStream
stderr = errStream

View file

@ -92,15 +92,6 @@ type ImageInspect struct {
VirtualSize int64
}
type LegacyImage struct {
ID string `json:"Id"`
Repository string
Tag string
Created int
Size int
VirtualSize int
}
// GET "/containers/json"
type Port struct {
IP string

View file

@ -458,10 +458,8 @@ func (b *Builder) pullImage(name string) (*imagepkg.Image, error) {
}
imagePullConfig := &graph.ImagePullConfig{
Parallel: true,
AuthConfig: pullRegistryAuth,
OutStream: ioutils.NopWriteCloser(b.OutOld),
Json: b.StreamFormatter.Json(),
}
if err := b.Daemon.Repositories().Pull(remote, tag, imagePullConfig); err != nil {

View file

@ -45,7 +45,6 @@ type Config struct {
Remove bool
ForceRemove bool
Pull bool
JSONFormat bool
Memory int64
MemorySwap int64
CpuShares int64
@ -142,7 +141,7 @@ func Build(d *daemon.Daemon, buildConfig *Config) error {
}
defer context.Close()
sf := streamformatter.NewStreamFormatter(buildConfig.JSONFormat)
sf := streamformatter.NewStreamFormatter(true)
builder := &Builder{
Daemon: d,

View file

@ -12,18 +12,6 @@ type ContainerJSONRaw struct {
HostConfig *runconfig.HostConfig
}
func (daemon *Daemon) ContainerInspectRaw(name string) (*ContainerJSONRaw, error) {
container, err := daemon.Get(name)
if err != nil {
return nil, err
}
container.Lock()
defer container.Unlock()
return &ContainerJSONRaw{container, container.hostConfig}, nil
}
func (daemon *Daemon) ContainerInspect(name string) (*types.ContainerJSON, error) {
container, err := daemon.Get(name)
if err != nil {

View file

@ -16,14 +16,13 @@ import (
type ImageImportConfig struct {
Changes []string
InConfig io.ReadCloser
Json bool
OutStream io.Writer
ContainerConfig *runconfig.Config
}
func (s *TagStore) Import(src string, repo string, tag string, imageImportConfig *ImageImportConfig) error {
var (
sf = streamformatter.NewStreamFormatter(imageImportConfig.Json)
sf = streamformatter.NewStreamFormatter(true)
archive archive.ArchiveReader
resp *http.Response
)

View file

@ -22,16 +22,14 @@ import (
)
type ImagePullConfig struct {
Parallel bool
MetaHeaders map[string][]string
AuthConfig *cliconfig.AuthConfig
Json bool
OutStream io.Writer
}
func (s *TagStore) Pull(image string, tag string, imagePullConfig *ImagePullConfig) error {
var (
sf = streamformatter.NewStreamFormatter(imagePullConfig.Json)
sf = streamformatter.NewStreamFormatter(true)
)
// Resolve the Repository name from fqn to RepositoryInfo
@ -78,7 +76,7 @@ func (s *TagStore) Pull(image string, tag string, imagePullConfig *ImagePullConf
}
logrus.Debugf("pulling v2 repository with local name %q", repoInfo.LocalName)
if err := s.pullV2Repository(r, imagePullConfig.OutStream, repoInfo, tag, sf, imagePullConfig.Parallel); err == nil {
if err := s.pullV2Repository(r, imagePullConfig.OutStream, repoInfo, tag, sf); err == nil {
s.eventsService.Log("pull", logName, "")
return nil
} else if err != registry.ErrDoesNotExist && err != ErrV2RegistryUnavailable {
@ -89,7 +87,7 @@ func (s *TagStore) Pull(image string, tag string, imagePullConfig *ImagePullConf
}
logrus.Debugf("pulling v1 repository with local name %q", repoInfo.LocalName)
if err = s.pullRepository(r, imagePullConfig.OutStream, repoInfo, tag, sf, imagePullConfig.Parallel); err != nil {
if err = s.pullRepository(r, imagePullConfig.OutStream, repoInfo, tag, sf); err != nil {
return err
}
@ -98,7 +96,7 @@ func (s *TagStore) Pull(image string, tag string, imagePullConfig *ImagePullConf
return nil
}
func (s *TagStore) pullRepository(r *registry.Session, out io.Writer, repoInfo *registry.RepositoryInfo, askedTag string, sf *streamformatter.StreamFormatter, parallel bool) error {
func (s *TagStore) pullRepository(r *registry.Session, out io.Writer, repoInfo *registry.RepositoryInfo, askedTag string, sf *streamformatter.StreamFormatter) error {
out.Write(sf.FormatStatus("", "Pulling repository %s", repoInfo.CanonicalName))
repoData, err := r.GetRepositoryData(repoInfo.RemoteName)
@ -146,17 +144,13 @@ func (s *TagStore) pullRepository(r *registry.Session, out io.Writer, repoInfo *
for _, image := range repoData.ImgList {
downloadImage := func(img *registry.ImgData) {
if askedTag != "" && img.Tag != askedTag {
if parallel {
errors <- nil
}
errors <- nil
return
}
if img.Tag == "" {
logrus.Debugf("Image (id: %s) present in this repository but untagged, skipping", img.ID)
if parallel {
errors <- nil
}
errors <- nil
return
}
@ -169,9 +163,7 @@ func (s *TagStore) pullRepository(r *registry.Session, out io.Writer, repoInfo *
} else {
logrus.Debugf("Image (id: %s) pull is already running, skipping: %v", img.ID, err)
}
if parallel {
errors <- nil
}
errors <- nil
return
}
defer s.poolRemove("pull", "img:"+img.ID)
@ -209,36 +201,27 @@ func (s *TagStore) pullRepository(r *registry.Session, out io.Writer, repoInfo *
if !success {
err := fmt.Errorf("Error pulling image (%s) from %s, %v", img.Tag, repoInfo.CanonicalName, lastErr)
out.Write(sf.FormatProgress(stringid.TruncateID(img.ID), err.Error(), nil))
if parallel {
errors <- err
return
}
errors <- err
return
}
out.Write(sf.FormatProgress(stringid.TruncateID(img.ID), "Download complete", nil))
if parallel {
errors <- nil
}
errors <- nil
}
if parallel {
go downloadImage(image)
} else {
downloadImage(image)
}
go downloadImage(image)
}
if parallel {
var lastError error
for i := 0; i < len(repoData.ImgList); i++ {
if err := <-errors; err != nil {
lastError = err
}
}
if lastError != nil {
return lastError
}
var lastError error
for i := 0; i < len(repoData.ImgList); i++ {
if err := <-errors; err != nil {
lastError = err
}
}
if lastError != nil {
return lastError
}
for tag, id := range tagsList {
if askedTag != "" && tag != askedTag {
continue
@ -373,7 +356,7 @@ type downloadInfo struct {
err chan error
}
func (s *TagStore) pullV2Repository(r *registry.Session, out io.Writer, repoInfo *registry.RepositoryInfo, tag string, sf *streamformatter.StreamFormatter, parallel bool) error {
func (s *TagStore) pullV2Repository(r *registry.Session, out io.Writer, repoInfo *registry.RepositoryInfo, tag string, sf *streamformatter.StreamFormatter) error {
endpoint, err := r.V2RegistryEndpoint(repoInfo.Index)
if err != nil {
if repoInfo.Index.Official {
@ -397,14 +380,14 @@ func (s *TagStore) pullV2Repository(r *registry.Session, out io.Writer, repoInfo
return registry.ErrDoesNotExist
}
for _, t := range tags {
if downloaded, err := s.pullV2Tag(r, out, endpoint, repoInfo, t, sf, parallel, auth); err != nil {
if downloaded, err := s.pullV2Tag(r, out, endpoint, repoInfo, t, sf, auth); err != nil {
return err
} else if downloaded {
layersDownloaded = true
}
}
} else {
if downloaded, err := s.pullV2Tag(r, out, endpoint, repoInfo, tag, sf, parallel, auth); err != nil {
if downloaded, err := s.pullV2Tag(r, out, endpoint, repoInfo, tag, sf, auth); err != nil {
return err
} else if downloaded {
layersDownloaded = true
@ -419,7 +402,7 @@ func (s *TagStore) pullV2Repository(r *registry.Session, out io.Writer, repoInfo
return nil
}
func (s *TagStore) pullV2Tag(r *registry.Session, out io.Writer, endpoint *registry.Endpoint, repoInfo *registry.RepositoryInfo, tag string, sf *streamformatter.StreamFormatter, parallel bool, auth *registry.RequestAuthorization) (bool, error) {
func (s *TagStore) pullV2Tag(r *registry.Session, out io.Writer, endpoint *registry.Endpoint, repoInfo *registry.RepositoryInfo, tag string, sf *streamformatter.StreamFormatter, auth *registry.RequestAuthorization) (bool, error) {
logrus.Debugf("Pulling tag from V2 registry: %q", tag)
manifestBytes, manifestDigest, err := r.GetV2ImageManifest(endpoint, repoInfo.RemoteName, tag, auth)
@ -531,16 +514,10 @@ func (s *TagStore) pullV2Tag(r *registry.Session, out io.Writer, endpoint *regis
return nil
}
if parallel {
downloads[i].err = make(chan error)
go func(di *downloadInfo) {
di.err <- downloadFunc(di)
}(&downloads[i])
} else {
if err := downloadFunc(&downloads[i]); err != nil {
return false, err
}
}
downloads[i].err = make(chan error)
go func(di *downloadInfo) {
di.err <- downloadFunc(di)
}(&downloads[i])
}
var tagUpdated bool

View file

@ -30,7 +30,6 @@ type ImagePushConfig struct {
MetaHeaders map[string][]string
AuthConfig *cliconfig.AuthConfig
Tag string
Json bool
OutStream io.Writer
}
@ -496,7 +495,7 @@ func (s *TagStore) pushV2Image(r *registry.Session, img *image.Image, endpoint *
// FIXME: Allow to interrupt current push when new push of same image is done.
func (s *TagStore) Push(localName string, imagePushConfig *ImagePushConfig) error {
var (
sf = streamformatter.NewStreamFormatter(imagePushConfig.Json)
sf = streamformatter.NewStreamFormatter(true)
)
// Resolve the Repository name from fqn to RepositoryInfo

View file

@ -11,21 +11,6 @@ import (
"github.com/go-check/check"
)
func (s *DockerSuite) TestLegacyImages(c *check.C) {
status, body, err := sockRequest("GET", "/v1.6/images/json", nil)
c.Assert(status, check.Equals, http.StatusOK)
c.Assert(err, check.IsNil)
images := []types.LegacyImage{}
if err = json.Unmarshal(body, &images); err != nil {
c.Fatalf("Error on unmarshal: %s", err)
}
if len(images) == 0 || images[0].Tag == "" || images[0].Repository == "" {
c.Fatalf("Bad data: %q", images)
}
}
func (s *DockerSuite) TestApiImagesFilter(c *check.C) {
name := "utest:tag1"
name2 := "utest/docker:tag2"

View file

@ -18,40 +18,27 @@ func (s *DockerSuite) TestInspectApiContainerResponse(c *check.C) {
cleanedContainerID := strings.TrimSpace(out)
// test on json marshal version
// and latest version
testVersions := []string{"v1.11", "latest"}
endpoint := "/containers/" + cleanedContainerID + "/json"
status, body, err := sockRequest("GET", endpoint, nil)
c.Assert(status, check.Equals, http.StatusOK)
c.Assert(err, check.IsNil)
for _, testVersion := range testVersions {
endpoint := "/containers/" + cleanedContainerID + "/json"
if testVersion != "latest" {
endpoint = "/" + testVersion + endpoint
}
status, body, err := sockRequest("GET", endpoint, nil)
c.Assert(status, check.Equals, http.StatusOK)
c.Assert(err, check.IsNil)
var inspectJSON map[string]interface{}
if err = json.Unmarshal(body, &inspectJSON); err != nil {
c.Fatalf("unable to unmarshal body for latest version: %v", err)
}
var inspectJSON map[string]interface{}
if err = json.Unmarshal(body, &inspectJSON); err != nil {
c.Fatalf("unable to unmarshal body for %s version: %v", testVersion, err)
}
keys := []string{"State", "Created", "Path", "Args", "Config", "Image", "NetworkSettings", "ResolvConfPath", "HostnamePath", "HostsPath", "LogPath", "Name", "Driver", "ExecDriver", "MountLabel", "ProcessLabel", "Volumes", "VolumesRW"}
keys := []string{"State", "Created", "Path", "Args", "Config", "Image", "NetworkSettings", "ResolvConfPath", "HostnamePath", "HostsPath", "LogPath", "Name", "Driver", "ExecDriver", "MountLabel", "ProcessLabel", "Volumes", "VolumesRW"}
keys = append(keys, "Id")
if testVersion == "v1.11" {
keys = append(keys, "ID")
} else {
keys = append(keys, "Id")
}
for _, key := range keys {
if _, ok := inspectJSON[key]; !ok {
c.Fatalf("%s does not exist in response for %s version", key, testVersion)
}
}
//Issue #6830: type not properly converted to JSON/back
if _, ok := inspectJSON["Path"].(bool); ok {
c.Fatalf("Path of `true` should not be converted to boolean `true` via JSON marshalling")
for _, key := range keys {
if _, ok := inspectJSON[key]; !ok {
c.Fatalf("%s does not exist in response for latest version", key)
}
}
//Issue #6830: type not properly converted to JSON/back
if _, ok := inspectJSON["Path"].(bool); ok {
c.Fatalf("Path of `true` should not be converted to boolean `true` via JSON marshalling")
}
}