github.com/huiliang/nomad@v0.2.1-0.20151124023127-7a8b664699ff/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      -cgo \
    48      -output "pkg/{{.OS}}_{{.Arch}}/nomad" \
    49      .
    50  
    51  # Move all the compiled things to the $GOPATH/bin
    52  GOPATH=${GOPATH:-$(go env GOPATH)}
    53  case $(uname) in
    54      CYGWIN*)
    55          GOPATH="$(cygpath $GOPATH)"
    56          ;;
    57  esac
    58  OLDIFS=$IFS
    59  IFS=: MAIN_GOPATH=($GOPATH)
    60  IFS=$OLDIFS
    61  
    62  # Copy our OS/Arch to the bin/ directory
    63  DEV_PLATFORM="./pkg/$(go env GOOS)_$(go env GOARCH)"
    64  for F in $(find ${DEV_PLATFORM} -mindepth 1 -maxdepth 1 -type f); do
    65      cp ${F} bin/
    66      cp ${F} ${MAIN_GOPATH}/bin/
    67  done
    68  
    69  if [[ "x${NOMAD_DEV}" == "x" ]]; then
    70      # Zip and copy to the dist dir
    71      echo "==> Packaging..."
    72      for PLATFORM in $(find ./pkg -mindepth 1 -maxdepth 1 -type d); do
    73          OSARCH=$(basename ${PLATFORM})
    74          echo "--> ${OSARCH}"
    75  
    76          pushd $PLATFORM >/dev/null 2>&1
    77          zip ../${OSARCH}.zip ./*
    78          popd >/dev/null 2>&1
    79      done
    80  fi
    81  
    82  # Done!
    83  echo
    84  echo "==> Results:"
    85  ls -hl bin/