github.com/maier/nomad@v0.4.1-0.20161110003312-a9e3d0b8549d/scripts/build.sh (about) 1 #!/usr/bin/env 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"} 20 # XC_OS=${XC_OS:-linux} 21 22 XC_ARCH=${XC_ARCH:-"386 amd64 arm"} 23 XC_OS=${XC_OS:-"darwin linux windows"} 24 XC_EXCLUDE=${XC_EXCLUDE:-"!darwin/arm !darwin/386"} 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 -arch="${XC_ARCH}" \ 43 -osarch="${XC_EXCLUDE}" \ 44 -cgo \ 45 -ldflags "-X main.GitCommit='${GIT_COMMIT}${GIT_DIRTY}'" \ 46 -output "pkg/{{.OS}}_{{.Arch}}/nomad" \ 47 . 48 49 echo "" 50 if pkg-config --exists lxc; then 51 echo "==> Building linux_amd64_lxc..." 52 go build \ 53 -tags lxc \ 54 -ldflags "-X main.GitCommit='${GIT_COMMIT}${GIT_DIRTY}+lxc'" \ 55 -o "pkg/linux_amd64_lxc/nomad" 56 else 57 if [[ "${NOMAD_DEV}" ]]; then 58 # No lxc in dev mode is no problem 59 echo "LXC not installed; skipping" 60 else 61 # Require LXC for release mode 62 echo "LXC not installed; install lxc-dev to build release binaries" 63 exit 1 64 fi 65 fi 66 67 # Move all the compiled things to the $GOPATH/bin 68 GOPATH=${GOPATH:-$(go env GOPATH)} 69 case $(uname) in 70 CYGWIN*) 71 GOPATH="$(cygpath $GOPATH)" 72 ;; 73 esac 74 OLDIFS=$IFS 75 IFS=: MAIN_GOPATH=($GOPATH) 76 IFS=$OLDIFS 77 78 # Copy our OS/Arch to the bin/ directory 79 DEV_PLATFORM="./pkg/$(go env GOOS)_$(go env GOARCH)" 80 for F in $(find ${DEV_PLATFORM} -mindepth 1 -maxdepth 1 -type f); do 81 cp ${F} bin/ 82 cp ${F} ${MAIN_GOPATH}/bin/ 83 done 84 85 if [[ "x${NOMAD_DEV}" == "x" ]]; then 86 # Zip and copy to the dist dir 87 echo "==> Packaging..." 88 for PLATFORM in $(find ./pkg -mindepth 1 -maxdepth 1 -type d); do 89 OSARCH=$(basename ${PLATFORM}) 90 echo "--> ${OSARCH}" 91 92 pushd $PLATFORM >/dev/null 2>&1 93 zip ../${OSARCH}.zip ./* 94 popd >/dev/null 2>&1 95 done 96 fi 97 98 # Done! 99 echo 100 echo "==> Results:" 101 ls -hl bin/