Skip to content

Commit 2253697

Browse files
authored
Merge pull request #7 from BrowserOperator/feat/profiles-retained-locally
Feat/profiles retained locally
2 parents fe643ef + 0bed2e3 commit 2253697

File tree

5 files changed

+62
-9
lines changed

5 files changed

+62
-9
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,7 @@ service-account-key.json
5151

5252
# Backup files
5353
*.bak
54-
*.backup
54+
*.backup
55+
56+
# Chromium persistent data
57+
chromium-data/

Dockerfile.local

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,21 @@ RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \
315315
RUN echo '#!/bin/bash\ncd /opt/eval-server && node examples/with-http-wrapper.js' > /usr/local/bin/start-eval-server.sh && \
316316
chmod +x /usr/local/bin/start-eval-server.sh
317317

318+
# ============================================================================
319+
# Chromium Data Directory Configuration
320+
# ============================================================================
321+
322+
# Environment variable for configurable data directory
323+
ENV CHROMIUM_DATA_DIR=/data
324+
325+
# Create data directory structure for optional volume mounting
326+
RUN mkdir -p /data/user-data /data/config /data/cache && \
327+
chown -R kernel:kernel /data && \
328+
chmod -R 755 /data
329+
330+
# Declare volume for optional mounting of Chromium profiles and data
331+
VOLUME ["/data"]
332+
318333
# Expose ports
319334
EXPOSE 8000 8001 8080 8081 8082
320335

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ help: ## Show this help message
1010
@echo ""
1111
@echo "Available commands:"
1212
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " %-15s %s\n", $$1, $$2}'
13+
@echo ""
14+
@echo "Chromium Data Persistence:"
15+
@echo " - Browser data persists to ./chromium-data by default"
16+
@echo " - Customize location: CHROMIUM_DATA_HOST=/path/to/data make run"
17+
@echo " - Disable persistence: CHROMIUM_DATA_HOST=\"\" make run"
1318

1419
init: ## Initialize submodules (run this first)
1520
git submodule update --init --recursive
@@ -23,7 +28,7 @@ build: init ## Build extended image with DevTools frontend
2328
run: ## Run extended container with DevTools (interactive)
2429
@echo "🚀 Starting extended kernel-browser with DevTools..."
2530
@if [ -n "$(URLS)" ]; then echo "📄 Opening URLs: $(URLS)"; fi
26-
URLS='$(URLS)' ./run-local.sh
31+
@./run-local.sh
2732

2833
compose-up: build ## Start with docker-compose (background)
2934
@echo "🚀 Starting with docker-compose..."

docker-compose.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ version: '3.8'
22

33
services:
44
kernel-browser:
5-
image: "kernel-browser:local"
6-
container_name: "kernel-browser-local"
5+
image: "kernel-browser:extended"
6+
container_name: "kernel-browser-extended"
77
privileged: true
88
shm_size: 2gb
99
deploy:
@@ -30,13 +30,15 @@ services:
3030
- NEKO_WEBRTC_NAT1TO1=127.0.0.1
3131
# Run as kernel user (not root)
3232
- RUN_AS_ROOT=false
33-
# Mount Chromium flags
34-
- CHROMIUM_FLAGS=--user-data-dir=/home/kernel/user-data --disable-dev-shm-usage --start-maximized --remote-allow-origins=* --no-sandbox --disable-setuid-sandbox
33+
# Chromium flags with persistent data directory
34+
- CHROMIUM_FLAGS=--user-data-dir=/data/user-data --disable-dev-shm-usage --start-maximized --remote-allow-origins=* --no-sandbox --disable-setuid-sandbox
3535
volumes:
3636
# Persist recordings in local directory
3737
- "./recordings:/recordings"
3838
# Mount Chromium flags file (will be created by run script)
3939
- "./kernel-images/images/chromium-headful/.tmp/chromium/flags:/chromium/flags:ro"
40+
# Persist Chromium data across container restarts (set CHROMIUM_DATA_HOST env var to customize path)
41+
- "${CHROMIUM_DATA_HOST:-./chromium-data}:/data"
4042
tmpfs:
4143
- /dev/shm:size=2g
4244
restart: unless-stopped

