diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..c640a566 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,15 @@ +language: minimal +sudo: required +services: + - docker +install: + - gem install travis --no-rdoc --no-ri +matrix: + fast_finish: true +env: + - TEST_TYPE=bazel.build +script: ./ci/ci_steps.sh + +branches: + only: + - master diff --git a/ci/build_setup.sh b/ci/build_setup.sh new file mode 100755 index 00000000..62706cf3 --- /dev/null +++ b/ci/build_setup.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# Configure environment variables for Bazel build and test. + +set -e + +NUM_CPUS=`grep -c ^processor /proc/cpuinfo` + +export ENVOY_SRCDIR=/source + +export BUILD_DIR=/build +if [[ ! -d "${BUILD_DIR}" ]] +then + echo "${BUILD_DIR} mount missing - did you forget -v :${BUILD_DIR}?" + exit 1 +fi + +# Environment setup. +export USER=bazel +export TEST_TMPDIR=/build/tmp +export BAZEL="bazel" + +# Not sandboxing, since non-privileged Docker can't do nested namespaces. +BAZEL_OPTIONS="--package_path %workspace%:/source" +export BAZEL_QUERY_OPTIONS="${BAZEL_OPTIONS}" +export BAZEL_BUILD_OPTIONS="--strategy=Genrule=standalone --spawn_strategy=standalone \ + --verbose_failures ${BAZEL_OPTIONS} --jobs=${NUM_CPUS}" +export BAZEL_TEST_OPTIONS="${BAZEL_BUILD_OPTIONS} --cache_test_results=no --test_output=all" +[[ "${BAZEL_EXPUNGE}" == "1" ]] && "${BAZEL}" clean --expunge + +function cleanup() { + # Remove build artifacts. This doesn't mess with incremental builds as these + # are just symlinks. + rm -f "${ENVOY_SRCDIR}"/bazel-* +} +trap cleanup EXIT diff --git a/ci/ci_steps.sh b/ci/ci_steps.sh new file mode 100755 index 00000000..8767af3e --- /dev/null +++ b/ci/ci_steps.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +# Script that lists all the steps take by the CI system when doing Envoy builds. +set -e + +# We reuse the https://github.com/lyft/envoy/ CI image here to get Bazel. +ENVOY_BUILD_SHA=22c55f8ec756c5ddeb26c3424e128a91aec23116 + +# Lint travis file. +travis lint .travis.yml --skip-completion-check + +# Where the Envoy build takes place. +export ENVOY_API_BUILD_DIR=/tmp/envoy-api-docker-build + +# Do a build matrix with different types of builds docs, coverage, bazel.release, etc. +docker run -t -i -v "$ENVOY_API_BUILD_DIR":/build -v $TRAVIS_BUILD_DIR:/source \ + lyft/envoy-build:$ENVOY_BUILD_SHA /bin/bash -c "cd /source && ci/do_ci.sh $TEST_TYPE" diff --git a/ci/do_ci.sh b/ci/do_ci.sh new file mode 100755 index 00000000..7c5cfff1 --- /dev/null +++ b/ci/do_ci.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# Run a CI build/test target, e.g. docs, asan. + +set -e + +. "$(dirname "$0")"/build_setup.sh + +echo "building using ${NUM_CPUS} CPUs" + +if [[ "$1" == "bazel.build" ]]; then + echo "bazel build..." + bazel --batch build ${BAZEL_BUILD_OPTIONS} //... + exit 0 +else + echo "Invalid do_ci.sh target, see ci/README.md for valid targets." + exit 1 +fi diff --git a/ci/run_envoy_docker.sh b/ci/run_envoy_docker.sh new file mode 100755 index 00000000..c1411870 --- /dev/null +++ b/ci/run_envoy_docker.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +set -e + +[[ -z "${IMAGE_ID}" ]] && IMAGE_ID="latest" +[[ -z "${ENVOY_API_DOCKER_BUILD_DIR}" ]] && ENVOY_API_DOCKER_BUILD_DIR=/tmp/envoy-api-docker-build + +mkdir -p "${ENVOY_API_DOCKER_BUILD_DIR}" +docker pull lyft/envoy-build:"${IMAGE_ID}" +docker run -t -i -u $(id -u):$(id -g) -v "${ENVOY_API_DOCKER_BUILD_DIR}":/build \ + -v "$PWD":/source lyft/envoy-build:"${IMAGE_ID}" /bin/bash -c "cd source && $*"