annotate utils/docker/build_docker_image.sh @ 131:f476a9ba4795

http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
author mir3636
date Fri, 16 Feb 2018 21:02:11 +0900
parents 803732b1fca8
children 3a76565eade5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
1 #!/bin/bash
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
2 #===- llvm/utils/docker/build_docker_image.sh ----------------------------===//
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
3 #
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
4 # The LLVM Compiler Infrastructure
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
5 #
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
6 # This file is distributed under the University of Illinois Open Source
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
7 # License. See LICENSE.TXT for details.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
8 #
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
9 #===----------------------------------------------------------------------===//
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
10 set -e
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
11
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
12 IMAGE_SOURCE=""
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
13 DOCKER_REPOSITORY=""
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
14 DOCKER_TAG=""
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
15 BUILDSCRIPT_ARGS=""
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
16
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
17 function show_usage() {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
18 cat << EOF
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
19 Usage: build_docker_image.sh [options] [-- [cmake_args]...]
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
20
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
21 Available options:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
22 General:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
23 -h|--help show this help message
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
24 Docker-specific:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
25 -s|--source image source dir (i.e. debian8, nvidia-cuda, etc)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
26 -d|--docker-repository docker repository for the image
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
27 -t|--docker-tag docker tag for the image
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
28 LLVM-specific:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
29 -b|--branch svn branch to checkout, i.e. 'trunk',
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
30 'branches/release_40'
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
31 (default: 'trunk')
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
32 -r|--revision svn revision to checkout
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
33 -p|--llvm-project name of an svn project to checkout. Will also add the
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
34 project to a list LLVM_ENABLE_PROJECTS, passed to CMake.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
35 For clang, please use 'clang', not 'cfe'.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
36 Project 'llvm' is always included and ignored, if
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
37 specified.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
38 Can be specified multiple times.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
39 -i|--install-target name of a cmake install target to build and include in
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
40 the resulting archive. Can be specified multiple times.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
41 -c|--checksums name of a file, containing checksums of llvm checkout.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
42 Script will fail if checksums of the checkout do not
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
43 match.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
44
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
45 Required options: --source and --docker-repository, at least one
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
46 --install-target.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
47
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
48 All options after '--' are passed to CMake invocation.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
49
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
50 For example, running:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
51 $ build_docker_image.sh -s debian8 -d mydocker/debian8-clang -t latest \
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
52 -p clang -i install-clang -i install-clang-headers
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
53 will produce two docker images:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
54 mydocker/debian8-clang-build:latest - an intermediate image used to compile
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
55 clang.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
56 mydocker/clang-debian8:latest - a small image with preinstalled clang.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
57 Please note that this example produces a not very useful installation, since it
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
58 doesn't override CMake defaults, which produces a Debug and non-boostrapped
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
59 version of clang.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
60
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
61 To get a 2-stage clang build, you could use this command:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
62 $ ./build_docker_image.sh -s debian8 -d mydocker/clang-debian8 -t "latest" \
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
63 -p clang -i stage2-install-clang -i stage2-install-clang-headers \
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
64 -- \
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
65 -DLLVM_TARGETS_TO_BUILD=Native -DCMAKE_BUILD_TYPE=Release \
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
66 -DBOOTSTRAP_CMAKE_BUILD_TYPE=Release \
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
67 -DCLANG_ENABLE_BOOTSTRAP=ON \
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
68 -DCLANG_BOOTSTRAP_TARGETS="install-clang;install-clang-headers"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
69 EOF
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
70 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
71
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
72 CHECKSUMS_FILE=""
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
73 SEEN_INSTALL_TARGET=0
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
74 while [[ $# -gt 0 ]]; do
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
75 case "$1" in
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
76 -h|--help)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
77 show_usage
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
78 exit 0
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
79 ;;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
80 -s|--source)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
81 shift
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
82 IMAGE_SOURCE="$1"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
83 shift
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
84 ;;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
85 -d|--docker-repository)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
86 shift
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
87 DOCKER_REPOSITORY="$1"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
88 shift
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
89 ;;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
90 -t|--docker-tag)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
91 shift
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
92 DOCKER_TAG="$1"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
93 shift
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
94 ;;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
95 -i|--install-target|-r|--revision|-b|--branch|-p|--llvm-project)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
96 if [ "$1" == "-i" ] || [ "$1" == "--install-target" ]; then
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
97 SEEN_INSTALL_TARGET=1
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
98 fi
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
99 BUILDSCRIPT_ARGS="$BUILDSCRIPT_ARGS $1 $2"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
100 shift 2
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
101 ;;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
102 -c|--checksums)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
103 shift
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
104 CHECKSUMS_FILE="$1"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
105 shift
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
106 ;;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
107 --)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
108 shift
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
109 BUILDSCRIPT_ARGS="$BUILDSCRIPT_ARGS -- $*"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
110 shift $#
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
111 ;;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
112 *)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
113 echo "Unknown argument $1"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
114 exit 1
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
115 ;;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
116 esac
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
117 done
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
118
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
119 command -v docker >/dev/null ||
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
120 {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
121 echo "Docker binary cannot be found. Please install Docker to use this script."
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
122 exit 1
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
123 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
124
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
125 if [ "$IMAGE_SOURCE" == "" ]; then
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
126 echo "Required argument missing: --source"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
127 exit 1
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
128 fi
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
129
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
130 if [ "$DOCKER_REPOSITORY" == "" ]; then
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
131 echo "Required argument missing: --docker-repository"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
132 exit 1
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
133 fi
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
134
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
135 if [ $SEEN_INSTALL_TARGET -eq 0 ]; then
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
136 echo "Please provide at least one --install-target"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
137 exit 1
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
138 fi
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
139
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
140 SOURCE_DIR=$(dirname $0)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
141 if [ ! -d "$SOURCE_DIR/$IMAGE_SOURCE" ]; then
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
142 echo "No sources for '$IMAGE_SOURCE' were found in $SOURCE_DIR"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
143 exit 1
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
144 fi
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
145
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
146 BUILD_DIR=$(mktemp -d)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
147 trap "rm -rf $BUILD_DIR" EXIT
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
148 echo "Using a temporary directory for the build: $BUILD_DIR"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
149
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
150 cp -r "$SOURCE_DIR/$IMAGE_SOURCE" "$BUILD_DIR/$IMAGE_SOURCE"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
151 cp -r "$SOURCE_DIR/scripts" "$BUILD_DIR/scripts"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
152
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
153 mkdir "$BUILD_DIR/checksums"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
154 if [ "$CHECKSUMS_FILE" != "" ]; then
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
155 cp "$CHECKSUMS_FILE" "$BUILD_DIR/checksums/checksums.txt"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
156 fi
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
157
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
158 if [ "$DOCKER_TAG" != "" ]; then
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
159 DOCKER_TAG=":$DOCKER_TAG"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
160 fi
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
161
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
162 echo "Building from $IMAGE_SOURCE"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
163 echo "Building $DOCKER_REPOSITORY-build$DOCKER_TAG"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
164 docker build -t "$DOCKER_REPOSITORY-build$DOCKER_TAG" \
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
165 --build-arg "buildscript_args=$BUILDSCRIPT_ARGS" \
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
166 -f "$BUILD_DIR/$IMAGE_SOURCE/build/Dockerfile" \
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
167 "$BUILD_DIR"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
168
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
169 echo "Copying clang installation to release image sources"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
170 docker run -v "$BUILD_DIR/$IMAGE_SOURCE:/workspace" "$DOCKER_REPOSITORY-build$DOCKER_TAG" \
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
171 cp /tmp/clang.tar.gz /workspace/release
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
172
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
173 echo "Building release image"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
174 docker build -t "${DOCKER_REPOSITORY}${DOCKER_TAG}" \
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
175 "$BUILD_DIR/$IMAGE_SOURCE/release"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
176
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
177 echo "Done"