-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathrun-unikernel.sh
More file actions
executable file
·84 lines (73 loc) · 2.71 KB
/
run-unikernel.sh
File metadata and controls
executable file
·84 lines (73 loc) · 2.71 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
80
81
82
83
84
#!/usr/bin/env bash
set -euo pipefail
# Move to the script's directory so relative paths work regardless of the caller CWD
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
cd "$SCRIPT_DIR"
source ../../shared/ensure-common-build-run-vars.sh chromium-headful
kraft cloud inst rm $NAME || true
# Name for the Kraft Cloud volume that will carry Chromium flags
volume_name="${NAME}-flags"
# ------------------------------------------------------------------------------
# Prepare Kraft Cloud volume containing Chromium flags
# ------------------------------------------------------------------------------
# Build a temporary directory with a single file "flags" that holds all
# Chromium runtime flags. This directory will be imported into a Kraft Cloud
# volume which we then mount into the image at /chromium.
# RUN_AS_ROOT defaults to true in unikernel (for now, until we figure it out)
RUN_AS_ROOT="${RUN_AS_ROOT:-true}"
chromium_flags_default="--user-data-dir=/home/kernel/user-data --disable-dev-shm-usage --disable-gpu --start-maximized --disable-software-rasterizer --remote-allow-origins=*"
if [[ "$RUN_AS_ROOT" == "true" ]]; then
chromium_flags_default="$chromium_flags_default --no-sandbox --no-zygote"
fi
CHROMIUM_FLAGS="${CHROMIUM_FLAGS:-$chromium_flags_default}"
rm -rf .tmp/chromium
mkdir -p .tmp/chromium
FLAGS_DIR=".tmp/chromium"
echo "$CHROMIUM_FLAGS" > "$FLAGS_DIR/flags"
# Re-create the volume from scratch every run
kraft cloud volume rm "$volume_name" || true
kraft cloud volume create -n "$volume_name" -s 16M
# Import the flags directory into the freshly created volume
kraft cloud volume import --image onkernel/utils/volimport:1.0 -s "$FLAGS_DIR" -v "$volume_name"
# Ensure the temp directory is cleaned up on exit
trap 'rm -rf "$FLAGS_DIR"' EXIT
deploy_args=(
--vcpus 4
-M 4096
-p 9222:9222/tls
-p 444:10001/tls
-e DISPLAY_NUM=1
-e HEIGHT=768
-e WIDTH=1024
-e RUN_AS_ROOT="$RUN_AS_ROOT"
-e LOG_CDP_MESSAGES=true
-v "$volume_name":/chromium
-n "$NAME"
)
# Add XDS environment variables if provided
if [[ -n "${INST_NAME:-}" ]]; then
deploy_args+=(-e "INST_NAME=$INST_NAME")
fi
if [[ -n "${METRO_NAME:-}" ]]; then
deploy_args+=(-e "METRO_NAME=$METRO_NAME")
fi
if [[ -n "${XDS_SERVER:-}" ]]; then
deploy_args+=(-e "XDS_SERVER=$XDS_SERVER")
fi
if [[ -n "${XDS_JWT:-}" ]]; then
deploy_args+=(-e "XDS_JWT=$XDS_JWT")
fi
if [[ "${ENABLE_WEBRTC:-}" == "true" ]]; then
echo "Deploying with WebRTC enabled"
kraft cloud inst create --start \
"${deploy_args[@]}" \
-p 443:8080/http+tls \
-e ENABLE_WEBRTC=true \
-e NEKO_ICESERVERS="${NEKO_ICESERVERS:-}" "$IMAGE"
else
echo "Deploying without WebRTC"
kraft cloud inst create --start \
"${deploy_args[@]}" \
-p 443:6080/http+tls \
"$IMAGE"
fi