From ef6cb1fc7bc2230e03af2ac62e47ffbd1fd27e3a Mon Sep 17 00:00:00 2001 From: Oleh Luchkiv Date: Fri, 26 Sep 2025 09:24:34 -0500 Subject: [PATCH 1/2] Profiles retained locally --- Dockerfile.local | 15 +++++++++++++++ Makefile | 8 +++++++- docker-compose.yml | 10 ++++++---- run-local.sh | 24 +++++++++++++++++++++--- 4 files changed, 49 insertions(+), 8 deletions(-) diff --git a/Dockerfile.local b/Dockerfile.local index 92b4353..35756a4 100644 --- a/Dockerfile.local +++ b/Dockerfile.local @@ -315,6 +315,21 @@ RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \ RUN echo '#!/bin/bash\ncd /opt/eval-server && node examples/with-http-wrapper.js' > /usr/local/bin/start-eval-server.sh && \ chmod +x /usr/local/bin/start-eval-server.sh +# ============================================================================ +# Chromium Data Directory Configuration +# ============================================================================ + +# Environment variable for configurable data directory +ENV CHROMIUM_DATA_DIR=/data + +# Create data directory structure for optional volume mounting +RUN mkdir -p /data/user-data /data/config /data/cache && \ + chown -R kernel:kernel /data && \ + chmod -R 755 /data + +# Declare volume for optional mounting of Chromium profiles and data +VOLUME ["/data"] + # Expose ports EXPOSE 8000 8001 8080 8081 8082 diff --git a/Makefile b/Makefile index 2e640e0..941c528 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,11 @@ help: ## Show this help message @echo "" @echo "Available commands:" @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " %-15s %s\n", $$1, $$2}' + @echo "" + @echo "Chromium Data Persistence:" + @echo " - Set CHROMIUM_DATA_HOST=./chromium-data for persistent browser data" + @echo " - Example: CHROMIUM_DATA_HOST=./chromium-data make run" + @echo " - For docker-compose, uncomment the ./chromium-data:/data volume" init: ## Initialize submodules (run this first) git submodule update --init --recursive @@ -23,7 +28,8 @@ build: init ## Build extended image with DevTools frontend run: ## Run extended container with DevTools (interactive) @echo "🚀 Starting extended kernel-browser with DevTools..." @if [ -n "$(URLS)" ]; then echo "📄 Opening URLs: $(URLS)"; fi - URLS='$(URLS)' ./run-local.sh + @if [ -n "$(CHROMIUM_DATA_HOST)" ]; then echo "🗂️ Using persistent data: $(CHROMIUM_DATA_HOST)"; fi + CHROMIUM_DATA_HOST='$(CHROMIUM_DATA_HOST)' URLS='$(URLS)' ./run-local.sh compose-up: build ## Start with docker-compose (background) @echo "🚀 Starting with docker-compose..." diff --git a/docker-compose.yml b/docker-compose.yml index 42a2744..3416e1f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,8 +2,8 @@ version: '3.8' services: kernel-browser: - image: "kernel-browser:local" - container_name: "kernel-browser-local" + image: "kernel-browser:extended" + container_name: "kernel-browser-extended" privileged: true shm_size: 2gb deploy: @@ -30,13 +30,15 @@ services: - NEKO_WEBRTC_NAT1TO1=127.0.0.1 # Run as kernel user (not root) - RUN_AS_ROOT=false - # Mount Chromium flags - - CHROMIUM_FLAGS=--user-data-dir=/home/kernel/user-data --disable-dev-shm-usage --start-maximized --remote-allow-origins=* --no-sandbox --disable-setuid-sandbox + # Mount Chromium flags (user-data-dir will be set automatically by start-chromium.sh using CHROMIUM_DATA_DIR) + - CHROMIUM_FLAGS=--disable-dev-shm-usage --start-maximized --remote-allow-origins=* --no-sandbox --disable-setuid-sandbox volumes: # Persist recordings in local directory - "./recordings:/recordings" # Mount Chromium flags file (will be created by run script) - "./kernel-images/images/chromium-headful/.tmp/chromium/flags:/chromium/flags:ro" + # Optional: Uncomment to persist Chromium data across container restarts + # - "./chromium-data:/data" tmpfs: - /dev/shm:size=2g restart: unless-stopped diff --git a/run-local.sh b/run-local.sh index 9c89adb..17c1b8d 100755 --- a/run-local.sh +++ b/run-local.sh @@ -37,7 +37,8 @@ export UKC_METRO="dummy-metro-for-local-run" # Local-friendly Chrome flags (less restrictive than cloud) + custom DevTools frontend -export CHROMIUM_FLAGS="--user-data-dir=/home/kernel/user-data --disable-dev-shm-usage --start-maximized --remote-allow-origins=* --no-sandbox --disable-setuid-sandbox --custom-devtools-frontend=http://localhost:8001/" +# Note: --user-data-dir will be set automatically by start-chromium.sh using CHROMIUM_DATA_DIR +export CHROMIUM_FLAGS="--disable-dev-shm-usage --start-maximized --remote-allow-origins=* --no-sandbox --disable-setuid-sandbox --custom-devtools-frontend=http://localhost:8001/" echo "🔧 Configuration:" echo " Image: $IMAGE" @@ -56,12 +57,24 @@ echo "🏃 Starting extended container with kernel-images run system..." # Source common build vars source ../../shared/ensure-common-build-run-vars.sh chromium-headful -# Directory on host where recordings will be saved +# Directory on host where recordings will be saved HOST_RECORDINGS_DIR="$SCRIPT_DIR/recordings" mkdir -p "$HOST_RECORDINGS_DIR" +# Optional Chromium data directory for persistence +# Set CHROMIUM_DATA_HOST to enable volume mounting (e.g., ./chromium-data) +if [[ -n "${CHROMIUM_DATA_HOST:-}" ]]; then + echo "🗂️ Using persistent Chromium data directory: $CHROMIUM_DATA_HOST" + mkdir -p "$CHROMIUM_DATA_HOST" + CHROMIUM_DATA_VOLUME="-v $(realpath "$CHROMIUM_DATA_HOST"):/data" +else + echo "🔄 Using ephemeral Chromium data (no persistence)" + CHROMIUM_DATA_VOLUME="" +fi + # Build Chromium flags file and mount -CHROMIUM_FLAGS_DEFAULT="--user-data-dir=/home/kernel/user-data --disable-dev-shm-usage --disable-gpu --start-maximized --disable-software-rasterizer --remote-allow-origins=*" +# Note: --user-data-dir will be set automatically by start-chromium.sh using CHROMIUM_DATA_DIR +CHROMIUM_FLAGS_DEFAULT="--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 @@ -92,6 +105,11 @@ RUN_ARGS=( --mount type=bind,src="$FLAGS_FILE",dst=/chromium/flags,ro ) +# Add Chromium data volume if specified +if [[ -n "$CHROMIUM_DATA_VOLUME" ]]; then + RUN_ARGS+=( $CHROMIUM_DATA_VOLUME ) +fi + # Add URLS environment variable if provided if [[ -n "${URLS:-}" ]]; then echo " URLs: $URLS" From 0bed2e34ac2dc4842ca1555b66a6775cab1ec1b6 Mon Sep 17 00:00:00 2001 From: Oleh Luchkiv Date: Wed, 8 Oct 2025 11:02:22 -0500 Subject: [PATCH 2/2] =?UTF-8?q?=20=20-=20=E2=9C=85=20Profiles=20persist=20?= =?UTF-8?q?to=20./chromium-data=20by=20default=20=20=20-=20=E2=9C=85=20Chr?= =?UTF-8?q?ome=20version=20and=20all=2041=20profile=20files=20persist=20ac?= =?UTF-8?q?ross=20restarts=20=20=20-=20=E2=9C=85=20Can=20customize=20locat?= =?UTF-8?q?ion=20with=20CHROMIUM=5FDATA=5FHOST=20=20=20-=20=E2=9C=85=20Can?= =?UTF-8?q?=20disable=20with=20CHROMIUM=5FDATA=5FHOST=3D""=20=20=20-=20?= =?UTF-8?q?=E2=9C=85=20Docker-compose=20works=20with=20env=20var=20or=20de?= =?UTF-8?q?fault?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 5 ++++- Makefile | 9 ++++----- docker-compose.yml | 8 ++++---- run-local.sh | 34 ++++++++++++++++++++++------------ 4 files changed, 34 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index d571dba..e92ab63 100644 --- a/.gitignore +++ b/.gitignore @@ -51,4 +51,7 @@ service-account-key.json # Backup files *.bak -*.backup \ No newline at end of file +*.backup + +# Chromium persistent data +chromium-data/ \ No newline at end of file diff --git a/Makefile b/Makefile index 941c528..477e46e 100644 --- a/Makefile +++ b/Makefile @@ -12,9 +12,9 @@ help: ## Show this help message @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " %-15s %s\n", $$1, $$2}' @echo "" @echo "Chromium Data Persistence:" - @echo " - Set CHROMIUM_DATA_HOST=./chromium-data for persistent browser data" - @echo " - Example: CHROMIUM_DATA_HOST=./chromium-data make run" - @echo " - For docker-compose, uncomment the ./chromium-data:/data volume" + @echo " - Browser data persists to ./chromium-data by default" + @echo " - Customize location: CHROMIUM_DATA_HOST=/path/to/data make run" + @echo " - Disable persistence: CHROMIUM_DATA_HOST=\"\" make run" init: ## Initialize submodules (run this first) git submodule update --init --recursive @@ -28,8 +28,7 @@ build: init ## Build extended image with DevTools frontend run: ## Run extended container with DevTools (interactive) @echo "🚀 Starting extended kernel-browser with DevTools..." @if [ -n "$(URLS)" ]; then echo "📄 Opening URLs: $(URLS)"; fi - @if [ -n "$(CHROMIUM_DATA_HOST)" ]; then echo "🗂️ Using persistent data: $(CHROMIUM_DATA_HOST)"; fi - CHROMIUM_DATA_HOST='$(CHROMIUM_DATA_HOST)' URLS='$(URLS)' ./run-local.sh + @./run-local.sh compose-up: build ## Start with docker-compose (background) @echo "🚀 Starting with docker-compose..." diff --git a/docker-compose.yml b/docker-compose.yml index 3416e1f..d54e756 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -30,15 +30,15 @@ services: - NEKO_WEBRTC_NAT1TO1=127.0.0.1 # Run as kernel user (not root) - RUN_AS_ROOT=false - # Mount Chromium flags (user-data-dir will be set automatically by start-chromium.sh using CHROMIUM_DATA_DIR) - - CHROMIUM_FLAGS=--disable-dev-shm-usage --start-maximized --remote-allow-origins=* --no-sandbox --disable-setuid-sandbox + # Chromium flags with persistent data directory + - CHROMIUM_FLAGS=--user-data-dir=/data/user-data --disable-dev-shm-usage --start-maximized --remote-allow-origins=* --no-sandbox --disable-setuid-sandbox volumes: # Persist recordings in local directory - "./recordings:/recordings" # Mount Chromium flags file (will be created by run script) - "./kernel-images/images/chromium-headful/.tmp/chromium/flags:/chromium/flags:ro" - # Optional: Uncomment to persist Chromium data across container restarts - # - "./chromium-data:/data" + # Persist Chromium data across container restarts (set CHROMIUM_DATA_HOST env var to customize path) + - "${CHROMIUM_DATA_HOST:-./chromium-data}:/data" tmpfs: - /dev/shm:size=2g restart: unless-stopped diff --git a/run-local.sh b/run-local.sh index 17c1b8d..cb17e47 100755 --- a/run-local.sh +++ b/run-local.sh @@ -37,8 +37,7 @@ export UKC_METRO="dummy-metro-for-local-run" # Local-friendly Chrome flags (less restrictive than cloud) + custom DevTools frontend -# Note: --user-data-dir will be set automatically by start-chromium.sh using CHROMIUM_DATA_DIR -export CHROMIUM_FLAGS="--disable-dev-shm-usage --start-maximized --remote-allow-origins=* --no-sandbox --disable-setuid-sandbox --custom-devtools-frontend=http://localhost:8001/" +export CHROMIUM_FLAGS="--user-data-dir=/data/user-data --disable-dev-shm-usage --start-maximized --remote-allow-origins=* --no-sandbox --disable-setuid-sandbox --custom-devtools-frontend=http://localhost:8001/" echo "🔧 Configuration:" echo " Image: $IMAGE" @@ -61,20 +60,31 @@ source ../../shared/ensure-common-build-run-vars.sh chromium-headful HOST_RECORDINGS_DIR="$SCRIPT_DIR/recordings" mkdir -p "$HOST_RECORDINGS_DIR" -# Optional Chromium data directory for persistence -# Set CHROMIUM_DATA_HOST to enable volume mounting (e.g., ./chromium-data) -if [[ -n "${CHROMIUM_DATA_HOST:-}" ]]; then - echo "🗂️ Using persistent Chromium data directory: $CHROMIUM_DATA_HOST" - mkdir -p "$CHROMIUM_DATA_HOST" - CHROMIUM_DATA_VOLUME="-v $(realpath "$CHROMIUM_DATA_HOST"):/data" -else +# Chromium data directory for persistence +# Set CHROMIUM_DATA_HOST to customize location (default: ./chromium-data) +# Set CHROMIUM_DATA_HOST="" to disable persistence (ephemeral mode) +if [[ "${CHROMIUM_DATA_HOST+set}" == "set" && -z "$CHROMIUM_DATA_HOST" ]]; then echo "🔄 Using ephemeral Chromium data (no persistence)" CHROMIUM_DATA_VOLUME="" +else + # Default to ./chromium-data if not specified + CHROMIUM_DATA_HOST="${CHROMIUM_DATA_HOST:-$SCRIPT_DIR/chromium-data}" + echo "🗂️ Using persistent Chromium data directory: $CHROMIUM_DATA_HOST" + CHROMIUM_DATA_REAL=$(realpath "$CHROMIUM_DATA_HOST" 2>/dev/null || echo "") + if [[ -z "$CHROMIUM_DATA_REAL" ]]; then + # Path doesn't exist yet, try to create it first + mkdir -p "$CHROMIUM_DATA_HOST" + CHROMIUM_DATA_REAL=$(realpath "$CHROMIUM_DATA_HOST" 2>/dev/null || echo "") + if [[ -z "$CHROMIUM_DATA_REAL" ]]; then + echo "❌ Error: Invalid path $CHROMIUM_DATA_HOST" + exit 1 + fi + fi + CHROMIUM_DATA_VOLUME="${CHROMIUM_DATA_REAL}:/data" fi # Build Chromium flags file and mount -# Note: --user-data-dir will be set automatically by start-chromium.sh using CHROMIUM_DATA_DIR -CHROMIUM_FLAGS_DEFAULT="--disable-dev-shm-usage --disable-gpu --start-maximized --disable-software-rasterizer --remote-allow-origins=*" +CHROMIUM_FLAGS_DEFAULT="--user-data-dir=/data/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 @@ -107,7 +117,7 @@ RUN_ARGS=( # Add Chromium data volume if specified if [[ -n "$CHROMIUM_DATA_VOLUME" ]]; then - RUN_ARGS+=( $CHROMIUM_DATA_VOLUME ) + RUN_ARGS+=( -v "${CHROMIUM_DATA_VOLUME}" ) fi # Add URLS environment variable if provided