Skip to content

Add Dockerfile for Headless Chrome #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions docker-modules/Headless-Google-Chrome/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Dockerfile
FROM debian:bullseye

# Install system dependencies, including ca-certificates
RUN apt-get update && apt-get install -y \
wget \
curl \
gnupg \
ca-certificates \
unzip \
fonts-liberation \
libappindicator3-1 \
libasound2 \
libatk-bridge2.0-0 \
libatk1.0-0 \
libcups2 \
libdbus-1-3 \
libgdk-pixbuf2.0-0 \
libnspr4 \
libnss3 \
libx11-xcb1 \
libxcomposite1 \
libxdamage1 \
libxrandr2 \
xdg-utils \
--no-install-recommends && \
rm -rf /var/lib/apt/lists/*

# Install Google Chrome
RUN apt-get update && \
curl -fsSL https://dl.google.com/linux/linux_signing_key.pub | gpg --dearmor -o /usr/share/keyrings/google-linux-keyring.gpg && \
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/google-linux-keyring.gpg] http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google-chrome.list && \
apt-get update && apt-get install -y google-chrome-stable && \
rm -rf /var/lib/apt/lists/*

# Create non-root user
RUN useradd -m chromeuser

# Switch to non-root user
USER chromeuser

# Set Chrome as entrypoint with headless configuration
ENTRYPOINT ["google-chrome", "--headless", "--no-sandbox", "--disable-gpu", "--remote-debugging-port=9222", "--disable-dev-shm-usage"]
36 changes: 36 additions & 0 deletions docker-modules/Headless-Google-Chrome/Github-action-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# .github/workflows/chrome-test.yml
name: Run Chrome Headless Test

on: [push]

jobs:
headless-test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Docker
run: sudo apt-get update && sudo apt-get install -y docker.io

- name: Build Chrome Docker image
run: docker build -t headless-chrome .

- name: Run screenshot test
run: |
mkdir screenshots
docker run --rm \
-v ${{ github.workspace }}/screenshots:/screenshots \
headless-chrome \
--headless \
--disable-gpu \
--no-sandbox \
--screenshot=/screenshots/test.png \
https://google.com

- name: Upload screenshot artifact
uses: actions/upload-artifact@v3
with:
name: screenshot
path: screenshots/test.png