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