Merge pull request #341 from nalind/layerless

CreateContainer: don't worry about mapping layers unless necessary
This commit is contained in:
Daniel J Walsh 2019-05-08 14:21:07 -04:00 committed by GitHub
commit a97b757f6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 58 additions and 23 deletions

View File

@ -148,10 +148,7 @@ func createImage(flags *mflag.FlagSet, action string, m storage.Store, args []st
} }
paramMetadata = string(b) paramMetadata = string(b)
} }
layer := "" layer := args[0]
if len(args) > 0 {
layer = args[0]
}
imageOptions := &storage.ImageOptions{ imageOptions := &storage.ImageOptions{
Digest: digest.Digest(paramDigest), Digest: digest.Digest(paramDigest),
} }
@ -191,7 +188,8 @@ func createContainer(flags *mflag.FlagSet, action string, m storage.Store, args
return 1 return 1
} }
options := &storage.ContainerOptions{IDMappingOptions: *mappings} options := &storage.ContainerOptions{IDMappingOptions: *mappings}
container, err := m.CreateContainer(paramID, paramNames, args[0], paramLayer, paramMetadata, options) image := args[0]
container, err := m.CreateContainer(paramID, paramNames, image, paramLayer, paramMetadata, options)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "%+v\n", err) fmt.Fprintf(os.Stderr, "%+v\n", err)
return 1 return 1
@ -253,7 +251,7 @@ func init() {
names: []string{"create-image", "createimage"}, names: []string{"create-image", "createimage"},
optionsHelp: "[options [...]] topLayerNameOrID", optionsHelp: "[options [...]] topLayerNameOrID",
usage: "Create a new image using layers", usage: "Create a new image using layers",
minArgs: 0, minArgs: 1,
maxArgs: 1, maxArgs: 1,
action: createImage, action: createImage,
addFlags: func(flags *mflag.FlagSet, cmd *command) { addFlags: func(flags *mflag.FlagSet, cmd *command) {

View File

@ -1197,19 +1197,21 @@ func (s *store) CreateContainer(id string, names []string, image, layer, metadat
} }
imageID = cimage.ID imageID = cimage.ID
if cimage.TopLayer != "" {
createMappedLayer := imageHomeStore == istore createMappedLayer := imageHomeStore == istore
ilayer, err := s.imageTopLayerForMapping(cimage, imageHomeStore, createMappedLayer, rlstore, lstores, idMappingsOptions) ilayer, err := s.imageTopLayerForMapping(cimage, imageHomeStore, createMappedLayer, rlstore, lstores, idMappingsOptions)
if err != nil { if err != nil {
return nil, err return nil, err
} }
imageTopLayer = ilayer imageTopLayer = ilayer
if !options.HostUIDMapping && len(options.UIDMap) == 0 { if !options.HostUIDMapping && len(options.UIDMap) == 0 {
uidMap = ilayer.UIDMap uidMap = ilayer.UIDMap
} }
if !options.HostGIDMapping && len(options.GIDMap) == 0 { if !options.HostGIDMapping && len(options.GIDMap) == 0 {
gidMap = ilayer.GIDMap gidMap = ilayer.GIDMap
} }
}
} else { } else {
rlstore.Lock() rlstore.Lock()
defer rlstore.Unlock() defer rlstore.Unlock()

View File

@ -3,6 +3,25 @@
load helpers load helpers
@test "create-container" { @test "create-container" {
# Create a container based on no image.
run storage --debug=false create-container ""
[ "$status" -eq 0 ]
[ "$output" != "" ]
zerothcontainer=${output%% *}
# Create an image using no layer.
run storage --debug=false create-image ""
[ "$status" -eq 0 ]
[ "$output" != "" ]
image=${output%% *}
# Create a container based on that image.
run storage --debug=false create-container $image
echo "$output"
[ "$status" -eq 0 ]
[ "$output" != "" ]
thirdcontainer=${output%% *}
# Create a layer. # Create a layer.
run storage --debug=false create-layer run storage --debug=false create-layer
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
@ -37,8 +56,15 @@ load helpers
run storage --debug=false containers run storage --debug=false containers
echo :"$output": echo :"$output":
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[ "${#lines[*]}" -eq 2 ] [ "${#lines[*]}" -eq 4 ]
[ "${lines[0]}" != "${lines[1]}" ] [ "${lines[0]}" != "${lines[1]}" ]
[ "${lines[0]}" = "$firstcontainer" ] || [ "${lines[0]}" = "$secondcontainer" ] [ "${lines[0]}" != "${lines[2]}" ]
[ "${lines[1]}" = "$firstcontainer" ] || [ "${lines[1]}" = "$secondcontainer" ] [ "${lines[0]}" != "${lines[3]}" ]
[ "${lines[1]}" != "${lines[2]}" ]
[ "${lines[1]}" != "${lines[3]}" ]
[ "${lines[2]}" != "${lines[3]}" ]
[ "${lines[0]}" = "$zerothcontainer" ] || [ "${lines[0]}" = "$firstcontainer" ] || [ "${lines[0]}" = "$secondcontainer" ] || [ "${lines[0]}" = "$thirdcontainer" ]
[ "${lines[1]}" = "$zerothcontainer" ] || [ "${lines[1]}" = "$firstcontainer" ] || [ "${lines[1]}" = "$secondcontainer" ] || [ "${lines[1]}" = "$thirdcontainer" ]
[ "${lines[2]}" = "$zerothcontainer" ] || [ "${lines[2]}" = "$firstcontainer" ] || [ "${lines[2]}" = "$secondcontainer" ] || [ "${lines[2]}" = "$thirdcontainer" ]
[ "${lines[3]}" = "$zerothcontainer" ] || [ "${lines[3]}" = "$firstcontainer" ] || [ "${lines[3]}" = "$secondcontainer" ] || [ "${lines[3]}" = "$thirdcontainer" ]
} }

View File

@ -3,6 +3,12 @@
load helpers load helpers
@test "create-image" { @test "create-image" {
# Create an image using no layer.
run storage --debug=false create-image ""
[ "$status" -eq 0 ]
[ "$output" != "" ]
zerothimage=${output%% *}
# Create a layer. # Create a layer.
run storage --debug=false create-layer run storage --debug=false create-layer
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
@ -31,8 +37,11 @@ load helpers
run storage --debug=false images run storage --debug=false images
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
echo :"$output": echo :"$output":
[ "${#lines[*]}" -eq 2 ] [ "${#lines[*]}" -eq 3 ]
[ "${lines[0]}" != "${lines[1]}" ] [ "${lines[0]}" != "${lines[1]}" ]
[ "${lines[0]}" = "$firstimage" ] || [ "${lines[0]}" = "$secondimage" ] [ "${lines[1]}" != "${lines[2]}" ]
[ "${lines[1]}" = "$firstimage" ] || [ "${lines[1]}" = "$secondimage" ] [ "${lines[0]}" != "${lines[2]}" ]
[ "${lines[0]}" = "$zerothimage" ] || [ "${lines[0]}" = "$firstimage" ] || [ "${lines[0]}" = "$secondimage" ]
[ "${lines[1]}" = "$zerothimage" ] || [ "${lines[1]}" = "$firstimage" ] || [ "${lines[1]}" = "$secondimage" ]
[ "${lines[2]}" = "$zerothimage" ] || [ "${lines[2]}" = "$firstimage" ] || [ "${lines[2]}" = "$secondimage" ]
} }