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/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..477e46e 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 " - 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 @@ -23,7 +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 - 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 42a2744..d54e756 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 + # 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" + # 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 9c89adb..cb17e47 100755 --- a/run-local.sh +++ b/run-local.sh @@ -37,7 +37,7 @@ 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/" +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" @@ -56,12 +56,35 @@ 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" +# 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 -CHROMIUM_FLAGS_DEFAULT="--user-data-dir=/home/kernel/user-data --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 @@ -92,6 +115,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+=( -v "${CHROMIUM_DATA_VOLUME}" ) +fi + # Add URLS environment variable if provided if [[ -n "${URLS:-}" ]]; then echo " URLs: $URLS"