From c5f9144e32b94d054b8e292bb696930fae9a5450 Mon Sep 17 00:00:00 2001 From: Michael Schurter Date: Tue, 24 Jan 2017 16:55:02 -0800 Subject: [PATCH 01/11] Split dev build into its own script The dev build is far simpler than the release build, so move it to its own shell script. This simplifies the release build script slightly as well at the cost of duplicating the version/tag logic. Also don't even try to check for LXC if not running on Linux. I don't think we want to try to support cross-compiling LXC from non-Linux hosts. --- GNUmakefile | 5 ++--- scripts/build-dev.sh | 16 ++++++++++++++++ scripts/build.sh | 43 ++++++++++++++++--------------------------- 3 files changed, 34 insertions(+), 30 deletions(-) create mode 100755 scripts/build-dev.sh diff --git a/GNUmakefile b/GNUmakefile index 117fcf925..b3ad7d3f8 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -14,7 +14,7 @@ GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*") all: test dev: format generate - @NOMAD_DEV=1 sh -c "'$(PWD)/scripts/build.sh'" + @scripts/build-dev.sh bin: generate @sh -c "'$(PWD)/scripts/build.sh'" @@ -45,8 +45,7 @@ format: generate: @echo "--> Running go generate" @go generate $(PACKAGES) - @sed -e 's|github.com/hashicorp/nomad/vendor/github.com/ugorji/go/codec|github.com/ugorji/go/codec|' nomad/structs/structs.generated.go >> structs.gen.tmp - @mv structs.gen.tmp nomad/structs/structs.generated.go + @sed -i -e 's|github.com/hashicorp/nomad/vendor/github.com/ugorji/go/codec|github.com/ugorji/go/codec|' nomad/structs/structs.generated.go vet: @go tool vet 2>/dev/null ; if [ $$? -eq 3 ]; then \ diff --git a/scripts/build-dev.sh b/scripts/build-dev.sh new file mode 100755 index 000000000..abc1126e9 --- /dev/null +++ b/scripts/build-dev.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +set -e + +GIT_COMMIT="$(git rev-parse HEAD)" +GIT_DIRTY="$(test -n "`git status --porcelain`" && echo "+CHANGES" || true)" +LDFLAG="main.GitCommit=${GIT_COMMIT}${GIT_DIRTY}" + +TAGS="nomad_test" +if [[ $(uname) == "Linux" ]]; then + if pkg-config --exists lxc; then + TAGS="$TAGS lxc" + fi +fi + +echo "--> Installing with tags: $TAGS" +go install -ldflags "-X $LDFLAG" -tags "${TAGS}" diff --git a/scripts/build.sh b/scripts/build.sh index 393c1f342..f27623e64 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -29,12 +29,6 @@ rm -f bin/* rm -rf pkg/* mkdir -p bin/ -# If its dev mode, only build for ourself -if [[ "${NOMAD_DEV}" ]]; then - XC_OS=$(go env GOOS) - XC_ARCH=$(go env GOARCH) -fi - # Build! echo "==> Building..." gox \ @@ -47,16 +41,13 @@ gox \ . echo "" -if pkg-config --exists lxc; then - echo "==> Building linux_amd64-lxc..." - go build \ - -tags lxc \ - -ldflags "-X main.GitCommit='${GIT_COMMIT}${GIT_DIRTY}+lxc'" \ - -o "pkg/linux_amd64-lxc/nomad" -else - if [[ "${NOMAD_DEV}" ]]; then - # No lxc in dev mode is no problem - echo "LXC not installed; skipping" +if [[ $(uname) == "Linux" ]]; then + if pkg-config --exists lxc; then + echo "==> Building linux_amd64-lxc..." + go build \ + -tags lxc \ + -ldflags "-X main.GitCommit='${GIT_COMMIT}${GIT_DIRTY}+lxc'" \ + -o "pkg/linux_amd64-lxc/nomad" else # Require LXC for release mode echo "LXC not installed; install lxc-dev to build release binaries" @@ -82,18 +73,16 @@ for F in $(find ${DEV_PLATFORM} -mindepth 1 -maxdepth 1 -type f); do cp ${F} ${MAIN_GOPATH}/bin/ done -if [[ "x${NOMAD_DEV}" == "x" ]]; then - # Zip and copy to the dist dir - echo "==> Packaging..." - for PLATFORM in $(find ./pkg -mindepth 1 -maxdepth 1 -type d); do - OSARCH=$(basename ${PLATFORM}) - echo "--> ${OSARCH}" +# Zip and copy to the dist dir +echo "==> Packaging..." +for PLATFORM in $(find ./pkg -mindepth 1 -maxdepth 1 -type d); do + OSARCH=$(basename ${PLATFORM}) + echo "--> ${OSARCH}" - pushd $PLATFORM >/dev/null 2>&1 - zip ../${OSARCH}.zip ./* - popd >/dev/null 2>&1 - done -fi + pushd $PLATFORM >/dev/null 2>&1 + zip ../${OSARCH}.zip ./* + popd >/dev/null 2>&1 +done # Done! echo From 2f0550cfc4bc8e8ecc745174a10cee25fcec136f Mon Sep 17 00:00:00 2001 From: Michael Schurter Date: Wed, 25 Jan 2017 10:54:08 -0800 Subject: [PATCH 02/11] Cache build deps prior to running tests --- scripts/test.sh | 9 +++++++-- scripts/travis.sh | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/scripts/test.sh b/scripts/test.sh index 097003e76..bc163dd6b 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -1,7 +1,12 @@ #!/usr/bin/env bash set -e -GOTEST_TAGS="nomad_test lxc" +GOTEST_TAGS="nomad_test" +if [[ $(uname) == "Linux" ]]; then + if pkg-config --exists lxc; then + GOTEST_TAGS="$GOTEST_TAGS lxc" + fi +fi # Create a temp dir and clean it up on exit TEMPDIR=`mktemp -d -t nomad-test.XXX` @@ -9,7 +14,7 @@ trap "rm -rf $TEMPDIR" EXIT HUP INT QUIT TERM # Build the Nomad binary for the API tests echo "--> Building nomad" -go build -tags "$GOTEST_TAGS" -o $TEMPDIR/nomad || exit 1 +go build -i -tags "$GOTEST_TAGS" -o $TEMPDIR/nomad || exit 1 # Run the tests echo "--> Running tests" diff --git a/scripts/travis.sh b/scripts/travis.sh index 4bb85a1f2..bc181faae 100755 --- a/scripts/travis.sh +++ b/scripts/travis.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -e -export PING_SLEEP=30 +export PING_SLEEP=60 bash -c "while true; do echo \$(date) - building ...; sleep $PING_SLEEP; done" & PING_LOOP_PID=$! From b9da18efc8085018c92a39118f4c5c2473bb3931 Mon Sep 17 00:00:00 2001 From: Michael Schurter Date: Wed, 25 Jan 2017 11:16:54 -0800 Subject: [PATCH 03/11] Install crosscompile dep to build arm in Vagrant --- Vagrantfile | 2 +- scripts/build.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index 23a8de8b8..591c37c14 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -10,7 +10,7 @@ GO_VERSION="1.7.4" # Install Prereq Packages sudo apt-get update -sudo apt-get install -y build-essential curl git-core mercurial bzr libpcre3-dev pkg-config zip default-jre qemu libc6-dev-i386 silversearcher-ag jq htop vim unzip liblxc1 lxc-dev +sudo apt-get install -y build-essential curl git-core mercurial bzr libpcre3-dev pkg-config zip default-jre qemu gcc-4.8-arm-linux-gnueabihf libc6-dev-i386 silversearcher-ag jq htop vim unzip liblxc1 lxc-dev # Setup go, for development of Nomad SRCROOT="/opt/go" diff --git a/scripts/build.sh b/scripts/build.sh index f27623e64..42f776821 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -19,7 +19,7 @@ GIT_DIRTY="$(test -n "`git status --porcelain`" && echo "+CHANGES" || true)" # XC_ARCH=${XC_ARCH:-"386 amd64"} # XC_OS=${XC_OS:-linux} -XC_ARCH=${XC_ARCH:-"386 amd64"} +XC_ARCH=${XC_ARCH:-"386 amd64 arm arm64"} XC_OS=${XC_OS:-"linux"} XC_EXCLUDE=${XC_EXCLUDE:-"!darwin/arm !darwin/386"} From d84660a047c3ad7dbb49661fc194b80d61ec95f8 Mon Sep 17 00:00:00 2001 From: Michael Schurter Date: Thu, 26 Jan 2017 16:42:17 -0800 Subject: [PATCH 04/11] Split out massive list of cross compile deps+cmds --- Vagrantfile | 15 ++++++++++-- scripts/build.sh | 60 ++++++++++++++++++++++-------------------------- 2 files changed, 41 insertions(+), 34 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index 591c37c14..b1bb330f9 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -8,9 +8,20 @@ DEFAULT_CPU_COUNT = 2 $script = <