2 #===- llvm/utils/docker/build_docker_image.sh ----------------------------===//
4 # The LLVM Compiler Infrastructure
6 # This file is distributed under the University of Illinois Open Source
7 # License. See LICENSE.TXT for details.
9 #===----------------------------------------------------------------------===//
17 function show_usage() {
19 Usage: build_docker_image.sh [options] [-- [cmake_args]...]
23 -h|--help show this help message
25 -s|--source image source dir (i.e. debian8, nvidia-cuda, etc)
26 -d|--docker-repository docker repository for the image
27 -t|--docker-tag docker tag for the image
29 -b|--branch svn branch to checkout, i.e. 'trunk',
32 -r|--revision svn revision to checkout
33 -c|--cherrypick revision to cherry-pick. Can be specified multiple times.
34 Cherry-picks are performed in the sorted order using the
36 'svn patch <(svn diff -c \$rev)'.
37 -p|--llvm-project name of an svn project to checkout. Will also add the
38 project to a list LLVM_ENABLE_PROJECTS, passed to CMake.
39 For clang, please use 'clang', not 'cfe'.
40 Project 'llvm' is always included and ignored, if
42 Can be specified multiple times.
43 -i|--install-target name of a cmake install target to build and include in
44 the resulting archive. Can be specified multiple times.
45 -c|--checksums name of a file, containing checksums of llvm checkout.
46 Script will fail if checksums of the checkout do not
49 Required options: --source and --docker-repository, at least one
52 All options after '--' are passed to CMake invocation.
55 $ build_docker_image.sh -s debian8 -d mydocker/debian8-clang -t latest \
56 -p clang -i install-clang -i install-clang-headers
57 will produce two docker images:
58 mydocker/debian8-clang-build:latest - an intermediate image used to compile
60 mydocker/clang-debian8:latest - a small image with preinstalled clang.
61 Please note that this example produces a not very useful installation, since it
62 doesn't override CMake defaults, which produces a Debug and non-boostrapped
65 To get a 2-stage clang build, you could use this command:
66 $ ./build_docker_image.sh -s debian8 -d mydocker/clang-debian8 -t "latest" \
67 -p clang -i stage2-install-clang -i stage2-install-clang-headers \
69 -DLLVM_TARGETS_TO_BUILD=Native -DCMAKE_BUILD_TYPE=Release \
70 -DBOOTSTRAP_CMAKE_BUILD_TYPE=Release \
71 -DCLANG_ENABLE_BOOTSTRAP=ON \
72 -DCLANG_BOOTSTRAP_TARGETS="install-clang;install-clang-headers"
78 while [[ $# -gt 0 ]]; do
89 -d|--docker-repository)
91 DOCKER_REPOSITORY="$1"
99 -i|--install-target|-r|--revision|-c|-cherrypick|-b|--branch|-p|--llvm-project)
100 if [ "$1" == "-i" ] || [ "$1" == "--install-target" ]; then
101 SEEN_INSTALL_TARGET=1
103 BUILDSCRIPT_ARGS="$BUILDSCRIPT_ARGS $1 $2"
113 BUILDSCRIPT_ARGS="$BUILDSCRIPT_ARGS -- $*"
117 echo "Unknown argument $1"
123 command -v docker >/dev/null ||
125 echo "Docker binary cannot be found. Please install Docker to use this script."
129 if [ "$IMAGE_SOURCE" == "" ]; then
130 echo "Required argument missing: --source"
134 if [ "$DOCKER_REPOSITORY" == "" ]; then
135 echo "Required argument missing: --docker-repository"
139 if [ $SEEN_INSTALL_TARGET -eq 0 ]; then
140 echo "Please provide at least one --install-target"
144 SOURCE_DIR=$(dirname $0)
145 if [ ! -d "$SOURCE_DIR/$IMAGE_SOURCE" ]; then
146 echo "No sources for '$IMAGE_SOURCE' were found in $SOURCE_DIR"
150 BUILD_DIR=$(mktemp -d)
151 trap "rm -rf $BUILD_DIR" EXIT
152 echo "Using a temporary directory for the build: $BUILD_DIR"
154 cp -r "$SOURCE_DIR/$IMAGE_SOURCE" "$BUILD_DIR/$IMAGE_SOURCE"
155 cp -r "$SOURCE_DIR/scripts" "$BUILD_DIR/scripts"
157 mkdir "$BUILD_DIR/checksums"
158 if [ "$CHECKSUMS_FILE" != "" ]; then
159 cp "$CHECKSUMS_FILE" "$BUILD_DIR/checksums/checksums.txt"
162 if [ "$DOCKER_TAG" != "" ]; then
163 DOCKER_TAG=":$DOCKER_TAG"
166 echo "Building from $IMAGE_SOURCE"
167 echo "Building $DOCKER_REPOSITORY-build$DOCKER_TAG"
168 docker build -t "$DOCKER_REPOSITORY-build$DOCKER_TAG" \
169 --build-arg "buildscript_args=$BUILDSCRIPT_ARGS" \
170 -f "$BUILD_DIR/$IMAGE_SOURCE/build/Dockerfile" \
173 echo "Copying clang installation to release image sources"
174 docker run -v "$BUILD_DIR/$IMAGE_SOURCE:/workspace" "$DOCKER_REPOSITORY-build$DOCKER_TAG" \
175 cp /tmp/clang.tar.gz /workspace/release
177 echo "Building release image"
178 docker build -t "${DOCKER_REPOSITORY}${DOCKER_TAG}" \
179 "$BUILD_DIR/$IMAGE_SOURCE/release"