github.com/mattyr/nomad@v0.3.3-0.20160919021406-3485a065154a/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  # Delete the old dir
    23  echo "==> Removing old directory..."
    24  rm -f bin/*
    25  rm -rf pkg/*
    26  mkdir -p bin/
    27  
    28  # If its dev mode, only build for ourself
    29  if [[ "${NOMAD_DEV}" ]]; then
    30      XC_OS=$(go env GOOS)
    31      XC_ARCH=$(go env GOARCH)
    32  fi
    33  
    34  # Build!
    35  echo "==> Building..."
    36  gox \
    37      -os="${XC_OS}" \
    38      -os="!dragonfly" \
    39      -os="!netbsd" \
    40      -os="!openbsd" \
    41      -os="!solaris" \
    42      -arch="${XC_ARCH}" \
    43      -cgo \
    44      -osarch="!darwin/386" \
    45      -ldflags "-X main.GitCommit='${GIT_COMMIT}${GIT_DIRTY}'" \
    46      -output "pkg/{{.OS}}_{{.Arch}}/nomad" \
    47      .
    48  
    49  # Move all the compiled things to the $GOPATH/bin
    50  GOPATH=${GOPATH:-$(go env GOPATH)}
    51  case $(uname) in
    52      CYGWIN*)
    53          GOPATH="$(cygpath $GOPATH)"
    54          ;;
    55  esac
    56  OLDIFS=$IFS
    57  IFS=: MAIN_GOPATH=($GOPATH)
    58  IFS=$OLDIFS
    59  
    60  # Copy our OS/Arch to the bin/ directory
    61  DEV_PLATFORM="./pkg/$(go env GOOS)_$(go env GOARCH)"
    62  for F in $(find ${DEV_PLATFORM} -mindepth 1 -maxdepth 1 -type f); do
    63      cp ${F} bin/
    64      cp ${F} ${MAIN_GOPATH}/bin/
    65  done
    66  
    67  if [[ "x${NOMAD_DEV}" == "x" ]]; then
    68      # Zip and copy to the dist dir
    69      echo "==> Packaging..."
    70      for PLATFORM in $(find ./pkg -mindepth 1 -maxdepth 1 -type d); do
    71          OSARCH=$(basename ${PLATFORM})
    72          echo "--> ${OSARCH}"
    73  
    74          pushd $PLATFORM >/dev/null 2>&1
    75          zip ../${OSARCH}.zip ./*
    76          popd >/dev/null 2>&1
    77      done
    78  fi
    79  
    80  # Done!
    81  echo
    82  echo "==> Results:"
    83  ls -hl bin/