github.com/unigraph-dev/dgraph@v1.1.1-0.20200923154953-8b52b426f765/contrib/nightly/build.sh (about)

     1  #!/bin/bash
     2  
     3  # This script is used to compile and tar gzip the release binaries so that they
     4  # can be uploaded to Github. It would typically only be used by Dgraph developers
     5  # while doing a new release. If you are looking to build Dgraph, you should run a
     6  # go build from inside $GOPATH/src/github.com/dgraph-io/dgraph/cmd/dgraph
     7  
     8  # Exit script in case an error is encountered.
     9  set -e
    10  
    11  asset_suffix=$1
    12  cur_dir=$(pwd);
    13  tmp_dir=/tmp/dgraph-build;
    14  release_version=$(git describe --abbrev=0);
    15  if [[ -n $asset_suffix ]]; then
    16    release_version="$release_version${asset_suffix}"
    17  fi
    18  platform="$(uname | tr '[:upper:]' '[:lower:]')"
    19  # If temporary directory already exists delete it.
    20  if [ -d "$tmp_dir" ]; then
    21    rm -rf $tmp_dir
    22  fi
    23  mkdir $tmp_dir;
    24  
    25  if ! type strip > /dev/null; then
    26    echo -e "\033[0;31mYou don't have strip command line tool available. Install it and try again.\033[0m"
    27    exit 1
    28  fi
    29  
    30  source $GOPATH/src/github.com/dgraph-io/dgraph/contrib/nightly/constants.sh
    31  pushd $dgraph_cmd
    32  echo -e "\033[1;33mBuilding dgraph binary for $platform\033[0m"
    33  go build -ldflags \
    34    "-X $release=$release_version -X $branch=$gitBranch -X $commitSHA1=$lastCommitSHA1 -X '$commitTime=$lastCommitTime'" .;
    35  
    36  strip -x dgraph
    37  
    38  digest_cmd=""
    39  if hash shasum 2>/dev/null; then
    40    digest_cmd="shasum -a 256"
    41  else
    42    echo -e "\033[0;31mYou don't have shasum command line tool available. Install it and try again.\033[0m"
    43    exit 1
    44  fi
    45  
    46  # Create the checksum file for dgraph binary.
    47  checksum_file=$cur_dir/"dgraph-checksum-$platform-amd64.sha256"
    48  if [ -f "$checksum_file" ]; then
    49    rm $checksum_file
    50    rm -rf $cur_dir/"dgraph-checksum-darwin-amd64.sha256"
    51  fi
    52  
    53  checksum=$($digest_cmd dgraph | awk '{print $1}')
    54  echo "$checksum /usr/local/bin/dgraph" >> $checksum_file
    55  
    56  # Move dgraph to tmp directory.
    57  cp dgraph $tmp_dir
    58  
    59  popd
    60  
    61  
    62  if [ -d "$ratel" ]; then
    63    pushd $ratel
    64    echo -e "\033[1;33mBuilding ratel binary for $platform\033[0m"
    65    go build -ldflags \
    66      "-X $ratel_release=$release_version" -o dgraph-ratel
    67    strip -x dgraph-ratel
    68    checksum=$($digest_cmd dgraph-ratel | awk '{print $1}')
    69    echo "$checksum /usr/local/bin/dgraph-ratel" >> $checksum_file
    70    cp dgraph-ratel $tmp_dir
    71    popd
    72  fi
    73  
    74  echo -e "\n\033[1;34mSize of files after  strip: $(du -sh $tmp_dir)\033[0m"
    75  
    76  echo -e "\n\033[1;33mCreating tar file\033[0m"
    77  tar_file=dgraph-"$platform"-amd64
    78  
    79  # Create a tar file with the contents of the dgraph folder (i.e the binaries)
    80  tar -zvcf $tar_file.tar.gz -C $tmp_dir .;
    81  echo -e "\n\033[1;34mSize of tar file: $(du -sh $tar_file.tar.gz)\033[0m"
    82  
    83  mv $tmp_dir ./
    84  
    85  # Only run this locally, if DOCKER environment variable is set to true.
    86  if [[ $DOCKER == true ]]; then
    87    docker build -t dgraph/dgraph:master -f $GOPATH/src/github.com/dgraph-io/dgraph/contrib/nightly/Dockerfile .
    88  fi
    89  
    90  rm -Rf dgraph-build