From c72f796e177574ee79cc6f8b522542bd5564bdea Mon Sep 17 00:00:00 2001 From: Dan Voiculeasa Date: Sat, 5 Dec 2020 11:43:37 +0200 Subject: [PATCH] Fix incorrect entrypoint for updated image Modify update-stx-image.sh to format the original CMD and ENTRYPOINT as an array of tokens. For example ["token1", "token2"] or [""]. This way `docker commit --change` behaves as expected. Tested on: ORIG_CMD=/bin/bash ORIG_ENTRYPOINT= ORIG_CMD='/bin/bash -c' ORIG_ENTRYPOINT=/bin/bash Change-Id: If6fbe61adf15d9987dfade536a9c886ad1732580 Closes-Bug: 1906914 Signed-off-by: Dan Voiculeasa --- .../build-docker-images/update-stx-image.sh | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/build-tools/build-docker-images/update-stx-image.sh b/build-tools/build-docker-images/update-stx-image.sh index c6f476ed..ff7ea8f7 100755 --- a/build-tools/build-docker-images/update-stx-image.sh +++ b/build-tools/build-docker-images/update-stx-image.sh @@ -442,6 +442,28 @@ fi ORIG_CMD=$(docker inspect --format='{{.Config.Cmd}}' ${FROM} | sed -e 's/^\[//' -e 's/\]$//') ORIG_ENTRYPOINT=$(docker inspect --format='{{.Config.Entrypoint}}' ${FROM} | sed -e 's/^\[//' -e 's/\]$//') +# Format the CMD and ENTRYPOINT to be valid for docker commit change +FORMATTED_ORIG_CMD="" +FORMATTED_ORIG_ENTRYPOINT="" + +for token in ${ORIG_CMD}; do + FORMATTED_ORIG_CMD="${FORMATTED_ORIG_CMD}, \"${token}\"" +done +if [ -z "${FORMATTED_ORIG_CMD}" ]; then + FORMATTED_ORIG_CMD="[\"\"]" +else + FORMATTED_ORIG_CMD="[${FORMATTED_ORIG_CMD:2}]" +fi + +for token in ${ORIG_ENTRYPOINT}; do + FORMATTED_ORIG_ENTRYPOINT="${FORMATTED_ORIG_ENTRYPOINT}, \"${token}\"" +done +if [ -z "${FORMATTED_ORIG_ENTRYPOINT}" ]; then + FORMATTED_ORIG_ENTRYPOINT="[\"\"]" +else + FORMATTED_ORIG_ENTRYPOINT="[${FORMATTED_ORIG_ENTRYPOINT:2}]" +fi + # Get the OS NAME from /etc/os-release OS_NAME=$(docker run --entrypoint /bin/bash --rm ${FROM} -c 'source /etc/os-release && echo ${NAME}') @@ -457,7 +479,7 @@ if [ $? -ne 0 ]; then fi # Commit the updated image -docker commit --change="CMD ${ORIG_CMD}" --change="ENTRYPOINT ${ORIG_ENTRYPOINT}" ${UPDATE_CONTAINER} ${UPDATED_IMAGE} +docker commit --change="CMD ${FORMATTED_ORIG_CMD}" --change="ENTRYPOINT ${FORMATTED_ORIG_ENTRYPOINT}" ${UPDATE_CONTAINER} ${UPDATED_IMAGE} if [ $? -ne 0 ]; then echo "Failed to commit updated image: ${UPDATE_CONTAINER}" >&2 docker rm ${UPDATE_CONTAINER} >/dev/null