github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/sawtooth-supply-chain-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  usage() {
    22      echo "Usage:"
    23      echo "  $0"
    24      echo
    25      echo "Options:"
    26      echo "  -h            print usage and exit"
    27  }
    28  
    29  info() {
    30      echo -e "\033[0;36m\n[--- $1 ---]\n\033[0m"
    31  }
    32  
    33  warn() {
    34      echo -e "\033[0;31m\n[--- $1 ---]\n\033[0m"
    35  }
    36  
    37  while getopts :x:l:h opt
    38  do
    39      case $opt in
    40          h)
    41              usage
    42              exit 0
    43              ;;
    44  
    45          \?)
    46              echo "Invalid option: -$OPTARG" >&2
    47              usage
    48              exit 1
    49              ;;
    50      esac
    51  done
    52  shift $(($OPTIND-1))
    53  
    54  main() {
    55      # Set project directory relative to this file
    56      top_dir=$(cd $(dirname $(dirname $0)) && pwd)
    57  
    58      # Start in project directory
    59      cd $top_dir
    60  
    61      docker_build server/Dockerfile . supply-chain-server
    62      docker_build docker/supply-chain-dev-python . supply-chain-dev-python
    63      docker_build processor/Dockerfile processor/ supply-tp
    64      docker_build docker/supply-chain-dev-rust . supply-chain-dev-rust
    65      docker_run supply-chain-dev-rust
    66  }
    67  
    68  docker_run() {
    69      image=$1
    70  
    71      if [ -z $ISOLATION_ID ]; then
    72          tag=$image
    73      else
    74          tag=$image:$ISOLATION_ID
    75      fi
    76  
    77      info "Running $image"
    78      if [ -z $BUILD_TAG ]
    79      then
    80          docker run -t --rm -v $top_dir:/project/sawtooth-supply-chain \
    81              --env https_proxy=$https_proxy \
    82              --env http_proxy=$http_proxy \
    83              --env HTTPS_PROXY=$HTTPS_PROXY \
    84              --env HTTP_PROXY=$HTTP_PROXY \
    85              $tag
    86      else
    87          docker run --rm -v $top_dir:/project/sawtooth-supply-chain \
    88              --env https_proxy=$https_proxy \
    89              --env http_proxy=$http_proxy \
    90              --env HTTPS_PROXY=$HTTPS_PROXY \
    91              --env HTTP_PROXY=$HTTP_PROXY \
    92              $tag
    93      fi
    94  }
    95  
    96  docker_build() {
    97      image=$1
    98      context=$2
    99      tag=$3
   100  
   101      if [ ! -z $ISOLATION_ID ]
   102      then
   103          tag=$tag:$ISOLATION_ID
   104      fi
   105  
   106      info "Building $tag from $image"
   107  
   108      # Build the image and pass in any proxy information if set
   109      docker build -f $image -t $tag $context \
   110          --build-arg https_proxy=$https_proxy \
   111          --build-arg http_proxy=$http_proxy \
   112          --build-arg HTTPS_PROXY=$HTTPS_PROXY \
   113          --build-arg HTTP_PROXY=$HTTP_PROXY
   114  }
   115  
   116  main