Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 52 additions & 6 deletions images/chromium-headful/start-chromium.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,58 @@ echo "Starting Chromium launcher"
# Resolve internal port for the remote debugging interface
INTERNAL_PORT="${INTERNAL_PORT:-9223}"

# Load additional Chromium flags from env and optional file
CHROMIUM_FLAGS="${CHROMIUM_FLAGS:-}"
# Load flags from env (base) and optional runtime overlay file
BASE_FLAGS="${CHROMIUM_FLAGS:-}"
RUNTIME_FLAGS=""
if [[ -f /chromium/flags ]]; then
CHROMIUM_FLAGS="$CHROMIUM_FLAGS $(cat /chromium/flags)"
RUNTIME_FLAGS="$(cat /chromium/flags)"
fi
echo "CHROMIUM_FLAGS: $CHROMIUM_FLAGS"

# When runtime overlay includes extension directives, strip conflicting flags
has_extension_overlay=false
if [[ "$RUNTIME_FLAGS" == *"--load-extension"* || "$RUNTIME_FLAGS" == *"--disable-extensions-except"* ]]; then
has_extension_overlay=true
fi

FILTERED_BASE=()
if [[ "$has_extension_overlay" == true ]]; then
for tok in $BASE_FLAGS; do
case "$tok" in
--disable-extensions|--disable-extensions=*|--load-extension|--load-extension=*|--disable-extensions-except|--disable-extensions-except=*)
;;
*)
FILTERED_BASE+=("$tok")
;;
esac
done
else
for tok in $BASE_FLAGS; do
FILTERED_BASE+=("$tok")
done
fi

COMBINED=()
for tok in "${FILTERED_BASE[@]}"; do
COMBINED+=("$tok")
done
for tok in $RUNTIME_FLAGS; do
COMBINED+=("$tok")
done

declare -A SEEN
DEDUP=()
for tok in "${COMBINED[@]}"; do
if [[ -z "${SEEN[$tok]:-}" && -n "$tok" ]]; then
DEDUP+=("$tok")
SEEN[$tok]=1
fi
done

FINAL_FLAGS="${DEDUP[*]}"

echo "BASE_FLAGS: $BASE_FLAGS"
echo "RUNTIME_FLAGS: $RUNTIME_FLAGS"
echo "FINAL_FLAGS: $FINAL_FLAGS"

# Always use display :1 and point DBus to the system bus socket
export DISPLAY=":1"
Expand All @@ -30,7 +76,7 @@ if [[ "$RUN_AS_ROOT" == "true" ]]; then
--user-data-dir=/home/kernel/user-data \
--password-store=basic \
--no-first-run \
${CHROMIUM_FLAGS:-}
${FINAL_FLAGS:-}
else
echo "Running chromium as kernel user"
exec runuser -u kernel -- env \
Expand All @@ -44,5 +90,5 @@ else
--user-data-dir=/home/kernel/user-data \
--password-store=basic \
--no-first-run \
${CHROMIUM_FLAGS:-}
${FINAL_FLAGS:-}
fi
62 changes: 56 additions & 6 deletions images/chromium-headless/image/start-chromium.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,62 @@ echo "Starting Chromium launcher (headless)"
# Resolve internal port for the remote debugging interface
INTERNAL_PORT="${INTERNAL_PORT:-9223}"

# Load additional Chromium flags from env and optional file
CHROMIUM_FLAGS="${CHROMIUM_FLAGS:-}"
# Load flags from env (base) and optional runtime overlay file
BASE_FLAGS="${CHROMIUM_FLAGS:-}"
RUNTIME_FLAGS=""
if [[ -f /chromium/flags ]]; then
CHROMIUM_FLAGS="$CHROMIUM_FLAGS $(cat /chromium/flags)"
RUNTIME_FLAGS="$(cat /chromium/flags)"
fi
echo "CHROMIUM_FLAGS: $CHROMIUM_FLAGS"

