blob: fa62a9baafdc4955c26e7477d8ea5851a9c79de1 [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
12# New image for each build - the Dockerfile might have changed.
13# Rely on the build step cache to avoid costly rebuilds.
14podman build -t ${TAG} build
15
16# Keep this in sync with create_container.sh:
17
18function cleanup {
19 rc=$?
20 ! podman pod rm $POD --force
21 ! podman rmi $TAG --force
22 exit $rc
23}
24
25trap cleanup EXIT
26
27! podman volume create \
28 --opt device=tmpfs \
29 --opt type=tmpfs \
30 --opt o=nodev,exec \
31 bazel-shared-cache
32
33podman pod create --name ${POD}
34
35podman run -d \
36 --pod ${POD} \
37 --ulimit nofile=262144:262144 \
38 --name=${POD}-cockroach \
39 cockroachdb/cockroach:v19.1.5 start --insecure
40
41podman run \
42 -v $(pwd):/work \
43 -v bazel-shared-cache:/user/.cache/bazel/_bazel_root \
44 --device /dev/kvm \
45 --privileged \
46 --pod ${POD} \
47 --name=${POD}-bazel \
48 ${TAG} \
49 $@
50
51cat <<EOF
52{
53 "buildTargetPHID": "${BUILD_PHID}",
54 "type": "pass"
55}
56EOF
57
58env
59
60function conduit() {
61 # Get Phabricator host from Git origin
62 local pattern='ssh://(.+?):([0-9]+)'
63 [[ "$(git remote get-url origin)" =~ $pattern ]];
64 local host=${BASH_REMATCH[1]}
65 local port=${BASH_REMATCH[2]}
66
67 ssh "$host" -p "$port" conduit $@
68}
69
70# Report build results if we made it here successfully
71conduit harbormaster.sendmessage <<EOF
72{"params": "{\"buildTargetPHID\": \"${BUILD_PHID}\", \"type\": \"pass\"}"}
73EOF