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 | |
| 12 | # New image for each build - the Dockerfile might have changed. |
| 13 | # Rely on the build step cache to avoid costly rebuilds. |
| 14 | podman build -t ${TAG} build |
| 15 | |
| 16 | # Keep this in sync with create_container.sh: |
| 17 | |
| 18 | function cleanup { |
| 19 | rc=$? |
| 20 | ! podman pod rm $POD --force |
| 21 | ! podman rmi $TAG --force |
| 22 | exit $rc |
| 23 | } |
| 24 | |
| 25 | trap 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 | |
| 33 | podman pod create --name ${POD} |
| 34 | |
| 35 | podman run -d \ |
| 36 | --pod ${POD} \ |
| 37 | --ulimit nofile=262144:262144 \ |
| 38 | --name=${POD}-cockroach \ |
| 39 | cockroachdb/cockroach:v19.1.5 start --insecure |
| 40 | |
| 41 | podman 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 | |
| 51 | cat <<EOF |
| 52 | { |
| 53 | "buildTargetPHID": "${BUILD_PHID}", |
| 54 | "type": "pass" |
| 55 | } |
| 56 | EOF |
| 57 | |
| 58 | env |
| 59 | |
| 60 | function 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 |
| 71 | conduit harbormaster.sendmessage <<EOF |
| 72 | {"params": "{\"buildTargetPHID\": \"${BUILD_PHID}\", \"type\": \"pass\"}"} |
| 73 | EOF |