Skip to content

Commit

Permalink
fix: The container created by APIV2 has an incorrect Env and WorkDir
Browse files Browse the repository at this point in the history
Signed-off-by: zhangguanzhang <[email protected]>
  • Loading branch information
zhangguanzhang authored and mheon committed Oct 14, 2020
1 parent 9de593a commit eb39ac7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
13 changes: 12 additions & 1 deletion pkg/api/handlers/compat/containers_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,13 @@ func makeCreateConfig(ctx context.Context, containerConfig *config.Config, input
}
}

workDir := "/"
workDir, err := newImage.WorkingDir(ctx)
if err != nil {
return createconfig.CreateConfig{}, err
}
if workDir == "" {
workDir = "/"
}
if len(input.WorkingDir) > 0 {
workDir = input.WorkingDir
}
Expand Down Expand Up @@ -169,6 +175,11 @@ func makeCreateConfig(ctx context.Context, containerConfig *config.Config, input
// away incorrectly formatted variables so we cannot reuse the
// parsing of the env input
// [Foo Other=one Blank=]
imgEnv, err := newImage.Env(ctx)
if err != nil {
return createconfig.CreateConfig{}, err
}
input.Env = append(imgEnv, input.Env...)
for _, e := range input.Env {
splitEnv := strings.Split(e, "=")
switch len(splitEnv) {
Expand Down
23 changes: 22 additions & 1 deletion test/apiv2/20-containers.at
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
# test container-related endpoints
#

podman pull $IMAGE &>/dev/null
# WORKDIR=/data
ENV_WORKDIR_IMG=docker.io/library/redis:alpine

podman pull $IMAGE &>/dev/null
podman pull $ENV_WORKDIR_IMG &>/dev/null
# Unimplemented
#t POST libpod/containers/create '' 201 'sdf'

Expand Down Expand Up @@ -203,4 +206,22 @@ t POST containers/${cid_top}/stop "" 204
t DELETE containers/$cid 204
t DELETE containers/$cid_top 204

# test the apiv2 create, should't ignore the ENV and WORKDIR from the image
t POST containers/create '"Image":"'$ENV_WORKDIR_IMG'","Env":["testKey1"]' 201 \
.Id~[0-9a-f]\\{64\\}
cid=$(jq -r '.Id' <<<"$output")
t GET containers/$cid/json 200 \
.Config.Env~"REDIS_VERSION=" \
.Config.Env~"testEnv1=" \
.Config.WorkingDir="/data" # default is /data
t DELETE containers/$cid 204

# test the WORKDIR
t POST containers/create '"Image":"'$ENV_WORKDIR_IMG'","WorkingDir":"/dataDir"' 201 \
.Id~[0-9a-f]\\{64\\}
cid=$(jq -r '.Id' <<<"$output")
t GET containers/$cid/json 200 \
.Config.WorkingDir="/dataDir"
t DELETE containers/$cid 204

# vim: filetype=sh

0 comments on commit eb39ac7

Please sign in to comment.