mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Remove unused image/v1 code
This image format is only used for docker save / docker load. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
14fdd97b69
commit
78095e4d12
2 changed files with 1 additions and 87 deletions
|
@ -2,7 +2,6 @@ package v1 // import "github.com/docker/docker/image/v1"
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/docker/api/types/versions"
|
||||
|
@ -16,7 +15,7 @@ import (
|
|||
// noFallbackMinVersion is the minimum version for which v1compatibility
|
||||
// information will not be marshaled through the Image struct to remove
|
||||
// blank fields.
|
||||
var noFallbackMinVersion = "1.8.3"
|
||||
const noFallbackMinVersion = "1.8.3"
|
||||
|
||||
// HistoryFromConfig creates a History struct from v1 configuration JSON
|
||||
func HistoryFromConfig(imageJSON []byte, emptyLayer bool) (image.History, error) {
|
||||
|
@ -106,36 +105,6 @@ func MakeConfigFromV1Config(imageJSON []byte, rootfs *image.RootFS, history []im
|
|||
return json.Marshal(c)
|
||||
}
|
||||
|
||||
// MakeV1ConfigFromConfig creates a legacy V1 image config from an Image struct
|
||||
func MakeV1ConfigFromConfig(img *image.Image, v1ID, parentV1ID string, throwaway bool) ([]byte, error) {
|
||||
// Top-level v1compatibility string should be a modified version of the
|
||||
// image config.
|
||||
var configAsMap map[string]*json.RawMessage
|
||||
if err := json.Unmarshal(img.RawJSON(), &configAsMap); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Delete fields that didn't exist in old manifest
|
||||
imageType := reflect.TypeOf(img).Elem()
|
||||
for i := 0; i < imageType.NumField(); i++ {
|
||||
f := imageType.Field(i)
|
||||
jsonName := strings.Split(f.Tag.Get("json"), ",")[0]
|
||||
// Parent is handled specially below.
|
||||
if jsonName != "" && jsonName != "parent" {
|
||||
delete(configAsMap, jsonName)
|
||||
}
|
||||
}
|
||||
configAsMap["id"] = rawJSON(v1ID)
|
||||
if parentV1ID != "" {
|
||||
configAsMap["parent"] = rawJSON(parentV1ID)
|
||||
}
|
||||
if throwaway {
|
||||
configAsMap["throwaway"] = rawJSON(true)
|
||||
}
|
||||
|
||||
return json.Marshal(configAsMap)
|
||||
}
|
||||
|
||||
func rawJSON(value interface{}) *json.RawMessage {
|
||||
jsonval, err := json.Marshal(value)
|
||||
if err != nil {
|
||||
|
|
|
@ -1,55 +0,0 @@
|
|||
package v1 // import "github.com/docker/docker/image/v1"
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/image"
|
||||
)
|
||||
|
||||
func TestMakeV1ConfigFromConfig(t *testing.T) {
|
||||
img := &image.Image{
|
||||
V1Image: image.V1Image{
|
||||
ID: "v2id",
|
||||
Parent: "v2parent",
|
||||
OS: "os",
|
||||
},
|
||||
OSVersion: "osversion",
|
||||
RootFS: &image.RootFS{
|
||||
Type: "layers",
|
||||
},
|
||||
}
|
||||
v2js, err := json.Marshal(img)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Convert the image back in order to get RawJSON() support.
|
||||
img, err = image.NewFromJSON(v2js)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
js, err := MakeV1ConfigFromConfig(img, "v1id", "v1parent", false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
newimg := &image.Image{}
|
||||
err = json.Unmarshal(js, newimg)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if newimg.V1Image.ID != "v1id" || newimg.Parent != "v1parent" {
|
||||
t.Error("ids should have changed", newimg.V1Image.ID, newimg.V1Image.Parent)
|
||||
}
|
||||
|
||||
if newimg.RootFS != nil {
|
||||
t.Error("rootfs should have been removed")
|
||||
}
|
||||
|
||||
if newimg.V1Image.OS != "os" {
|
||||
t.Error("os should have been preserved")
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue