Skip to content

Commit

Permalink
builtin a x11 environment in docker
Browse files Browse the repository at this point in the history
  • Loading branch information
unixfox committed Jul 20, 2024
1 parent cd25c70 commit 48f2556
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
21 changes: 16 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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 changes: 22 additions & 0 deletions docker/scripts/startup.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion index.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

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")
Expand Down

0 comments on commit 48f2556

Please sign in to comment.