diff --git a/pkg/storage/runtime.go b/pkg/storage/runtime.go index 08c451f5..85b03145 100644 --- a/pkg/storage/runtime.go +++ b/pkg/storage/runtime.go @@ -167,7 +167,11 @@ func (r *runtimeService) createContainerOrPodSandbox(systemContext *types.System ref, err = istorage.Transport.ParseStoreReference(r.image.GetStore(), otherRef.DockerReference().FullName()) } 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) diff --git a/server/container_create.go b/server/container_create.go index e4354607..722ad21c 100644 --- a/server/container_create.go +++ b/server/container_create.go @@ -350,7 +350,7 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string, attempt := metadata.GetAttempt() containerInfo, err := s.storage.CreateContainer(s.imageContext, sb.name, sb.id, - image, "", + image, image, containerName, containerID, metaname, attempt, diff --git a/test/helpers.bash b/test/helpers.bash index 33d66d65..c9a97ae3 100644 --- a/test/helpers.bash +++ b/test/helpers.bash @@ -142,8 +142,9 @@ function start_ocid() { run ocic image status --id=redis if [ "$status" -ne 0 ] ; then - ocic image pull docker://redis:latest + ocic image pull redis:latest fi + REDIS_IMAGEID=$(ocic image status --id=redis | head -1 | sed -e "s/ID: //g") } function cleanup_ctrs() { diff --git a/test/image.bats b/test/image.bats index 88b2ac73..f571ac3c 100644 --- a/test/image.bats +++ b/test/image.bats @@ -8,6 +8,21 @@ function teardown() { 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" { start_ocid "" "" --no-pause-image run ocic image pull "$IMAGE" diff --git a/test/testdata/container_config_by_imageid.json b/test/testdata/container_config_by_imageid.json new file mode 100644 index 00000000..6cfb3556 --- /dev/null +++ b/test/testdata/container_config_by_imageid.json @@ -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 + ] + } + } +}