Skip to content

Commit

Permalink
Use temporary directory when building docker image.
Browse files Browse the repository at this point in the history
Summary:
This avoids races on copying of compiled clang from 'build' image
to 'release' image.

Reviewers: klimek, mehdi_amini

Reviewed By: mehdi_amini

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D37098

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@311769 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
ilya-biryukov committed Aug 25, 2017
1 parent bbcf256 commit 33badf7
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions utils/docker/build_docker_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -128,30 +128,36 @@ if [ $SEEN_INSTALL_TARGET -eq 0 ]; then
exit 1
fi

cd $(dirname $0)
if [ ! -d $IMAGE_SOURCE ]; then
echo "No sources for '$IMAGE_SOURCE' were found in $PWD"
SOURCE_DIR=$(dirname $0)
if [ ! -d "$SOURCE_DIR/$IMAGE_SOURCE" ]; then
echo "No sources for '$IMAGE_SOURCE' were found in $SOURCE_DIR"
exit 1
fi

echo "Building from $IMAGE_SOURCE"
BUILD_DIR=$(mktemp -d)
trap "rm -rf $BUILD_DIR" EXIT
echo "Using a temporary directory for the build: $BUILD_DIR"

cp -r "$SOURCE_DIR/$IMAGE_SOURCE" "$BUILD_DIR/$IMAGE_SOURCE"
cp -r "$SOURCE_DIR/scripts" "$BUILD_DIR/scripts"

if [ "$DOCKER_TAG" != "" ]; then
DOCKER_TAG=":$DOCKER_TAG"
fi

echo "Building from $IMAGE_SOURCE"
echo "Building $DOCKER_REPOSITORY-build$DOCKER_TAG"
docker build -t "$DOCKER_REPOSITORY-build$DOCKER_TAG" \
--build-arg "buildscript_args=$BUILDSCRIPT_ARGS" \
-f "$IMAGE_SOURCE/build/Dockerfile" .
-f "$BUILD_DIR/$IMAGE_SOURCE/build/Dockerfile" \
"$BUILD_DIR"

echo "Copying clang installation to release image sources"
docker run -v "$PWD/$IMAGE_SOURCE:/workspace" "$DOCKER_REPOSITORY-build$DOCKER_TAG" \
docker run -v "$BUILD_DIR/$IMAGE_SOURCE:/workspace" "$DOCKER_REPOSITORY-build$DOCKER_TAG" \
cp /tmp/clang.tar.gz /workspace/release
trap "rm -f $PWD/$IMAGE_SOURCE/release/clang.tar.gz" EXIT

echo "Building release image"
docker build -t "${DOCKER_REPOSITORY}${DOCKER_TAG}" \
"$IMAGE_SOURCE/release"
"$BUILD_DIR/$IMAGE_SOURCE/release"

echo "Done"

0 comments on commit 33badf7

Please sign in to comment.