run-local.sh

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export UKC_METRO="dummy-metro-for-local-run"
3737

3838

3939
# Local-friendly Chrome flags (less restrictive than cloud) + custom DevTools frontend
40-
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/"
40+
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/"
4141

4242
echo "🔧 Configuration:"
4343
echo " Image: $IMAGE"
@@ -56,12 +56,35 @@ echo "🏃 Starting extended container with kernel-images run system..."
5656
# Source common build vars
5757
source ../../shared/ensure-common-build-run-vars.sh chromium-headful
5858

59-
# Directory on host where recordings will be saved
59+
# Directory on host where recordings will be saved
6060
HOST_RECORDINGS_DIR="$SCRIPT_DIR/recordings"
6161
mkdir -p "$HOST_RECORDINGS_DIR"
6262

63+
# Chromium data directory for persistence
64+
# Set CHROMIUM_DATA_HOST to customize location (default: ./chromium-data)
65+
# Set CHROMIUM_DATA_HOST="" to disable persistence (ephemeral mode)
66+
if [[ "${CHROMIUM_DATA_HOST+set}" == "set" && -z "$CHROMIUM_DATA_HOST" ]]; then
67+
echo "🔄 Using ephemeral Chromium data (no persistence)"
68+
CHROMIUM_DATA_VOLUME=""
69+
else
70+
# Default to ./chromium-data if not specified
71+
CHROMIUM_DATA_HOST="${CHROMIUM_DATA_HOST:-$SCRIPT_DIR/chromium-data}"
72+
echo "🗂️ Using persistent Chromium data directory: $CHROMIUM_DATA_HOST"
73+
CHROMIUM_DATA_REAL=$(realpath "$CHROMIUM_DATA_HOST" 2>/dev/null || echo "")
74+
if [[ -z "$CHROMIUM_DATA_REAL" ]]; then
75+
# Path doesn't exist yet, try to create it first
76+
mkdir -p "$CHROMIUM_DATA_HOST"
77+
CHROMIUM_DATA_REAL=$(realpath "$CHROMIUM_DATA_HOST" 2>/dev/null || echo "")
78+
if [[ -z "$CHROMIUM_DATA_REAL" ]]; then
79+
echo "❌ Error: Invalid path $CHROMIUM_DATA_HOST"
80+
exit 1
81+
fi
82+
fi
83+
CHROMIUM_DATA_VOLUME="${CHROMIUM_DATA_REAL}:/data"
84+
fi
85+
6386
# Build Chromium flags file and mount
64-
CHROMIUM_FLAGS_DEFAULT="--user-data-dir=/home/kernel/user-data --disable-dev-shm-usage --disable-gpu --start-maximized --disable-software-rasterizer --remote-allow-origins=*"
87+
CHROMIUM_FLAGS_DEFAULT="--user-data-dir=/data/user-data --disable-dev-shm-usage --disable-gpu --start-maximized --disable-software-rasterizer --remote-allow-origins=*"
6588
if [[ "$RUN_AS_ROOT" == "true" ]]; then
6689
CHROMIUM_FLAGS_DEFAULT="$CHROMIUM_FLAGS_DEFAULT --no-sandbox --no-zygote"
6790
fi
@@ -92,6 +115,11 @@ RUN_ARGS=(
92115
--mount type=bind,src="$FLAGS_FILE",dst=/chromium/flags,ro
93116
)
94117

118+
# Add Chromium data volume if specified
119+
if [[ -n "$CHROMIUM_DATA_VOLUME" ]]; then
120+
RUN_ARGS+=( -v "${CHROMIUM_DATA_VOLUME}" )
121+
fi
122+
95123
# Add URLS environment variable if provided
96124
if [[ -n "${URLS:-}" ]]; then
97125
echo " URLs: $URLS"

0 commit comments

Comments
 (0)