From f4302035054a64bed6508dfde0391467b67038de Mon Sep 17 00:00:00 2001 From: Michael Schurter Date: Wed, 26 Oct 2016 14:55:54 -0700 Subject: [PATCH] Put lxc support behind a flag Since lxc support requires linking to a C lib at compile and runtime I'm putting it behind a build flag to avoid forcing all nomad users to install liblxc (lxc-dev for development). --- client/driver/lxc.go | 2 +- client/driver/lxc_test.go | 2 ++ scripts/build.sh | 18 ++++++++++++++++++ scripts/test.sh | 4 ++-- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/client/driver/lxc.go b/client/driver/lxc.go index 762d5d87c..ffcbc3897 100644 --- a/client/driver/lxc.go +++ b/client/driver/lxc.go @@ -1,4 +1,4 @@ -//+build linux +//+build linux,lxc package driver diff --git a/client/driver/lxc_test.go b/client/driver/lxc_test.go index a50640c75..8a46ec46f 100644 --- a/client/driver/lxc_test.go +++ b/client/driver/lxc_test.go @@ -1,3 +1,5 @@ +//+build linux,lxc + package driver import ( diff --git a/scripts/build.sh b/scripts/build.sh index 10accd062..b82fb35c6 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -46,6 +46,24 @@ gox \ -output "pkg/{{.OS}}_{{.Arch}}/nomad" \ . +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" + else + # Require LXC for release mode + echo "LXC not installed; install lxc-dev to build release binaries" + exit 1 + fi +fi + # Move all the compiled things to the $GOPATH/bin GOPATH=${GOPATH:-$(go env GOPATH)} case $(uname) in diff --git a/scripts/test.sh b/scripts/test.sh index f2baeba24..196b1b310 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -7,11 +7,11 @@ trap "rm -rf $TEMPDIR" EXIT HUP INT QUIT TERM # Build the Nomad binary for the API tests echo "--> Building nomad" -go build -tags "nomad_test" -o $TEMPDIR/nomad || exit 1 +go build -tags "nomad_test lxc" -o $TEMPDIR/nomad || exit 1 # Run the tests echo "--> Running tests" GOBIN="`which go`" sudo -E PATH=$TEMPDIR:$PATH -E GOPATH=$GOPATH -E NOMAD_TEST_RKT=1 \ - $GOBIN test -tags "nomad_test" ${GOTEST_FLAGS:--cover -timeout=900s} $($GOBIN list ./... | grep -v /vendor/) + $GOBIN test -tags "nomad_test lxc" ${GOTEST_FLAGS:--cover -timeout=900s} $($GOBIN list ./... | grep -v /vendor/)