github.com/google/cloudprober@v0.11.3/tools/build.sh (about) 1 #!/bin/bash -eu 2 # 3 # Copyright 2017 Google Inc. 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 # This script builds cloudprober from source. It expects protobuf's Go code to 18 # be already available (can be done using tools/gen_pb_go.sh). 19 20 PROTOC_VERSION="3.3.0" 21 PROJECT="github.com/google/cloudprober" 22 23 GOPATH=$(go env GOPATH) 24 25 if [ -z "$GOPATH" ]; then 26 echo "Go environment is not setup correctly. Please look at" 27 echo "https://golang.org/doc/code.html to set up Go environment." 28 exit 1 29 fi 30 31 # Change directory to the project workspace in GOPATH 32 project_dir="${GOPATH}/src/${PROJECT}" 33 34 if [ ! -d "${project_dir}" ];then 35 echo "${PROJECT} not found under Go workspace: ${GOPATH}/src. Please download" 36 echo " cloudprober source code from github.com/google/cloudprober and set it " 37 echo "such that it's available at ${project_dir}." 38 exit 1 39 fi 40 41 cd ${project_dir} 42 # Get all dependencies 43 echo "Getting all the dependencies.." 44 echo "======================================================================" 45 go get -t ./... 46 47 # Build everything 48 echo "Build everything..." 49 echo "======================================================================" 50 go build ./... 51 52 # Run tests 53 echo "Running tests..." 54 echo "======================================================================" 55 go test ./... 56 57 # Install cloudprober 58 echo "Build static cloudprober binary.." 59 echo "======================================================================" 60 CGO_ENABLED=0 go build -ldflags '-extldflags "-static"' ./cmd/cloudprober.go