From 26153d9919834fe4ee1dc273d071deea5d45c419 Mon Sep 17 00:00:00 2001 From: Grimes Date: Mon, 28 May 2018 14:07:30 -0700 Subject: [PATCH] Avoid docker buildkite plugin, which is not supported by bkrun --- ci/buildkite.yml | 33 +++------------------------------ ci/coverage.sh | 21 ++++++++------------- ci/docker-run.sh | 41 +++++++++++++++++++++++++++++++++++++++++ ci/publish.sh | 4 ++-- ci/shellcheck.sh | 7 ++----- 5 files changed, 56 insertions(+), 50 deletions(-) create mode 100755 ci/docker-run.sh diff --git a/ci/buildkite.yml b/ci/buildkite.yml index d1cacc25c0..56d4a54acc 100644 --- a/ci/buildkite.yml +++ b/ci/buildkite.yml @@ -1,32 +1,12 @@ steps: - command: "ci/coverage.sh" name: "coverage [public]" - # TODO: Run coverage in a docker image rather than assuming kcov/cargo-kcov - # is installed on the build agent... - #plugins: - # docker#v1.1.1: - # image: "rust" - # user: "998:997" # buildkite-agent:buildkite-agent - # environment: - # - CODECOV_TOKEN - - command: "ci/test-stable.sh" + - command: "ci/docker-run.sh rust ci/test-stable.sh" name: "stable [public]" - plugins: - docker#v1.1.1: - image: "rust" - user: "998:997" # buildkite-agent:buildkite-agent - - command: "ci/test-nightly.sh || true" + - command: "ci/docker-run.sh rustlang/rust:nightly ci/test-nightly.sh || true" name: "nightly - FAILURES IGNORED [public]" - plugins: - docker#v1.1.1: - image: "rustlang/rust:nightly" - user: "998:997" # buildkite-agent:buildkite-agent - - command: "ci/test-ignored.sh" + - command: "ci/docker-run.sh rust ci/test-ignored.sh" name: "ignored [public]" - plugins: - docker#v1.1.1: - image: "rust" - user: "998:997" # buildkite-agent:buildkite-agent - command: "ci/test-cuda.sh" name: "cuda" - command: "ci/shellcheck.sh" @@ -34,10 +14,3 @@ steps: - wait - command: "ci/publish.sh" name: "publish release artifacts" - plugins: - docker#v1.1.1: - image: "rust" - user: "998:997" # buildkite-agent:buildkite-agent - environment: - - BUILDKITE_TAG - - CRATES_IO_TOKEN diff --git a/ci/coverage.sh b/ci/coverage.sh index dfae3ca66b..fc6098fc3b 100755 --- a/ci/coverage.sh +++ b/ci/coverage.sh @@ -2,20 +2,15 @@ cd "$(dirname "$0")/.." -if [[ -r ~/.cargo/env ]]; then - # Pick up local install of kcov/cargo-kcov - # shellcheck disable=SC1090 - source ~/.cargo/env -fi +ci/docker-run.sh evilmachines/rust-cargo-kcov \ + bash -exc "\ + export RUST_BACKTRACE=1; \ + cargo build --verbose; \ + cargo kcov --lib --verbose; \ + " -rustc --version -cargo --version -kcov --version -cargo-kcov --version - -export RUST_BACKTRACE=1 -cargo build -cargo kcov --lib +echo Coverage report: +ls -l target/cov/index.html if [[ -z "$CODECOV_TOKEN" ]]; then echo CODECOV_TOKEN undefined diff --git a/ci/docker-run.sh b/ci/docker-run.sh new file mode 100755 index 0000000000..889d568b76 --- /dev/null +++ b/ci/docker-run.sh @@ -0,0 +1,41 @@ +#!/bin/bash -e + +usage() { + echo "Usage: $0 [docker image name] [command]" + echo + echo Runs command in the specified docker image with + echo a CI-appropriate environment + echo +} + +cd "$(dirname "$0")/.." + +IMAGE="$1" +if [[ -z "$IMAGE" ]]; then + echo Error: image not defined + exit 1 +fi + +docker pull "$IMAGE" +shift + +ARGS=(--workdir /solana --volume "$PWD:/solana" --rm) + +ARGS+=(--env "CARGO_HOME=/solana/.cargo") + +# kcov tries to set the personality of the binary which docker +# doesn't allow by default. +ARGS+=(--security-opt "seccomp=unconfined") + +# Ensure files are created with the current host uid/gid +ARGS+=(--user "$(id -u):$(id -g)") + +# Environment variables to propagate into the container +ARGS+=( + --env BUILDKITE_TAG + --env CODECOV_TOKEN + --env CRATES_IO_TOKEN +) + +set -x +docker run "${ARGS[@]}" "$IMAGE" "$@" diff --git a/ci/publish.sh b/ci/publish.sh index fb700a6ae7..3dd0832c28 100755 --- a/ci/publish.sh +++ b/ci/publish.sh @@ -12,8 +12,8 @@ if [[ -z "$CRATES_IO_TOKEN" ]]; then exit 1 fi -cargo package # TODO: Ensure the published version matches the contents of BUILDKITE_TAG -cargo publish --token "$CRATES_IO_TOKEN" +ci/docker-run.sh rust \ + bash -exc "cargo package; cargo publish --token $CRATES_IO_TOKEN" exit 0 diff --git a/ci/shellcheck.sh b/ci/shellcheck.sh index 551a029146..808e1724c2 100755 --- a/ci/shellcheck.sh +++ b/ci/shellcheck.sh @@ -5,10 +5,7 @@ cd "$(dirname "$0")/.." set -x -docker pull koalaman/shellcheck -find -E . -name "*.sh" -not -regex ".*/(.cargo|node_modules)/.*" -print0 \ +find . -name "*.sh" -not -regex ".*/.cargo/.*" -not -regex ".*/node_modules/.*" -print0 \ | xargs -0 \ - docker run -w /work -v "$PWD:/work" \ - koalaman/shellcheck --color=always --external-sources --shell=bash - + ci/docker-run.sh koalaman/shellcheck --color=always --external-sources --shell=bash exit 0