# When runtime overlay includes extension directives, strip conflicting flags
# from the base (e.g. --disable-extensions and prior extension directives)
has_extension_overlay=false
if [[ "$RUNTIME_FLAGS" == *"--load-extension"* || "$RUNTIME_FLAGS" == *"--disable-extensions-except"* ]]; then
has_extension_overlay=true
fi

FILTERED_BASE=()
if [[ "$has_extension_overlay" == true ]]; then
for tok in $BASE_FLAGS; do
case "$tok" in
--disable-extensions|--disable-extensions=*|--load-extension|--load-extension=*|--disable-extensions-except|--disable-extensions-except=*)
# drop conflicting/duplicate extension-related flags from base
;;
*)
FILTERED_BASE+=("$tok")
;;
esac
done
else
# no overlay, keep base as-is
for tok in $BASE_FLAGS; do
FILTERED_BASE+=("$tok")
done
fi

# Merge filtered base with runtime overlay, deduplicating while preserving order
COMBINED=()
for tok in "${FILTERED_BASE[@]}"; do
COMBINED+=("$tok")
done
for tok in $RUNTIME_FLAGS; do
COMBINED+=("$tok")
done

declare -A SEEN
DEDUP=()
for tok in "${COMBINED[@]}"; do
if [[ -z "${SEEN[$tok]:-}" && -n "$tok" ]]; then
DEDUP+=("$tok")
SEEN[$tok]=1
fi
done

FINAL_FLAGS="${DEDUP[*]}"

echo "BASE_FLAGS: $BASE_FLAGS"
echo "RUNTIME_FLAGS: $RUNTIME_FLAGS"
echo "FINAL_FLAGS: $FINAL_FLAGS"

# Always use display :1 and point DBus to the system bus socket
export DISPLAY=":1"
Expand All @@ -28,7 +78,7 @@ if [[ "$RUN_AS_ROOT" == "true" ]]; then
--user-data-dir=/home/kernel/user-data \
--password-store=basic \
--no-first-run \
${CHROMIUM_FLAGS:-}
${FINAL_FLAGS:-}
else
echo "Running chromium as kernel user"
exec runuser -u kernel -- env \
Expand All @@ -44,5 +94,5 @@ else
--user-data-dir=/home/kernel/user-data \
--password-store=basic \
--no-first-run \
${CHROMIUM_FLAGS:-}
${FINAL_FLAGS:-}
fi
9 changes: 8 additions & 1 deletion server/cmd/api/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"sync"
"time"

"github.com/onkernel/kernel-images/server/lib/devtoolsproxy"
"github.com/onkernel/kernel-images/server/lib/logger"
oapi "github.com/onkernel/kernel-images/server/lib/oapi"
"github.com/onkernel/kernel-images/server/lib/recorder"
Expand All @@ -26,16 +27,21 @@ type ApiService struct {
// Process management
procMu sync.RWMutex
procs map[string]*processHandle

// DevTools upstream manager (Chromium supervisord log tailer)
upstreamMgr *devtoolsproxy.UpstreamManager
}

var _ oapi.StrictServerInterface = (*ApiService)(nil)

func New(recordManager recorder.RecordManager, factory recorder.FFmpegRecorderFactory) (*ApiService, error) {
func New(recordManager recorder.RecordManager, factory recorder.FFmpegRecorderFactory, upstreamMgr *devtoolsproxy.UpstreamManager) (*ApiService, error) {
switch {
case recordManager == nil:
return nil, fmt.Errorf("recordManager cannot be nil")
case factory == nil:
return nil, fmt.Errorf("factory cannot be nil")
case upstreamMgr == nil:
return nil, fmt.Errorf("upstreamMgr cannot be nil")
}

return &ApiService{
Expand All @@ -44,6 +50,7 @@ func New(recordManager recorder.RecordManager, factory recorder.FFmpegRecorderFa
defaultRecorderID: "default",
watches: make(map[string]*fsWatch),
procs: make(map[string]*processHandle),
upstreamMgr: upstreamMgr,
}, nil
}

Expand Down
Loading
Loading