Repository navigation
Expand file tree
/
Copy pathqa-native-release.sh
More file actions
executable file
·79 lines (76 loc) · 3.14 KB
/
Copy pathqa-native-release.sh
File metadata and controls
executable file
·79 lines (76 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env bash
set -euo pipefail
if [[ $# != 3 || "$2" != amd64 && "$2" != arm64 ]]; then
echo "Usage: $0 <release archive> <amd64|arm64> <release tag>" >&2
exit 2
fi
file=$(cd -- "$(dirname -- "$1")" && pwd)/$(basename -- "$1")
version=${3#v}
docker run --rm -i --platform "linux/$2" --network none --user 1000:1000 \
--mount "type=bind,source=$file,target=/bundle.tar.gz,readonly" \
--tmpfs /var/lib/doca:uid=1000,gid=1000 \
--env "EXPECTED_VERSION=$version" \
debian:bookworm-slim bash -s <<'RUN'
set -euo pipefail
for command in node npm pnpm docker; do
if command -v "$command" >/dev/null; then exit 1; fi
done
runtime=$(mktemp -d)
tar -xzf /bundle.tar.gz -C "$runtime"
node="$runtime/bin/node"
cd "$runtime/app"
DOCA_SETUP_LOCALE=ja "$node" --import tsx apps/server/src/bootstrap/native-install.ts configure > "$runtime/site.env"
DOCA_BOOTSTRAP_LOGIN=smoke-admin DOCA_BOOTSTRAP_PASSWORD=native-release-smoke-password \
"$node" --env-file="$runtime/site.env" --import tsx apps/server/src/bootstrap/native-install.ts bootstrap
"$node" --env-file="$runtime/site.env" --import tsx apps/server/src/main.ts > "$runtime/service.log" 2>&1 &
service=$!
trap 'kill "$service" 2>/dev/null || true; wait "$service" || true' EXIT
trap 'cat "$runtime/service.log" >&2' ERR
"$node" --input-type=module - <<'JS'
import assert from "node:assert/strict";
import http from "node:http";
import { setTimeout as delay } from "node:timers/promises";
const base = "http://127.0.0.1:39120";
async function request(path, body) {
return await new Promise((resolve, reject) => {
const data = body === undefined ? "" : JSON.stringify(body);
const client = http.request(base + path, {
method: body === undefined ? "GET" : "POST",
headers: { origin: base, "content-type": "application/json", "content-length": Buffer.byteLength(data) },
timeout: 3000,
}, (res) => {
res.setEncoding("utf8");
let text = "";
res.on("data", (chunk) => { text += chunk; });
res.on("error", reject);
res.on("end", () => resolve({ status: res.statusCode, text, headers: res.headers }));
});
client.on("error", reject);
client.on("timeout", () => client.destroy(new Error("request timeout")));
client.end(data);
});
}
let health;
for (let i = 0; i < 60; i++) {
health = await request("/health").catch(() => undefined);
if (health?.status === 200) break;
await delay(500);
}
assert.equal(health?.status, 200);
assert.equal(JSON.parse(health.text).version, process.env.EXPECTED_VERSION);
const bootstrap = await request("/api/v1/bootstrap");
assert.equal(bootstrap.status, 200);
assert.equal(JSON.parse(bootstrap.text).defaultLocale, "ja");
const home = await request("/");
assert.equal(home.status, 200);
const entry = home.text.match(/src="(\/assets\/[^"]+\.js)"/)?.[1];
assert.ok(entry);
assert.equal((await request(entry)).status, 200);
const login = await request("/api/v1/auth/login", {
login: "smoke-admin", password: "native-release-smoke-password",
});
assert.equal(login.status, 200);
assert.ok(login.headers["set-cookie"]?.length);
console.log("Verified Doca " + process.env.EXPECTED_VERSION + " native runtime on " + process.arch);
JS
RUN