github.com/unigraph-dev/dgraph@v1.1.1-0.20200923154953-8b52b426f765/contrib/release.sh (about) 1 #!/bin/bash 2 3 # Script to do Dgraph release. This script would output the built binaries in 4 # $TMP. This script should NOT be responsible for doing any testing, or 5 # uploading to any server. The sole task of this script is to build the 6 # binaries and prepare them such that any human or script can then pick these up 7 # and use them as they deem fit. 8 9 # Output colors 10 RED='\033[91;1m' 11 RESET='\033[0m' 12 13 # Don't use standard GOPATH. Create a new one. 14 unset GOBIN 15 GOPATH="/tmp/go" 16 rm -Rf $GOPATH 17 mkdir $GOPATH 18 # Necessary to pick up Gobin binaries like protoc-gen-gofast 19 PATH="$GOPATH/bin:$PATH" 20 21 # The Go version used for release builds must match this version. 22 GOVERSION="1.12.7" 23 24 TAG=$1 25 # The Docker tag should not contain a slash e.g. feature/issue1234 26 # The initial slash is taken from the repository name dgraph/dgraph:tag 27 DTAG=$(echo "$TAG" | tr '/' '-') 28 29 30 # DO NOT change the /tmp/build directory, because Dockerfile also picks up binaries from there. 31 TMP="/tmp/build" 32 rm -Rf $TMP 33 mkdir $TMP 34 35 if [ -z "$TAG" ]; then 36 echo "Must specify which tag to build for." 37 exit 1 38 fi 39 echo "Building Dgraph for tag: $TAG" 40 41 # Stop on first failure. 42 set -e 43 set -o xtrace 44 45 # Check for existence of strip tool. 46 type strip 47 type shasum 48 49 ratel_release="github.com/dgraph-io/ratel/server.ratelVersion" 50 release="github.com/dgraph-io/dgraph/x.dgraphVersion" 51 branch="github.com/dgraph-io/dgraph/x.gitBranch" 52 commitSHA1="github.com/dgraph-io/dgraph/x.lastCommitSHA" 53 commitTime="github.com/dgraph-io/dgraph/x.lastCommitTime" 54 55 echo "Using Go version" 56 go version 57 if [[ ! "$(go version)" =~ $GOVERSION ]]; then 58 echo -e "${RED}Go version is NOT expected. Should be $GOVERSION.${RESET}" 59 exit 1 60 fi 61 62 go get -u github.com/jteeuwen/go-bindata/... 63 go get -d -u golang.org/x/net/context 64 go get -d google.golang.org/grpc 65 go get -u github.com/prometheus/client_golang/prometheus 66 go get -u github.com/dgraph-io/dgo 67 # go get github.com/stretchr/testify/require 68 go get -u github.com/dgraph-io/badger 69 go get -u github.com/golang/protobuf/protoc-gen-go 70 go get -u github.com/gogo/protobuf/protoc-gen-gofast 71 72 pushd $GOPATH/src/google.golang.org/grpc 73 git checkout v1.13.0 74 popd 75 76 basedir=$GOPATH/src/github.com/dgraph-io 77 # Clone Dgraph repo. 78 pushd $basedir 79 git clone https://github.com/dgraph-io/dgraph.git 80 popd 81 82 pushd $basedir/dgraph 83 git pull 84 git checkout $TAG 85 # HEAD here points to whatever is checked out. 86 lastCommitSHA1=$(git rev-parse --short HEAD) 87 gitBranch=$(git rev-parse --abbrev-ref HEAD) 88 lastCommitTime=$(git log -1 --format=%ci) 89 release_version=$TAG 90 popd 91 92 # Regenerate protos. Should not be different from what's checked in. 93 pushd $basedir/dgraph/protos 94 make regenerate 95 if [[ "$(git status --porcelain)" ]]; then 96 echo >&2 "Generated protos different in release." 97 exit 1 98 fi 99 popd 100 101 # Clone ratel repo. 102 pushd $basedir 103 git clone https://github.com/dgraph-io/ratel.git 104 popd 105 106 pushd $basedir/ratel 107 git pull 108 source ~/.nvm/nvm.sh 109 nvm install --lts 110 ./scripts/build.prod.sh 111 ./scripts/test.sh 112 popd 113 114 # Build Windows. 115 pushd $basedir/dgraph/dgraph 116 env GOOS=windows GOARCH=amd64 go get -v -d . 117 env GOOS=windows GOARCH=amd64 go build -v -o dgraph-windows-amd64.exe -ldflags \ 118 "-X $release=$release_version -X $branch=$gitBranch -X $commitSHA1=$lastCommitSHA1 -X '$commitTime=$lastCommitTime'" . 119 mkdir $TMP/windows 120 mv dgraph-windows-amd64.exe $TMP/windows/dgraph.exe 121 popd 122 123 pushd $basedir/badger/badger 124 env GOOS=windows GOARCH=amd64 go get -v -d . 125 env GOOS=windows GOARCH=amd64 go build -v -o badger-windows-amd64.exe . 126 mv badger-windows-amd64.exe $TMP/windows/badger.exe 127 popd 128 129 pushd $basedir/ratel 130 env GOOS=windows GOARCH=amd64 go get -v -d . 131 env GOOS=windows GOARCH=amd64 go build -v -o ratel-windows-amd64.exe -ldflags "-X $ratel_release=$release_version" . 132 mv ratel-windows-amd64.exe $TMP/windows/dgraph-ratel.exe 133 popd 134 135 # Build Darwin. 136 pushd $basedir/dgraph/dgraph 137 env GOOS=darwin GOARCH=amd64 go get -v -d . 138 env GOOS=darwin GOARCH=amd64 go build -v -o dgraph-darwin-amd64 -ldflags \ 139 "-X $release=$release_version -X $branch=$gitBranch -X $commitSHA1=$lastCommitSHA1 -X '$commitTime=$lastCommitTime'" . 140 mkdir $TMP/darwin 141 mv dgraph-darwin-amd64 $TMP/darwin/dgraph 142 popd 143 144 pushd $basedir/badger/badger 145 env GOOS=darwin GOARCH=amd64 go get -v -d . 146 env GOOS=darwin GOARCH=amd64 go build -v -o badger-darwin-amd64 . 147 mv badger-darwin-amd64 $TMP/darwin/badger 148 popd 149 150 pushd $basedir/ratel 151 env GOOS=darwin GOARCH=amd64 go get -v -d . 152 env GOOS=darwin GOARCH=amd64 go build -v -o ratel-darwin-amd64 -v -ldflags "-X $ratel_release=$release_version" . 153 mv ratel-darwin-amd64 $TMP/darwin/dgraph-ratel 154 popd 155 156 # Build Linux. 157 pushd $basedir/dgraph/dgraph 158 env GOOS=linux GOARCH=amd64 go get -v -d . 159 env GOOS=linux GOARCH=amd64 go build -v -o dgraph-linux-amd64 -ldflags \ 160 "-X $release=$release_version -X $branch=$gitBranch -X $commitSHA1=$lastCommitSHA1 -X '$commitTime=$lastCommitTime'" . 161 strip -x dgraph-linux-amd64 162 mkdir $TMP/linux 163 mv dgraph-linux-amd64 $TMP/linux/dgraph 164 popd 165 166 pushd $basedir/badger/badger 167 env GOOS=linux GOARCH=amd64 go get -v -d . 168 env GOOS=linux GOARCH=amd64 go build -v -o badger-linux-amd64 . 169 strip -x badger-linux-amd64 170 mv badger-linux-amd64 $TMP/linux/badger 171 popd 172 173 pushd $basedir/ratel 174 env GOOS=linux GOARCH=amd64 go get -v -d . 175 env GOOS=linux GOARCH=amd64 go build -v -o ratel-linux-amd64 -ldflags "-X $ratel_release=$release_version" . 176 strip -x ratel-linux-amd64 177 mv ratel-linux-amd64 $TMP/linux/dgraph-ratel 178 popd 179 180 createSum () { 181 os=$1 182 echo "Creating checksum for $os" 183 pushd $TMP/$os 184 csum=$(shasum -a 256 dgraph | awk '{print $1}') 185 echo $csum /usr/local/bin/dgraph >> ../dgraph-checksum-$os-amd64.sha256 186 csum=$(shasum -a 256 dgraph-ratel | awk '{print $1}') 187 echo $csum /usr/local/bin/dgraph-ratel >> ../dgraph-checksum-$os-amd64.sha256 188 popd 189 } 190 191 createSum darwin 192 createSum linux 193 194 # Create Docker image. 195 cp $basedir/dgraph/contrib/Dockerfile $TMP 196 pushd $TMP 197 docker build -t dgraph/dgraph:$DTAG . 198 popd 199 rm $TMP/Dockerfile 200 201 # Create the tars and delete the binaries. 202 createTar () { 203 os=$1 204 echo "Creating tar for $os" 205 pushd $TMP/$os 206 tar -zcvf ../dgraph-$os-amd64.tar.gz * 207 popd 208 rm -Rf $TMP/$os 209 } 210 211 createTar windows 212 createTar darwin 213 createTar linux 214 215 echo "Release $TAG is ready." 216 docker run -it dgraph/dgraph:$DTAG dgraph 217 ls -alh $TMP