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