Merge "Lock around extract-image downloads and extracts"
This commit is contained in:
@@ -14,11 +14,12 @@ CACHED_IMAGE=$4
|
|||||||
|
|
||||||
CACHED_TAR=$DIB_IMAGE_CACHE/$BASE_IMAGE_TAR
|
CACHED_TAR=$DIB_IMAGE_CACHE/$BASE_IMAGE_TAR
|
||||||
DIB_LOCAL_IMAGE=${DIB_LOCAL_IMAGE:-""}
|
DIB_LOCAL_IMAGE=${DIB_LOCAL_IMAGE:-""}
|
||||||
|
TAR_LOCK=$CACHED_TAR.lock
|
||||||
|
|
||||||
if [ -n "$DIB_OFFLINE" -a -f "$CACHED_TAR" ] ; then
|
function extract_image() {
|
||||||
|
if [ -n "$DIB_OFFLINE" -a -f "$CACHED_TAR" ] ; then
|
||||||
echo "Not checking freshness of cached $CACHED_TAR."
|
echo "Not checking freshness of cached $CACHED_TAR."
|
||||||
else
|
else
|
||||||
|
|
||||||
if [ -z "$DIB_LOCAL_IMAGE" ]; then
|
if [ -z "$DIB_LOCAL_IMAGE" ]; then
|
||||||
echo "Fetching Base Image"
|
echo "Fetching Base Image"
|
||||||
|
|
||||||
@@ -89,9 +90,20 @@ else
|
|||||||
else
|
else
|
||||||
echo "Using cached tar from $CACHED_TAR"
|
echo "Using cached tar from $CACHED_TAR"
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
fi
|
# Extract the base image (use --numeric-owner to avoid UID/GID mismatch between
|
||||||
# Extract the base image (use --numeric-owner to avoid UID/GID mismatch between
|
# image tarball and host OS e.g. when building Fedora image on an openSUSE host)
|
||||||
# image tarball and host OS e.g. when building Fedora image on an openSUSE host)
|
echo "Extracting base root image from $CACHED_TAR"
|
||||||
echo "Extracting base root image from $CACHED_TAR"
|
sudo tar -C $TARGET_ROOT --numeric-owner -xzf $CACHED_TAR
|
||||||
sudo tar -C $TARGET_ROOT --numeric-owner -xzf $CACHED_TAR
|
}
|
||||||
|
|
||||||
|
(
|
||||||
|
echo "Getting $TAR_LOCK: $(date)"
|
||||||
|
# Wait up to 20 minutes for another process to download
|
||||||
|
if ! flock -w 1200 9 ; then
|
||||||
|
echo "Did not get $TAR_LOCK: $(date)"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
extract_image
|
||||||
|
) 9> $TAR_LOCK
|
||||||
|
Reference in New Issue
Block a user