Leopold Schabel | 052af2d | 2019-11-06 02:21:53 +0000 | [diff] [blame] | 1 | #!/bin/bash |
Leopold Schabel | 383d4bb | 2019-11-14 22:53:58 +0100 | [diff] [blame] | 2 | # This helper scripts executes all Bazel tests in our CI environment. |
| 3 | # https://phab.monogon.dev/harbormaster/plan/2/ |
Leopold Schabel | 052af2d | 2019-11-06 02:21:53 +0000 | [diff] [blame] | 4 | set -euo pipefail |
| 5 | |
| 6 | BUILD_ID=$1; |
| 7 | BUILD_PHID=$2; |
| 8 | shift; shift; |
| 9 | |
| 10 | TAG=nexantic-build-${BUILD_ID} |
| 11 | POD=nexantic-build-${BUILD_ID} |
| 12 | |
Leopold Schabel | 1626705 | 2019-11-06 14:43:21 +0000 | [diff] [blame] | 13 | # We keep one Bazel build cache per working copy to avoid concurrency issues |
| 14 | # (we cannot run multiple Bazel servers on a given _bazel_root) |
| 15 | function getWorkingCopyID { |
| 16 | local pattern='/var/drydock/workingcopy-([0-9]+)/' |
| 17 | [[ "$(pwd)" =~ $pattern ]] |
| 18 | echo ${BASH_REMATCH[1]} |
| 19 | } |
| 20 | |
| 21 | CACHE_VOLUME=bazel-cache-$(getWorkingCopyID) |
| 22 | |
Leopold Schabel | 052af2d | 2019-11-06 02:21:53 +0000 | [diff] [blame] | 23 | # New image for each build - the Dockerfile might have changed. |
| 24 | # Rely on the build step cache to avoid costly rebuilds. |
| 25 | podman build -t ${TAG} build |
| 26 | |
| 27 | # Keep this in sync with create_container.sh: |
| 28 | |
| 29 | function cleanup { |
| 30 | rc=$? |
| 31 | ! podman pod rm $POD --force |
| 32 | ! podman rmi $TAG --force |
| 33 | exit $rc |
| 34 | } |
| 35 | |
| 36 | trap cleanup EXIT |
| 37 | |
Leopold Schabel | 1626705 | 2019-11-06 14:43:21 +0000 | [diff] [blame] | 38 | ! podman volume create --opt o=nodev,exec ${CACHE_VOLUME} |
Leopold Schabel | 052af2d | 2019-11-06 02:21:53 +0000 | [diff] [blame] | 39 | |
| 40 | podman pod create --name ${POD} |
| 41 | |
| 42 | podman run -d \ |
| 43 | --pod ${POD} \ |
| 44 | --ulimit nofile=262144:262144 \ |
| 45 | --name=${POD}-cockroach \ |
| 46 | cockroachdb/cockroach:v19.1.5 start --insecure |
| 47 | |
| 48 | podman run \ |
| 49 | -v $(pwd):/work \ |
Leopold Schabel | 5b87d7b | 2019-11-06 14:56:30 +0000 | [diff] [blame] | 50 | -v ${CACHE_VOLUME}:/user/.cache/bazel/_bazel_root \ |
Leopold Schabel | 052af2d | 2019-11-06 02:21:53 +0000 | [diff] [blame] | 51 | --device /dev/kvm \ |
| 52 | --privileged \ |
| 53 | --pod ${POD} \ |
| 54 | --name=${POD}-bazel \ |
| 55 | ${TAG} \ |
Leopold Schabel | 383d4bb | 2019-11-14 22:53:58 +0100 | [diff] [blame] | 56 | bazel test //... |
Leopold Schabel | 052af2d | 2019-11-06 02:21:53 +0000 | [diff] [blame] | 57 | |
Leopold Schabel | 052af2d | 2019-11-06 02:21:53 +0000 | [diff] [blame] | 58 | function conduit() { |
| 59 | # Get Phabricator host from Git origin |
| 60 | local pattern='ssh://(.+?):([0-9]+)' |
| 61 | [[ "$(git remote get-url origin)" =~ $pattern ]]; |
| 62 | local host=${BASH_REMATCH[1]} |
| 63 | local port=${BASH_REMATCH[2]} |
| 64 | |
| 65 | ssh "$host" -p "$port" conduit $@ |
| 66 | } |
| 67 | |
| 68 | # Report build results if we made it here successfully |
| 69 | conduit harbormaster.sendmessage <<EOF |
| 70 | {"params": "{\"buildTargetPHID\": \"${BUILD_PHID}\", \"type\": \"pass\"}"} |
| 71 | EOF |