builtin a x11 environment in docker

This commit is contained in:
Emilien Devos 2024-07-20 10:42:31 +02:00
parent cd25c70d17
commit 48f25566fa
3 changed files with 39 additions and 6 deletions

View File

@ -1,18 +1,29 @@
FROM python:3.12-alpine
# Install dependencies
RUN apk add --no-cache \
chromium \
xvfb \
x11vnc \
fluxbox \
nss \
freetype \
freetype-dev \
harfbuzz \
ca-certificates \
ttf-freefont
ttf-freefont \
chromium \
chromium-chromedriver
# Install x11vnc
RUN mkdir ~/.vnc
RUN x11vnc -storepasswd 1234 ~/.vnc/passwd
WORKDIR /usr/app/src
COPY index.py requirements.txt ./
RUN pip install -r requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
COPY docker/scripts/startup.sh ./
# Run
CMD [ "python", "./index.py"]
CMD [ "./startup.sh"]

22
docker/scripts/startup.sh Executable file
View File

@ -0,0 +1,22 @@
#!/bin/sh
echo "internally launching GUI (X11 environment)"
rm -f /tmp/.X0-lock
# Run Xvfb on display 0.
Xvfb :0 -screen 0 1280x720x16 &>/dev/null &
# Run fluxbox windows manager on display 0.
fluxbox -display :0 &>/dev/null &
# Run x11vnc on display 0
x11vnc -display :0 -forever -usepw &>/dev/null &
# Add delay
sleep 5
echo "launching the python script"
# Run python script on display 0
DISPLAY=:0 python index.py

View File

@ -6,7 +6,7 @@ import sys
async def main():
tab_url = 'https://www.google.com/search?q=me+at+the+zoo&tbm=vid&source=lnms&hl=en&lr=lang_us'
browser = await start(headless=True)
browser = await start(headless=False)
tab = browser.main_tab
page = await browser.get(tab_url)
accept_terms = await tab.find("Accept all")