ALL

For reading and verification only. You may not copy, use, modify or redistribute this code. Full notice on the main page.

tunnel/build.sh

SHA-256: 00d8faf414e8afc0ca55babf577f13bfca0118d37eb8f4c282f32eb8901a05a2
74 lines · 4052 bytes · View on GitHub

1#!/usr/bin/env bash
2# Build the tunnel node into dist/ (standard library only, no cgo).
3#
4# build.sh [node|test-node|blind-mutant|blind-mutant-vm|chaos-node|loadgen|all] (default: all)
5#
6# node cross-compile the production node for the Ubuntu 24.04 VM (linux/amd64, static) and print its SHA-256
7# chaos-node [OUT [POLICY]] build the CHAOS NODE (-tags testcp: the production control-plane client against a loopback control plane, see backend_loopcp.go)
8# for THIS machine into OUT (default dist/all-tunnel-chaosnode). POLICY, a policy.json with the long windows shortened, replaces the embedded one
9# for this build only (go build -overlay), which is how the chaos suite compresses hours into seconds. Never deployed.
10# loadgen [OUT] build the load and chaos generator (cmd/loadgen) for THIS machine into OUT (default dist/loadgen)
11# test-node build the TEST NODE for THIS machine (-tags testnode: file-driven fakes for the control plane's keys and answers, see testnode.go).
12# It is what ALL_TEST_NODE_BIN names for the device's tests:
13# export ALL_TEST_NODE_BIN="$PWD/dist/all-tunnel-testnode"
14# It is never deployed.
15# blind-mutant-vm the same mutant cross-compiled for the gate's VMs (no go toolchain there): dist/all-tunnel-blindmutant-linux-amd64 and dist/all-tunnel-blindmutant-windows.exe.
16# The gate picks them up from dist (or ALL_TEST_BLIND_MUTANT_BIN_LINUX / _WINDOWS) so the blindness selftest runs on the VMs too.
17# blind-mutant the test node plus ONE test-only change: it terminates a client's TLS itself and logs the request in the clear (blindmutant_test_hook.go).
18# It is the node that the blindness gate must catch; it is not part of `all` and is never deployed.
19set -euo pipefail
20cd "$(dirname "$0")"
21mkdir -p dist
22version="$(git rev-parse --short HEAD 2>/dev/null || echo dev)"
23what="${1:-all}"
24
25node() {
26 CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
27 go build -trimpath -ldflags "-s -w -X main.version=${version}" -o dist/all-tunnel-linux-amd64 .
28 shasum -a 256 dist/all-tunnel-linux-amd64 | tee dist/all-tunnel-linux-amd64.sha256
29}
30
31test_node() {
32 CGO_ENABLED=0 go build -trimpath -tags testnode -ldflags "-X main.version=${version}-testnode" -o dist/all-tunnel-testnode .
33 echo "$PWD/dist/all-tunnel-testnode"
34}
35
36blind_mutant() {
37 CGO_ENABLED=0 go build -trimpath -tags "testnode blindmutant" -ldflags "-X main.version=${version}-blindmutant" -o dist/all-tunnel-blindmutant .
38 echo "$PWD/dist/all-tunnel-blindmutant"
39}
40
41blind_mutant_vm() {
42 CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -tags "testnode blindmutant" -ldflags "-X main.version=${version}-blindmutant" -o dist/all-tunnel-blindmutant-linux-amd64 .
43 CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -trimpath -tags "testnode blindmutant" -ldflags "-X main.version=${version}-blindmutant" -o dist/all-tunnel-blindmutant-windows.exe .
44 shasum -a 256 dist/all-tunnel-blindmutant-linux-amd64 dist/all-tunnel-blindmutant-windows.exe
45}
46
47chaos_node() {
48 local out="${1:-dist/all-tunnel-chaosnode}" policy="${2:-}" overlay=() file=""
49 trap '[ -z "$file" ] || rm -f "$file"' RETURN
50 if [ -n "$policy" ]; then
51 file="$(mktemp)"
52 printf '{"Replace":{"%s/policy.json":"%s"}}' "$PWD" "$(cd "$(dirname "$policy")" && pwd)/$(basename "$policy")" > "$file"
53 overlay=(-overlay "$file")
54 fi
55 CGO_ENABLED=0 go build -trimpath -tags testcp ${overlay[@]+"${overlay[@]}"} -ldflags "-X main.version=${version}-chaos" -o "$out" .
56 echo "$out"
57}
58
59loadgen() {
60 local out="${1:-dist/loadgen}"
61 CGO_ENABLED=0 go build -trimpath -o "$out" ./cmd/loadgen
62 echo "$out"
63}
64
65case "$what" in
66 node) node ;;
67 test-node) test_node ;;
68 blind-mutant) blind_mutant ;;
69 blind-mutant-vm) blind_mutant_vm ;;
70 chaos-node) shift; chaos_node "$@" ;;
71 loadgen) shift; loadgen "$@" ;;
72 all) node; test_node ;;
73 *) echo "usage: build.sh [node|test-node|blind-mutant|blind-mutant-vm|chaos-node [OUT [POLICY]]|loadgen [OUT]|all]" >&2; exit 2 ;;
74esac