blob: f9e0c12362a511500cd74f2ee1d7bcf496748aef [file] [log] [blame]
Leopold Schabel052af2d2019-11-06 02:21:53 +00001#!/bin/bash
2# This script is executed by our CI
3set -euo pipefail
4
5BUILD_ID=$1;
6BUILD_PHID=$2;
7shift; shift;
8
9TAG=nexantic-build-${BUILD_ID}
10POD=nexantic-build-${BUILD_ID}
11
Leopold Schabel16267052019-11-06 14:43:21 +000012# 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)
14function getWorkingCopyID {
15 local pattern='/var/drydock/workingcopy-([0-9]+)/'
16 [[ "$(pwd)" =~ $pattern ]]
17 echo ${BASH_REMATCH[1]}
18}
19
20CACHE_VOLUME=bazel-cache-$(getWorkingCopyID)
21
Leopold Schabel052af2d2019-11-06 02:21:53 +000022# New image for each build - the Dockerfile might have changed.
23# Rely on the build step cache to avoid costly rebuilds.
24podman build -t ${TAG} build
25
26# Keep this in sync with create_container.sh:
27
28function cleanup {
29 rc=$?
30 ! podman pod rm $POD --force
31 ! podman rmi $TAG --force
32 exit $rc
33}
34
35trap cleanup EXIT
36
Leopold Schabel16267052019-11-06 14:43:21 +000037! podman volume create --opt o=nodev,exec ${CACHE_VOLUME}
Leopold Schabel052af2d2019-11-06 02:21:53 +000038
39podman pod create --name ${POD}
40
41podman run -d \
42 --pod ${POD} \
43 --ulimit nofile=262144:262144 \
44 --name=${POD}-cockroach \
45 cockroachdb/cockroach:v19.1.5 start --insecure
46
47podman run \
48 -v $(pwd):/work \
Leopold Schabel5b87d7b2019-11-06 14:56:30 +000049 -v ${CACHE_VOLUME}:/user/.cache/bazel/_bazel_root \
Leopold Schabel052af2d2019-11-06 02:21:53 +000050 --device /dev/kvm \
51 --privileged \
52 --pod ${POD} \
53 --name=${POD}-bazel \
54 ${TAG} \
55 $@
56
Leopold Schabel052af2d2019-11-06 02:21:53 +000057function 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
68conduit harbormaster.sendmessage <<EOF
69{"params": "{\"buildTargetPHID\": \"${BUILD_PHID}\", \"type\": \"pass\"}"}
70EOF