Skip to content
This repository has been archived by the owner on Oct 2, 2023. It is now read-only.

install_pkgs uses named volumes to work with DIND. #1277

Merged
merged 12 commits into from
Nov 21, 2019
Merged
9 changes: 4 additions & 5 deletions docker/package_managers/installer.sh.tpl
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#!/bin/bash
# This script installs debs in installables.tar through dpkg and apt-get.
# It expects to be volume-mounted inside a docker image, in /tmp along with the
# installables.tar.
# It expects to be volume-mounted inside a docker image, in /tmp/pkginstall
# along with the installables.tar.
set -ex
pushd /tmp
pushd /tmp/pkginstall
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update docs above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

%{install_commands}
popd
umount -l /tmp/installer.sh
umount -l /tmp/%{installables_tar}
umount -l /tmp/pkginstall
rm -rf /tmp/*
32 changes: 31 additions & 1 deletion docker/package_managers/run_install.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,41 @@ source %{util_script}
image_id=$(%{image_id_extractor_path} %{base_image_tar})
$DOCKER load -i %{base_image_tar}

# Create a docker volume containing the installer script and the
# installables TAR file.
#
# Note that we cannot mount local files and directories
# directly into the container, since it doesn't work correctly
# in docker-in-docker setups. In docker-in-docker setups, we
# are running in a container while the docker daemon is running
# on a host. Mounting directories is done from the perspective
# of the host and not our container.
#
# To get around this, we create a named volume and copy our files
# to the named volume.

# Prepare directory structure. 'docker cp' will not create
# intermediate paths.
tmpdir=$(mktemp -d)
trap "rm -rf $tmpdir" EXIT
mkdir -p $(dirname $tmpdir/%{installables_tar})
cp -L $(pwd)/%{installables_tar} $tmpdir/%{installables_tar}
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 volume create)
cid=$($DOCKER create -v $vid:/tmp/pkginstall $image_id /bin/true)
for f in $tmpdir/*; do
$DOCKER cp $f $cid:/tmp/pkginstall
done
$DOCKER rm $cid

cid=$($DOCKER run -d -v $(pwd)/%{installables_tar}:/tmp/%{installables_tar} -v $(pwd)/%{installer_script}:/tmp/installer.sh --privileged $image_id /tmp/installer.sh)
cid=$($DOCKER run -d -v $vid:/tmp/pkginstall --privileged $image_id /tmp/pkginstall/installer.sh)

$DOCKER attach $cid || true

reset_cmd $image_id $cid %{output_image_name}
$DOCKER save %{output_image_name} > %{output_file_name}
$DOCKER rm $cid
$DOCKER volume rm $vid