Skip to content

Commit

Permalink
Fall back to string for dockerfile parameter
Browse files Browse the repository at this point in the history
a9cb824 changed the expectations of the
dockerfile parameter to be json data however it's a string. In order to
support both, let's attempt json and fall back to a string if the json
parsing fails.

Closes containers#10660

Signed-off-by: Alex Schultz <[email protected]>
  • Loading branch information
mwhahaha committed Jun 11, 2021
1 parent a634b2c commit ded2f00
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/api/handlers/compat/images_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
if _, found := r.URL.Query()["dockerfile"]; found {
var m = []string{}
if err := json.Unmarshal([]byte(query.Dockerfile), &m); err != nil {
utils.BadRequest(w, "dockerfile", query.Dockerfile, err)
return
// it's not json, assume just a string
m = append(m, query.Dockerfile)
}
containerFiles = m
} else {
Expand Down
35 changes: 35 additions & 0 deletions test/apiv2/10-images.at
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,39 @@ t GET "images/get?names=alpine&names=busybox" 200 '[POSIX tar archive]'
img_cnt=$(tar xf "$WORKDIR/curl.result.out" manifest.json -O | jq "length")
is "$img_cnt" 2 "number of images in tar archive"

# check build works when uploading container file as a tar, see issue #10660
TMPD=$(mktemp -d podman-apiv2-test.build.XXXXXXXX)
function cleanBuildTest() {
podman rmi -a -f
rm -rf "${TMPD}" &> /dev/null
}
CONTAINERFILE_TAR="${TMPD}/containerfile.tar"
cat > $TMPD/containerfile << EOF
FROM quay.io/libpod/alpine_labels:latest
EOF
tar --format=posix -C $TMPD -cvf ${CONTAINERFILE_TAR} containerfile &> /dev/null

curl -XPOST --data-binary @<(cat $CONTAINERFILE_TAR) \
-H "content-type: application/x-tar" \
--dump-header "${TMPD}/headers.txt" \
-o "${TMPD}/response.txt" \
"http://$HOST:$PORT/v1.40/libpod/build?dockerfile=containerfile" &> /dev/null

BUILD_TEST_ERROR=""

if ! grep -q '200 OK' "${TMPD}/headers.txt"; then
echo -e "${red}NOK: Image build from tar failed response was not 200 OK"
BUILD_TEST_ERROR="1"
fi

if ! grep -q 'quay.io/libpod/alpine_labels' "${TMPD}/response.txt"; then
echo -e "${red}NOK: Image build from tar failed image name not in response"
BUILD_TEST_ERROR="1"
fi

cleanBuildTest
if [[ "${BUILD_TEST_ERROR}" ]]; then
exit 1
fi

# vim: filetype=sh

0 comments on commit ded2f00

Please sign in to comment.