Skip to content

Commit

Permalink
Fix docker executable not being quoted in shell script templates
Browse files Browse the repository at this point in the history
  • Loading branch information
gudmundur-heimisson authored and uhthomas committed Aug 29, 2022
1 parent 94a7ddb commit c823a69
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 42 deletions.
12 changes: 6 additions & 6 deletions contrib/automatic_container_release/run_checker.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ if [[ -z "$DOCKER" ]]; then
fi

# Create a new docker container that will run the checker.
container_id=$($DOCKER $DOCKER_FLAGS create %{image_name} %{cmd_args})
container_id=$("$DOCKER" $DOCKER_FLAGS create %{image_name} %{cmd_args})

specs=(%{specs})
spec_container_paths=(%{spec_container_paths})
Expand All @@ -60,20 +60,20 @@ if [ ${#specs[@]} -ne ${#spec_container_paths[@]} ]; then
exit 1
fi
for ((i=0;i<${#specs[@]};i++)); do
$DOCKER $DOCKER_FLAGS cp -L ${specs[$i]} $container_id:${spec_container_paths[$i]}
"$DOCKER" $DOCKER_FLAGS cp -L ${specs[$i]} $container_id:${spec_container_paths[$i]}
done

# Start the container that will run the checker logic.
$DOCKER $DOCKER_FLAGS start $container_id
"$DOCKER" $DOCKER_FLAGS start $container_id

# Wait for the checker to finish running.
retcode=$($DOCKER $DOCKER_FLAGS wait $container_id)
retcode=$("$DOCKER" $DOCKER_FLAGS wait $container_id)

# Print all logs generated by the container.
$DOCKER $DOCKER_FLAGS logs $container_id
"$DOCKER" $DOCKER_FLAGS logs $container_id

# Delete the container.
$DOCKER $DOCKER_FLAGS rm $container_id
"$DOCKER" $DOCKER_FLAGS rm $container_id

exit $retcode

12 changes: 6 additions & 6 deletions docker/package_managers/run_download.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ fi

# Load the image and remember its name
image_id=$(%{image_id_extractor_path} %{image_tar})
$DOCKER $DOCKER_FLAGS load -i %{image_tar}
"$DOCKER" $DOCKER_FLAGS load -i %{image_tar}

# Run the builder image.
cid=$($DOCKER $DOCKER_FLAGS run -w="/" -d --privileged $image_id sh -c $'%{download_commands}')
$DOCKER $DOCKER_FLAGS attach $cid
$DOCKER $DOCKER_FLAGS cp $cid:%{installables}_packages.tar %{output}
$DOCKER $DOCKER_FLAGS cp $cid:%{installables}_metadata.csv %{output_metadata}
cid=$("$DOCKER" $DOCKER_FLAGS run -w="/" -d --privileged $image_id sh -c $'%{download_commands}')
"$DOCKER" $DOCKER_FLAGS attach $cid
"$DOCKER" $DOCKER_FLAGS cp $cid:%{installables}_packages.tar %{output}
"$DOCKER" $DOCKER_FLAGS cp $cid:%{installables}_metadata.csv %{output_metadata}
# Cleanup
$DOCKER $DOCKER_FLAGS rm $cid
"$DOCKER" $DOCKER_FLAGS rm $cid
20 changes: 10 additions & 10 deletions docker/package_managers/run_install.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ source %{util_script}

# Load the image and remember its name
image_id=$(%{image_id_extractor_path} %{base_image_tar})
$DOCKER $DOCKER_FLAGS load -i %{base_image_tar}
"$DOCKER" $DOCKER_FLAGS load -i %{base_image_tar}

# Create a docker volume containing the installer script and the
# installables TAR file.
Expand Down Expand Up @@ -44,21 +44,21 @@ cp -L $(pwd)/%{installer_script} $tmpdir/installer.sh
# Temporarily create a container so we can mount the named volume
# and copy files. It's okay if /bin/true doesn't exist inside the
# image; we are never going to run the image anyways.
vid=$($DOCKER $DOCKER_FLAGS volume create)
cid=$($DOCKER $DOCKER_FLAGS create -v $vid:/tmp/pkginstall $image_id /bin/true)
vid=$("$DOCKER" $DOCKER_FLAGS volume create)
cid=$("$DOCKER" $DOCKER_FLAGS create -v $vid:/tmp/pkginstall $image_id /bin/true)
for f in $tmpdir/*; do
$DOCKER $DOCKER_FLAGS cp $f $cid:/tmp/pkginstall
"$DOCKER" $DOCKER_FLAGS cp $f $cid:/tmp/pkginstall
done
$DOCKER $DOCKER_FLAGS rm $cid
"$DOCKER" $DOCKER_FLAGS rm $cid

cid=$($DOCKER $DOCKER_FLAGS run -d -v $vid:/tmp/pkginstall --privileged $image_id /tmp/pkginstall/installer.sh)
cid=$("$DOCKER" $DOCKER_FLAGS run -d -v $vid:/tmp/pkginstall --privileged $image_id /tmp/pkginstall/installer.sh)

$DOCKER $DOCKER_FLAGS attach $cid || true
"$DOCKER" $DOCKER_FLAGS attach $cid || true

reset_cmd $image_id $cid %{output_image_name}
$DOCKER $DOCKER_FLAGS save %{output_image_name} > %{output_file_name}
$DOCKER $DOCKER_FLAGS rm $cid
$DOCKER $DOCKER_FLAGS volume rm $vid
"$DOCKER" $DOCKER_FLAGS save %{output_image_name} > %{output_file_name}
"$DOCKER" $DOCKER_FLAGS rm $cid
"$DOCKER" $DOCKER_FLAGS volume rm $vid
) > "$log" 2>&1

if (( $? )); then
Expand Down
10 changes: 5 additions & 5 deletions docker/util/commit.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ logfile=$(output_logfile)
if ! (
# Load the image and remember its name
image_id=$(%{image_id_extractor_path} %{image_tar})
$DOCKER $DOCKER_FLAGS load -i %{image_tar}
"$DOCKER" $DOCKER_FLAGS load -i %{image_tar}

readonly id=$($DOCKER $DOCKER_FLAGS create %{docker_run_flags} $image_id %{commands})
readonly id=$("$DOCKER" $DOCKER_FLAGS create %{docker_run_flags} $image_id %{commands})
retcode=0
if $DOCKER $DOCKER_FLAGS start -a "${id}"; then
if "$DOCKER" $DOCKER_FLAGS start -a "${id}"; then
reset_cmd $image_id $id %{output_image}
$DOCKER $DOCKER_FLAGS save %{output_image} -o %{output_tar}
"$DOCKER" $DOCKER_FLAGS save %{output_image} -o %{output_tar}
else
retcode=$?
fi

$DOCKER $DOCKER_FLAGS rm $id
"$DOCKER" $DOCKER_FLAGS rm $id
exit "$retcode"
) > "$logfile" 2>&1; then
cat $logfile
Expand Down
14 changes: 7 additions & 7 deletions docker/util/commit_layer.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ logfile=$(output_logfile)
if ! (
# Load the image and remember its name
image_id=$(%{image_id_extractor_path} %{image_tar})
$DOCKER $DOCKER_FLAGS load -i %{image_tar}
"$DOCKER" $DOCKER_FLAGS load -i %{image_tar}

readonly id=$($DOCKER $DOCKER_FLAGS create %{docker_run_flags} --env-file %{env_file_path} $image_id %{commands})
readonly id=$("$DOCKER" $DOCKER_FLAGS create %{docker_run_flags} --env-file %{env_file_path} $image_id %{commands})
retcode=0
if $DOCKER $DOCKER_FLAGS start -a "${id}"; then
if "$DOCKER" $DOCKER_FLAGS start -a "${id}"; then
OUTPUT_IMAGE_TAR="%{output_layer_tar}.image.tar"
reset_cmd $image_id $id %{output_image}
$DOCKER $DOCKER_FLAGS save %{output_image} -o $OUTPUT_IMAGE_TAR
"$DOCKER" $DOCKER_FLAGS save %{output_image} -o $OUTPUT_IMAGE_TAR

# Extract the last layer from the image - this will be the layer generated by $DOCKER commit
# Extract the last layer from the image - this will be the layer generated by "$DOCKER" commit
%{image_last_layer_extractor_path} $OUTPUT_IMAGE_TAR %{output_layer_tar} %{output_diff_id}

# Delete the intermediate tar
Expand All @@ -38,8 +38,8 @@ if ! (
fi

# Delete the container and the intermediate image
$DOCKER $DOCKER_FLAGS rm $id
$DOCKER $DOCKER_FLAGS rmi %{output_image}
"$DOCKER" $DOCKER_FLAGS rm $id
"$DOCKER" $DOCKER_FLAGS rmi %{output_image}

exit "$retcode"
) > "$logfile" 2>&1; then
Expand Down
12 changes: 6 additions & 6 deletions docker/util/extract.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ trap "rm $logfile" EXIT
if ! (
# Load the image and remember its name
image_id=$(%{image_id_extractor_path} %{image_tar})
$DOCKER $DOCKER_FLAGS load -i %{image_tar}
"$DOCKER" $DOCKER_FLAGS load -i %{image_tar}

id=$($DOCKER $DOCKER_FLAGS run -d %{docker_run_flags} $image_id %{commands})
id=$("$DOCKER" $DOCKER_FLAGS run -d %{docker_run_flags} $image_id %{commands})

retcode=$($DOCKER $DOCKER_FLAGS wait $id)
retcode=$("$DOCKER" $DOCKER_FLAGS wait $id)

# Print any error that occurred in the container.
if [ $retcode != 0 ]; then
$DOCKER $DOCKER_FLAGS logs $id && false
"$DOCKER" $DOCKER_FLAGS logs $id && false
exit $retcode
fi

$DOCKER $DOCKER_FLAGS cp $id:%{extract_file} %{output}
$DOCKER $DOCKER_FLAGS rm $id
"$DOCKER" $DOCKER_FLAGS cp $id:%{extract_file} %{output}
"$DOCKER" $DOCKER_FLAGS rm $id
) > "$logfile" 2>&1; then
cat "$logfile"
exit 1
Expand Down
4 changes: 2 additions & 2 deletions docker/util/image_util.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ reset_cmd() {
DOCKER_FLAGS="%{docker_flags}"
local old_cmd
# docker inspect input cannot be piped into docker commit directly, we need to JSON format it.
old_cmd=$($DOCKER $DOCKER_FLAGS inspect -f "{{range .Config.Cmd}}{{.}} {{end}}" "${original_image_name}")
old_cmd=$("$DOCKER" $DOCKER_FLAGS inspect -f "{{range .Config.Cmd}}{{.}} {{end}}" "${original_image_name}")
fmt_cmd=$(echo "$old_cmd" | ${TO_JSON_TOOL})
# If CMD wasn't set, set it to a sane default.
if [ "$fmt_cmd" == "" ] || [ "$fmt_cmd" == "[]" ];
then
fmt_cmd='["/bin/sh", "-c"]'
fi

$DOCKER $DOCKER_FLAGS commit -c "CMD $fmt_cmd" "${container_id}" "${output_image_name}"
"$DOCKER" $DOCKER_FLAGS commit -c "CMD $fmt_cmd" "${container_id}" "${output_image_name}"
}

function output_logfile {
Expand Down

0 comments on commit c823a69

Please sign in to comment.