github.com/jmitchell/nomad@v0.1.3-0.20151007230021-7ab84c2862d8/scripts/build.sh (about) 1 #!/bin/bash 2 # 3 # This script builds the application from source for multiple platforms. 4 set -e 5 6 # Get the parent directory of where this script is. 7 SOURCE="${BASH_SOURCE[0]}" 8 while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done 9 DIR="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )" 10 11 # Change into that directory 12 cd "$DIR" 13 14 # Get the git commit 15 GIT_COMMIT=$(git rev-parse HEAD) 16 GIT_DIRTY=$(test -n "`git status --porcelain`" && echo "+CHANGES" || true) 17 18 # Determine the arch/os combos we're building for 19 XC_ARCH=${XC_ARCH:-"386 amd64 arm"} 20 XC_OS=${XC_OS:-linux darwin windows freebsd openbsd} 21 22 # Install dependencies 23 echo "==> Getting dependencies..." 24 go get ./... 25 26 # Delete the old dir 27 echo "==> Removing old directory..." 28 rm -f bin/* 29 rm -rf pkg/* 30 mkdir -p bin/ 31 32 # If its dev mode, only build for ourself 33 if [[ "${NOMAD_DEV}" ]]; then 34 XC_OS=$(go env GOOS) 35 XC_ARCH=$(go env GOARCH) 36 fi 37 38 # Build! 39 echo "==> Building..." 40 gox \ 41 -os="${XC_OS}" \ 42 -os="!freebsd" \ 43 -os="!openbsd" \ 44 -arch="${XC_ARCH}" \ 45 -osarch="!linux/arm !darwin/386" \ 46 -ldflags "-X main.GitCommit ${GIT_COMMIT}${GIT_DIRTY}" \ 47 -output "pkg/{{.OS}}_{{.Arch}}/nomad" \ 48 . 49 50 # Move all the compiled things to the $GOPATH/bin 51 GOPATH=${GOPATH:-$(go env GOPATH)} 52 case $(uname) in 53 CYGWIN*) 54 GOPATH="$(cygpath $GOPATH)" 55 ;; 56 esac 57 OLDIFS=$IFS 58 IFS=: MAIN_GOPATH=($GOPATH) 59 IFS=$OLDIFS 60 61 # Copy our OS/Arch to the bin/ directory 62 DEV_PLATFORM="./pkg/$(go env GOOS)_$(go env GOARCH)" 63 for F in $(find ${DEV_PLATFORM} -mindepth 1 -maxdepth 1 -type f); do 64 cp ${F} bin/ 65 cp ${F} ${MAIN_GOPATH}/bin/ 66 done 67 68 if [[ "x${NOMAD_DEV}" == "x" ]]; then 69 # Zip and copy to the dist dir 70 echo "==> Packaging..." 71 for PLATFORM in $(find ./pkg -mindepth 1 -maxdepth 1 -type d); do 72 OSARCH=$(basename ${PLATFORM}) 73 echo "--> ${OSARCH}" 74 75 pushd $PLATFORM >/dev/null 2>&1 76 zip ../${OSARCH}.zip ./* 77 popd >/dev/null 2>&1 78 done 79 fi 80 81 # Done! 82 echo 83 echo "==> Results:" 84 ls -hl bin/