github.com/aergoio/aergo@v1.3.1/Docker/build.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  # This script can be used to build the Docker images manually (outside of CI)
     4  
     5  set -e
     6  
     7  GIT_TAG=$1
     8  MAIN_TAG=$2
     9  SECOND_TAG=$3
    10  THIRD_TAG=$4
    11  
    12  if [[ -z "$MAIN_TAG" || -z "$GIT_TAG" ]]
    13  then
    14      echo "Usage:"
    15      echo "  build.sh git-tag-or-hash tag [second-tag] [third-tag]"
    16      echo "Example:"
    17      echo "  build.sh release/0.12 0.12.0-rc"
    18      echo "  build.sh release/0.12 0.12.0 0.12 latest"
    19      exit 1
    20  fi
    21  
    22  if [[ -z "$THIRD_TAG" ]]
    23  then
    24      if [[ -z "$SECOND_TAG" ]]
    25      then
    26          declare -a tags=("$MAIN_TAG")
    27      else
    28          declare -a tags=("$MAIN_TAG" "$SECOND_TAG")
    29      fi
    30  else
    31      declare -a tags=("$MAIN_TAG" "$SECOND_TAG" "$THIRD_TAG")
    32  fi
    33  
    34  echo "Building Docker images for ${tags[*]} using git tag $GIT_TAG"
    35  sleep 1
    36  
    37  BUILDER_TAG="aergo/builder"
    38  echo "Building ${BUILDER_TAG}"
    39  
    40  docker build --no-cache --build-arg GIT_TAG=$GIT_TAG --file Dockerfile.builder -t ${BUILDER_TAG} .
    41  docker create --name extract ${BUILDER_TAG}
    42  docker cp extract:/go/aergo/bin/ .
    43  docker cp extract:/go/aergo/cmd/brick/arglog.toml bin/brick-arglog.toml
    44  docker cp extract:/go/aergo/libtool/lib/ .
    45  docker rm -f extract
    46  
    47  declare -a names=("node" "tools" "polaris")
    48  for name in "${names[@]}"
    49  do
    50      tagsExpanded=()
    51      for tag in "${tags[@]}"; do
    52          tagsExpanded+=("-t aergo/$name:$tag")
    53      done
    54      echo "[aergo/$name:${tags[*]}]"
    55      DOCKERFILE="Dockerfile.$name"
    56      echo docker build -q ${tagsExpanded[@]} --file $DOCKERFILE .
    57      imageid=`docker build -q ${tagsExpanded[@]} --file $DOCKERFILE .`
    58      docker images --format "Done: \t{{.Repository}}:{{.Tag}} \t{{.ID}} ({{.Size}})" | grep "${imageid:7:12}"
    59  done
    60  
    61  rm -rf bin lib
    62  
    63  echo -e "\nREPOSITORY          TAG                 IMAGE ID            CREATED             SIZE"
    64  for name in "${names[@]}"
    65  do
    66      for tag in "${tags[@]}"
    67      do
    68          docker images aergo/$name:$tag | tail -1
    69      done
    70  done
    71  
    72  echo -e "\nYou can now push these to Docker Hub."
    73  echo "For example:"
    74  
    75  declare -a names=("node" "tools" "polaris")
    76  for name in "${names[@]}"
    77  do
    78      for tag in "${tags[@]}"
    79      do
    80          echo "  docker push aergo/$name:$tag"
    81      done
    82  done
    83