diff --git a/Atomic/Export.py b/Atomic/Export.py index eb91e5a9..1198279b 100644 --- a/Atomic/Export.py +++ b/Atomic/Export.py @@ -16,6 +16,8 @@ DOCKER_CLIENT = docker.Client() +ATOMIC_LIBEXEC = os.environ.get('ATOMIC_LIBEXEC', '/usr/libexec/atomic') + def export_docker(graph, export_location): """ This is a wrapper function for exporting docker images, containers @@ -93,10 +95,11 @@ def export_containers(graph, export_location): split_containers.append(j["Id"]) for i in range(0, len(split_containers)): - util.writeOut("Exporting container ID:{0}".format(split_containers[i][:12])) - subprocess.check_call("/usr/libexec/atomic/migrate.sh export --container-id={0}" - " --graph={1} --export-location={2}" - .format(split_containers[i][:12], graph, export_location), + util.writeOut("Exporting container: {0}".format(split_containers[i][:12])) + subprocess.check_call("{0}/migrate.sh export --container-id={1}" + " --graph={2} --export-location={3}" + .format(ATOMIC_LIBEXEC, split_containers[i], + graph, export_location), shell=True) def export_volumes(graph, export_location): diff --git a/Atomic/Import.py b/Atomic/Import.py index fa9363b4..364fb744 100644 --- a/Atomic/Import.py +++ b/Atomic/Import.py @@ -12,6 +12,8 @@ from . import util +ATOMIC_LIBEXEC = os.environ.get('ATOMIC_LIBEXEC', '/usr/libexec/atomic') + def import_docker(graph, import_location): """ This is a wrapper function for importing docker images, containers @@ -64,10 +66,11 @@ def import_containers(graph, import_location): containers = subprocess.check_output("ls {0}/containers".format(import_location), shell=True) split_containers = containers.split() for i in split_containers: - util.writeOut("Importing container ID:{0}".format(i[8:])) - subprocess.check_call("/usr/libexec/atomic/migrate.sh import --container-id={0}" - " --graph={1} --import-location={2}" - .format(i[8:], graph, import_location), shell=True) + i = i[8:] # strip off the "migrate-" + util.writeOut("Importing container: {0}".format(i[:12])) + subprocess.check_call("{0}/migrate.sh import --container-id={1}" + " --graph={2} --import-location={3}" + .format(ATOMIC_LIBEXEC, i, graph, import_location), shell=True) def import_volumes(graph, import_location): """ diff --git a/migrate.sh b/migrate.sh index d0d662e9..fa364693 100755 --- a/migrate.sh +++ b/migrate.sh @@ -2,6 +2,9 @@ # bash script to migrate containers from one backend storage to another. set -e +ATOMIC_LIBEXEC="${ATOMIC_LIBEXEC-/usr/libexec/atomic}" +GOTAR="$ATOMIC_LIBEXEC/gotar" + main() { if [ $(id -u) != 0 ];then echo "Run 'migrate' as root user" @@ -116,11 +119,11 @@ container_export(){ echo $dockerRootDir>containerInfo.txt echo $containerBaseImageID>>containerInfo.txt echo $notruncContainerID>>containerInfo.txt - /usr/libexec/atomic/gotar -cf container-metadata.tar $dockerRootDir/containers/$notruncContainerID 2> /dev/null + "$GOTAR" -cf container-metadata.tar $dockerRootDir/containers/$notruncContainerID 2> /dev/null imageID=$(docker commit $containerID)||exit 1 mkdir -p $tmpDir/temp docker save $imageID > $tmpDir/temp/image.tar||exit 1 - $(cd $tmpDir/temp; /usr/libexec/atomic/gotar -xf image.tar) + $(cd $tmpDir/temp; "$GOTAR" -xf image.tar) cd $tmpDir/temp/$imageID cp layer.tar $tmpDir/container-diff.tar cd $tmpDir @@ -169,14 +172,14 @@ container_import(){ cd $importPath/containers/migrate-$containerID dockerBaseImageID=$(sed -n '2p' containerInfo.txt)||exit 1 - cat container-diff.tar|docker run -i -v /usr/libexec/atomic/gotar:/dev/shm/gotar $dockerBaseImageID /dev/shm/gotar -xf - + cat container-diff.tar|docker run -i -v "$GOTAR:/dev/shm/gotar" $dockerBaseImageID /dev/shm/gotar -xf - newContainerID=$(docker ps -lq)||exit 1 newContainerName=$(docker inspect -f '{{.Name}}' $newContainerID)||exit 1 newNotruncContainerID=$(docker ps -aq --no-trunc|grep $newContainerID)||exit 1 cd $dockerRootDir/containers/$newNotruncContainerID rm -rf * cp $importPath/containers/migrate-$containerID/container-metadata.tar . - /usr/libexec/atomic/gotar -xf container-metadata.tar + "$GOTAR" -xf container-metadata.tar rm container-metadata.tar oldDockerRootDir=$(sed -n '1p' $importPath/containers/migrate-$containerID/containerInfo.txt)||exit 1 oldNotruncContainerID=$(sed -n '3p' $importPath/containers/migrate-$containerID/containerInfo.txt)||exit 1 diff --git a/test.sh b/test.sh index 2935145e..cc37952e 100755 --- a/test.sh +++ b/test.sh @@ -9,6 +9,7 @@ export PYTHONPATH=${PYTHONPATH:-$(pwd)} export WORK_DIR=$(mktemp -p $(pwd) -d -t .tmp.XXXXXXXXXX) export DOCKER=${DOCKER:-"/usr/bin/docker"} export SECRET=`dd if=/dev/urandom bs=4096 count=1 2> /dev/null | sha256sum` +export ATOMIC_LIBEXEC="$(pwd)" # This image contains the secret, so it needs to be rebuilt each time. cat > tests/test-images/Dockerfile.secret <