github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/sawtooth-core-master/bin/build_all (about) 1 #!/bin/bash 2 # 3 # Copyright 2017 Intel Corporation 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 # ------------------------------------------------------------------------------ 17 18 # Exit on non-zero exit code from subcommand 19 set -e 20 21 # Default args 22 TARGETS="" 23 EXCLUDE="" 24 25 ALL_TARGETS=" 26 cxx 27 ext 28 go 29 java 30 javascript 31 poet_sgx 32 rust 33 python 34 " 35 36 MOUNTED="mounted" 37 INSTALLED="installed" 38 DEBS="debs" 39 40 usage() { 41 echo "Usage:" 42 echo " $0 [-l Language] [-x Language] {$MOUNTED,$INSTALLED,$DEBS}" 43 echo 44 echo "Options:" 45 echo " -h print usage and exit" 46 echo " -l Language only build the specified language(s)" 47 echo " -t Target only build the specified target(s)" 48 echo " -x Language/Target exclude the specified language(s)/target(s) " 49 echo "" 50 echo "Language/Target options are: $ALL_TARGETS" 51 echo "Build type options: {$MOUNTED,$INSTALLED,$DEBS}" 52 echo " $MOUNTED - build docker images that mount the Sawtooth" 53 echo " from your file system" 54 echo " $INSTALLED - build docker images with the Sawtooth " 55 echo " modules installed in them." 56 echo " $DEBS - build the debian packages for the selected targets" 57 } 58 59 info() { 60 echo -e "\033[0;36m\n[--- $1 ---]\n\033[0m" 61 } 62 63 warn() { 64 echo -e "\033[0;31m\n[--- $1 ---]\n\033[0m" 65 } 66 67 while getopts :x:t:l:h opt 68 do 69 case $opt in 70 h) 71 usage 72 exit 0 73 ;; 74 l) 75 TARGETS="$TARGETS $OPTARG" 76 ;; 77 t) 78 TARGETS="$TARGETS $OPTARG" 79 ;; 80 x) 81 EXCLUDE="$EXCLUDE $OPTARG" 82 ;; 83 84 \?) 85 echo "Invalid option: -$OPTARG" >&2 86 usage 87 exit 1 88 ;; 89 esac 90 done 91 shift $(($OPTIND-1)) 92 93 if [[ -z $1 ]] 94 then 95 BUILD_MODE=$MOUNTED 96 else 97 if [[ $1 == $MOUNTED || $1 == $INSTALLED || $1 == $DEBS ]] 98 then 99 BUILD_MODE=$1 100 else 101 echo "Invalid positional argument: $1" 102 usage 103 exit 1 104 fi 105 fi 106 107 # If no '-l' or '-t' flags are passed, run these modules 108 if [[ $TARGETS = "" ]] 109 then 110 TARGETS=$ALL_TARGETS 111 fi 112 113 main() { 114 115 info "Build mode: $BUILD_MODE" 116 117 # Set sawtooth-core project directory relative to this file 118 top_dir=$(cd $(dirname $(dirname $0)) && pwd) 119 120 # Start in project directory 121 cd $top_dir 122 123 if [[ $BUILD_MODE == $DEBS ]] 124 then 125 build_rust 126 build_debs 127 fi 128 129 for language in $TARGETS 130 do 131 132 # Check if we are skipping this module 133 skip=0 134 for exclude in $EXCLUDE 135 do 136 if [[ $language == $exclude ]] 137 then 138 skip=1 139 break 140 fi 141 done 142 143 if [[ $skip == 1 ]] 144 then 145 info "Skipping $language" 146 else 147 info "Building $language" 148 case $language in 149 cxx) 150 build_cxx 151 ;; 152 ext) 153 build_external 154 ;; 155 go) 156 build_go 157 ;; 158 java) 159 build_java 160 ;; 161 javascript) 162 build_javascript 163 ;; 164 poet_sgx) 165 build_poet_sgx 166 ;; 167 python) 168 build_python 169 ;; 170 rust) 171 build_rust 172 ;; 173 *) 174 warn "Module '$language' not found." 175 ;; 176 esac 177 fi 178 done 179 } 180 181 docker_run() { 182 image=$1 183 arg=$2 184 185 if [ -z $ISOLATION_ID ]; then 186 tag=$image 187 else 188 tag=$image:$ISOLATION_ID 189 fi 190 191 if [ -z $CARGO_REGISTRY ]; then 192 cargo_registry_flag="" 193 else 194 cargo_registry_flag="-v $CARGO_REGISTRY:/root/.cargo/registry" 195 fi 196 197 info "Running $image" 198 if [ -z $BUILD_TAG ] 199 then 200 docker run -t --rm -v $top_dir:/project/sawtooth-core \ 201 $cargo_registry_flag \ 202 --env https_proxy=$https_proxy \ 203 --env http_proxy=$http_proxy \ 204 --env HTTPS_PROXY=$HTTPS_PROXY \ 205 --env HTTP_PROXY=$HTTP_PROXY \ 206 $tag $arg 207 else 208 docker run --rm -v $top_dir:/project/sawtooth-core \ 209 $cargo_registry_flag \ 210 --env https_proxy=$https_proxy \ 211 --env http_proxy=$http_proxy \ 212 --env HTTPS_PROXY=$HTTPS_PROXY \ 213 --env HTTP_PROXY=$HTTP_PROXY \ 214 $tag $arg 215 fi 216 } 217 218 docker_build() { 219 image=$1 220 context=$2 221 tag=$3 222 223 if [ ! -z $ISOLATION_ID ] 224 then 225 tag=$tag:$ISOLATION_ID 226 fi 227 228 info "Building $tag from $image" 229 230 # Build the image and pass in any proxy information if set 231 docker build -f $image -t $tag $context \ 232 --build-arg https_proxy=$https_proxy \ 233 --build-arg http_proxy=$http_proxy \ 234 --build-arg HTTPS_PROXY=$HTTPS_PROXY \ 235 --build-arg HTTP_PROXY=$HTTP_PROXY 236 } 237 238 build_external() { 239 docker_build docker/apache-basic_auth_proxy docker/ apache-basic_auth_proxy 240 docker_build docker/grafana/sawtooth-stats-grafana \ 241 docker/ \ 242 sawtooth-stats-grafana 243 docker_build docker/influxdb/sawtooth-stats-influxdb \ 244 docker/ \ 245 sawtooth-stats-influxdb 246 } 247 248 build_debs() { 249 build_dir=/tmp/build-docker$ISOLATION_ID 250 rm -rf $build_dir 251 mkdir -p $build_dir 252 253 cp $top_dir/bin/install_packaging_deps $build_dir 254 cp $top_dir/ci/sawtooth-build-debs $build_dir 255 docker_build $build_dir/sawtooth-build-debs $build_dir sawtooth-build-debs 256 docker_run sawtooth-build-debs 257 exit 0 258 } 259 260 build_poet_sgx() { 261 docker_build docker/sawtooth-dev-poet-sgx docker/ sawtooth-dev-poet-sgx 262 docker_run sawtooth-dev-poet-sgx 263 } 264 265 if [[ $BUILD_MODE == $MOUNTED ]] 266 then 267 build_cxx() { 268 docker_build docker/sawtooth-dev-cxx docker/ sawtooth-dev-cxx 269 docker_run sawtooth-dev-cxx 270 } 271 272 build_go() { 273 docker_build docker/sawtooth-dev-go docker/ sawtooth-dev-go 274 docker_build docker/sawtooth-dev-go docker/ sawtooth-intkey-tp-go 275 docker_build docker/sawtooth-dev-go docker/ sawtooth-xo-tp-go 276 docker_build docker/sawtooth-dev-go docker/ sawtooth-smallbank-tp-go 277 docker_run sawtooth-dev-go 278 } 279 280 build_java() { 281 docker_build docker/sawtooth-dev-java docker/ sawtooth-dev-java 282 docker_build docker/sawtooth-dev-java docker/ sawtooth-intkey-tp-java 283 docker_build docker/sawtooth-dev-java docker/ sawtooth-xo-tp-java 284 docker_run sawtooth-dev-java 285 } 286 287 build_javascript() { 288 docker_build docker/sawtooth-dev-javascript docker/ sawtooth-dev-javascript 289 docker_build docker/sawtooth-dev-javascript docker/ sawtooth-intkey-tp-javascript 290 docker_build docker/sawtooth-dev-javascript docker/ sawtooth-xo-tp-javascript 291 docker_run sawtooth-dev-javascript 292 } 293 294 build_python() { 295 docker_build $top_dir/docker/sawtooth-dev-python docker/ sawtooth-dev-python 296 docker_build $top_dir/docker/sawtooth-dev-validator docker/ sawtooth-dev-validator 297 docker_build $top_dir/docker/sawtooth-dev-python docker/ sawtooth-rest-api 298 docker_build $top_dir/docker/sawtooth-dev-python docker/ sawtooth-settings-tp 299 docker_build $top_dir/docker/sawtooth-dev-python docker/ sawtooth-identity-tp 300 docker_build $top_dir/docker/sawtooth-dev-python docker/ sawtooth-block-info-tp 301 docker_build $top_dir/docker/sawtooth-dev-python docker/ sawtooth-battleship-tp 302 docker_build $top_dir/docker/sawtooth-dev-python docker/ sawtooth-intkey-tp-python 303 docker_build $top_dir/docker/sawtooth-dev-python docker/ sawtooth-poet-validator-registry-tp 304 docker_build $top_dir/docker/sawtooth-dev-python docker/ sawtooth-xo-tp-python 305 docker_build $top_dir/docker/sawtooth-dev-validator docker/ sawtooth-validator 306 docker_build $top_dir/docker/sawtooth-validator-mounted docker/ sawtooth-validator-mounted 307 docker_run sawtooth-dev-python 308 docker_run sawtooth-dev-validator 309 } 310 311 build_rust() { 312 docker_build docker/sawtooth-dev-rust docker/ sawtooth-dev-rust 313 docker_build $top_dir/docker/sawtooth-dev-rust docker/ sawtooth-intkey-tp-rust 314 docker_build $top_dir/docker/sawtooth-dev-rust docker/ sawtooth-xo-tp-rust 315 docker_run sawtooth-dev-rust 316 } 317 fi 318 319 if [[ $BUILD_MODE == $INSTALLED ]] 320 then 321 build_cxx() { 322 build_dir=/tmp/build-docker$ISOLATION_ID 323 rm -rf $build_dir 324 mkdir -p $build_dir 325 326 docker_build docker/sawtooth-dev-cxx docker/ sawtooth-dev-cxx 327 docker_run sawtooth-dev-cxx 328 329 cp $top_dir/bin/install_packaging_deps $build_dir 330 cp $top_dir/ci/sawtooth-build-debs $build_dir 331 docker_build $build_dir/sawtooth-build-debs $build_dir sawtooth-build-debs 332 docker_run sawtooth-build-debs cxx 333 } 334 335 build_go() { 336 build_dir=/tmp/build-docker$ISOLATION_ID 337 rm -rf $build_dir 338 mkdir -p $build_dir 339 340 docker_build docker/sawtooth-dev-go docker/ sawtooth-dev-go 341 docker_run sawtooth-dev-go 342 343 cp $top_dir/bin/install_packaging_deps $build_dir 344 cp $top_dir/ci/sawtooth-build-debs $build_dir 345 docker_build $build_dir/sawtooth-build-debs $build_dir sawtooth-build-debs 346 docker_run sawtooth-build-debs go 347 348 build_dir=/tmp/build-docker$ISOLATION_ID 349 rm -rf $build_dir 350 mkdir -p $build_dir 351 cp $top_dir/build/debs/go/sawtooth*go*.deb $build_dir/ 352 353 cp $top_dir/docker/sawtooth-int-intkey-tp-go $build_dir 354 cp $top_dir/docker/sawtooth-int-xo-tp-go $build_dir 355 cp $top_dir/docker/sawtooth-int-smallbank-tp-go $build_dir 356 357 ls $build_dir 358 359 docker_build $build_dir/sawtooth-int-intkey-tp-go $build_dir/ \ 360 sawtooth-intkey-tp-go 361 docker_build $build_dir/sawtooth-int-xo-tp-go $build_dir/ \ 362 sawtooth-xo-tp-go 363 docker_build $build_dir/sawtooth-int-smallbank-tp-go $build_dir/ \ 364 sawtooth-smallbank-tp-go 365 } 366 367 build_java() { 368 warn "Installed java images not implemented, building mounted instead" 369 docker_build docker/sawtooth-dev-java docker/ sawtooth-dev-java 370 docker_build docker/sawtooth-dev-java docker/ sawtooth-intkey-tp-java 371 docker_build docker/sawtooth-dev-java docker/ sawtooth-xo-tp-java 372 docker_run sawtooth-dev-java 373 } 374 375 build_javascript() { 376 warn "Installed javascript images not implemented, building mounted instead" 377 docker_build docker/sawtooth-dev-javascript docker/ sawtooth-dev-javascript 378 docker_build docker/sawtooth-dev-javascript docker/ sawtooth-intkey-tp-javascript 379 docker_build docker/sawtooth-dev-javascript docker/ sawtooth-xo-tp-javascript 380 docker_run sawtooth-dev-javascript 381 } 382 build_python() { 383 build_dir=/tmp/build-docker$ISOLATION_ID 384 rm -rf $build_dir 385 mkdir -p $build_dir 386 387 docker_build $top_dir/docker/sawtooth-dev-validator docker/ sawtooth-dev-validator 388 docker_run sawtooth-dev-validator 389 390 cp $top_dir/bin/install_packaging_deps $build_dir 391 cp $top_dir/ci/sawtooth-build-debs $build_dir 392 docker_build $build_dir/sawtooth-build-debs $build_dir sawtooth-build-debs 393 docker_run sawtooth-build-debs python 394 395 docker_build $top_dir/docker/sawtooth-dev-python docker/ sawtooth-dev-python 396 docker_run sawtooth-dev-python 397 398 cp $top_dir/build/debs/python/python3*.deb $build_dir/ 399 cp $top_dir/docker/sawtooth-int-* $build_dir/ 400 ls $build_dir 401 402 docker_build $build_dir/sawtooth-int-rest-api \ 403 $build_dir/ sawtooth-rest-api 404 405 docker_build $build_dir/sawtooth-int-settings-tp \ 406 $build_dir/ sawtooth-settings-tp 407 408 docker_build $build_dir/sawtooth-int-block-info-tp \ 409 $build_dir/ sawtooth-block-info-tp 410 411 docker_build $top_dir/docker/sawtooth-dev-python docker/ sawtooth-battleship-tp 412 413 docker_build $build_dir/sawtooth-int-identity-tp \ 414 $build_dir/ sawtooth-identity-tp 415 416 docker_build $build_dir/sawtooth-int-intkey-tp-python \ 417 $build_dir/ sawtooth-intkey-tp-python 418 419 docker_build $build_dir/sawtooth-int-poet-validator-registry-tp \ 420 $build_dir/ sawtooth-poet-validator-registry-tp 421 422 docker_build $build_dir/sawtooth-int-xo-tp-python \ 423 $build_dir/ sawtooth-xo-tp-python 424 425 docker_build $build_dir/sawtooth-int-validator \ 426 $build_dir/ sawtooth-validator 427 } 428 429 build_rust() { 430 build_dir=/tmp/build-docker$ISOLATION_ID 431 rm -rf $build_dir 432 mkdir -p $build_dir 433 434 cp $top_dir/docker/sawtooth-dev-rust $build_dir 435 docker_build $build_dir/sawtooth-dev-rust $build_dir/ sawtooth-dev-rust 436 docker_build $build_dir/sawtooth-dev-rust $build_dir/ sawtooth-intkey-tp-rust 437 docker_build $build_dir/sawtooth-dev-rust $build_dir/ sawtooth-xo-tp-rust 438 docker_run sawtooth-dev-rust 439 440 cp $top_dir/bin/install_packaging_deps $build_dir 441 cp $top_dir/ci/sawtooth-build-debs $build_dir 442 docker_build $build_dir/sawtooth-build-debs $build_dir sawtooth-build-debs 443 docker_run sawtooth-build-debs rust 444 445 } 446 fi 447 448 if [[ $BUILD_MODE == $DEBS ]] 449 then 450 build_rust() { 451 build_dir=/tmp/build-docker$ISOLATION_ID 452 rm -rf $build_dir 453 mkdir -p $build_dir 454 455 cp $top_dir/docker/sawtooth-dev-rust $build_dir 456 docker_build $build_dir/sawtooth-dev-rust $build_dir/ sawtooth-dev-rust 457 docker_run sawtooth-dev-rust 458 } 459 fi 460 461 main