Update wrapper/start.sh
This commit is contained in:
		
							parent
							
								
									82f4d0e75c
								
							
						
					
					
						commit
						a01478d605
					
				@ -1,14 +1,13 @@
 | 
				
			|||||||
#!/usr/bin/env bash
 | 
					#!/usr/bin/env bash
 | 
				
			||||||
set -euo pipefail
 | 
					set -euo pipefail
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Stable paths
 | 
					 | 
				
			||||||
export DATA_FILE="${DATA_FILE:-/data/data.json}"
 | 
					export DATA_FILE="${DATA_FILE:-/data/data.json}"
 | 
				
			||||||
export PLAYWRIGHT_BROWSERS_PATH="${PLAYWRIGHT_BROWSERS_PATH:-/cache/pw-browsers}"
 | 
					export PLAYWRIGHT_BROWSERS_PATH="${PLAYWRIGHT_BROWSERS_PATH:-/cache/pw-browsers}"
 | 
				
			||||||
export WITH_PLAYWRIGHT="${WITH_PLAYWRIGHT:-1}"
 | 
					export WITH_PLAYWRIGHT="${WITH_PLAYWRIGHT:-1}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
mkdir -p "$(dirname "$DATA_FILE")" /cache "$PLAYWRIGHT_BROWSERS_PATH"
 | 
					mkdir -p "$(dirname "$DATA_FILE")" /cache "$PLAYWRIGHT_BROWSERS_PATH"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Install browsers once if playwright is available in this image
 | 
					# Install browser binaries once (idempotent)
 | 
				
			||||||
if [ "$WITH_PLAYWRIGHT" = "1" ]; then
 | 
					if [ "$WITH_PLAYWRIGHT" = "1" ]; then
 | 
				
			||||||
  python - <<'PY' || true
 | 
					  python - <<'PY' || true
 | 
				
			||||||
import importlib, os, subprocess, sys, pathlib
 | 
					import importlib, os, subprocess, sys, pathlib
 | 
				
			||||||
@ -16,20 +15,14 @@ ok = importlib.util.find_spec("playwright") is not None
 | 
				
			|||||||
if ok:
 | 
					if ok:
 | 
				
			||||||
    bpath = os.environ.get("PLAYWRIGHT_BROWSERS_PATH", "/cache/pw-browsers")
 | 
					    bpath = os.environ.get("PLAYWRIGHT_BROWSERS_PATH", "/cache/pw-browsers")
 | 
				
			||||||
    p = pathlib.Path(bpath)
 | 
					    p = pathlib.Path(bpath)
 | 
				
			||||||
    need = True
 | 
					    need = not any(p.glob("*chromium*"))
 | 
				
			||||||
    if p.exists():
 | 
					 | 
				
			||||||
        # crude presence check: any chromium* dir inside browsers path
 | 
					 | 
				
			||||||
        for child in p.glob("*chromium*"):
 | 
					 | 
				
			||||||
            need = False
 | 
					 | 
				
			||||||
            break
 | 
					 | 
				
			||||||
    if need:
 | 
					    if need:
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            subprocess.check_call([sys.executable, "-m", "playwright", "install-deps", "chromium"])
 | 
					            subprocess.run([sys.executable, "-m", "playwright", "install-deps", "chromium"], check=False)
 | 
				
			||||||
        except Exception:
 | 
					        except Exception:
 | 
				
			||||||
            pass  # not fatal on slim images
 | 
					            pass
 | 
				
			||||||
        subprocess.check_call([sys.executable, "-m", "playwright", "install", "chromium"])
 | 
					        subprocess.check_call([sys.executable, "-m", "playwright", "install", "chromium"])
 | 
				
			||||||
PY
 | 
					PY
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Hand off to the Python wrapper (nightly update + rollback)
 | 
					 | 
				
			||||||
exec python -u /app/wrapper.py
 | 
					exec python -u /app/wrapper.py
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user