Merge pull request #348 from runcom/fix-imageid-lookup

storage: fix image retrieval by id
This commit is contained in:
Mrunal Patel 2017-02-01 09:05:36 -08:00 committed by GitHub
commit d0464b11e2
5 changed files with 105 additions and 3 deletions

View file

@ -167,7 +167,11 @@ func (r *runtimeService) createContainerOrPodSandbox(systemContext *types.System
ref, err = istorage.Transport.ParseStoreReference(r.image.GetStore(), otherRef.DockerReference().FullName()) ref, err = istorage.Transport.ParseStoreReference(r.image.GetStore(), otherRef.DockerReference().FullName())
} }
if err != nil { if err != nil {
return ContainerInfo{}, err // maybe it's just imageID
ref, err = istorage.Transport.ParseStoreReference(r.image.GetStore(), "@"+imageID)
if err != nil {
return ContainerInfo{}, err
}
} }
} }
img, err := istorage.Transport.GetStoreImage(r.image.GetStore(), ref) img, err := istorage.Transport.GetStoreImage(r.image.GetStore(), ref)

View file

@ -350,7 +350,7 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string,
attempt := metadata.GetAttempt() attempt := metadata.GetAttempt()
containerInfo, err := s.storage.CreateContainer(s.imageContext, containerInfo, err := s.storage.CreateContainer(s.imageContext,
sb.name, sb.id, sb.name, sb.id,
image, "", image, image,
containerName, containerID, containerName, containerID,
metaname, metaname,
attempt, attempt,

View file

@ -142,8 +142,9 @@ function start_ocid() {
run ocic image status --id=redis run ocic image status --id=redis
if [ "$status" -ne 0 ] ; then if [ "$status" -ne 0 ] ; then
ocic image pull docker://redis:latest ocic image pull redis:latest
fi fi
REDIS_IMAGEID=$(ocic image status --id=redis | head -1 | sed -e "s/ID: //g")
} }
function cleanup_ctrs() { function cleanup_ctrs() {

View file

@ -8,6 +8,21 @@ function teardown() {
cleanup_test cleanup_test
} }
@test "run container in pod with image ID" {
start_ocid
run ocic pod run --config "$TESTDATA"/sandbox_config.json
echo "$output"
[ "$status" -eq 0 ]
pod_id="$output"
sed -e "s/%VALUE%/$REDIS_IMAGEID/g" "$TESTDATA"/container_config_by_imageid.json > "$TESTDIR"/ctr_by_imageid.json
run ocic ctr create --config "$TESTDIR"/ctr_by_imageid.json --pod "$pod_id"
echo "$output"
[ "$status" -eq 0 ]
cleanup_ctrs
cleanup_pods
stop_ocid
}
@test "image pull" { @test "image pull" {
start_ocid "" "" --no-pause-image start_ocid "" "" --no-pause-image
run ocic image pull "$IMAGE" run ocic image pull "$IMAGE"

View file

@ -0,0 +1,82 @@
{
"metadata": {
"name": "container1",
"attempt": 1
},
"image": {
"image": "%VALUE%"
},
"command": [
"/bin/bash"
],
"args": [
"/bin/ls"
],
"working_dir": "/",
"envs": [
{
"key": "PATH",
"value": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
},
{
"key": "TERM",
"value": "xterm"
},
{
"key": "TESTDIR",
"value": "test/dir1"
},
{
"key": "TESTFILE",
"value": "test/file1"
}
],
"labels": {
"type": "small",
"batch": "no"
},
"annotations": {
"owner": "dragon",
"daemon": "ocid"
},
"privileged": true,
"readonly_rootfs": true,
"log_path": "container.log",
"stdin": false,
"stdin_once": false,
"tty": false,
"linux": {
"resources": {
"cpu_period": 10000,
"cpu_quota": 20000,
"cpu_shares": 512,
"memory_limit_in_bytes": 88000000,
"oom_score_adj": 30
},
"capabilities": {
"add_capabilities": [
"setuid",
"setgid"
],
"drop_capabilities": [
"audit_write",
"audit_read"
]
},
"selinux_options": {
"user": "system_u",
"role": "system_r",
"type": "container_t",
"level": "s0:c4,c5"
},
"user": {
"uid": 5,
"gid": 300,
"additional_gids": [
400,
401,
402
]
}
}
}