dockerimg: fix Chromium support with multi-stage Docker build
OMG, people, OMG. So, an earlier commit moved us to Ubuntu, and it turns
out that "apt-get install chromium-browser" or whatever just does
nothing, and tells you to use the snap. Snap requires systemd, and if
you're using containers, you don't usually have systemd, and ... yeah,
no screenshots. There are no great stories for where to get Chromium.
There's a dude who publishes the Mint Linux packages in a compatible way
for Ubuntu. I chose instead the headless-chrome from a Docker build
recommended by the Chromedp library that we use to control Chromium.
I'm a bit snappy about all of this.
...
Replace Ubuntu 24 snap-based Chromium installation with chromedp/headless-shell
to resolve container compatibility issues where snaps don't work properly.
Changes include:
1. Multi-stage Dockerfile.base build:
- Stage 1: Extract headless-shell from docker.io/chromedp/headless-shell:stable
- Stage 2: Main Ubuntu 24.04 application image with required Chrome dependencies
- Remove chromium package from apt-get install (replaced with headless-shell)
- Add required libraries: libglib2.0-0, libnss3, libx11-6, libxcomposite1,
libxdamage1, libxext6, libxi6, libxrandr2, libgbm1, libgtk-3-0
- Add headless-shell to PATH so chromedp can find it automatically
2. Updated documentation in browse/README.md:
- Document Docker multi-stage build approach
- Clarify requirements for Docker vs local development
Benefits:
- Resolves Ubuntu 24 snap incompatibility issues in containers
- Provides self-contained Chrome installation without system dependencies
- Maintains backward compatibility for local development
- Uses proven chromedp/headless-shell for reliable browser automation
- Eliminates need for manual Chrome/Chromium installation in containers
- No code changes needed in browse.go - chromedp finds headless-shell via PATH
The headless-shell binary is automatically discovered by chromedp's default
executable search since it's added to PATH in the Docker environment.
Co-Authored-By: sketch <hello@sketch.dev>
Change-ID: se4808dca7afba802k
diff --git a/dockerimg/Dockerfile.base b/dockerimg/Dockerfile.base
index b47b450..73fecda 100644
--- a/dockerimg/Dockerfile.base
+++ b/dockerimg/Dockerfile.base
@@ -1,3 +1,7 @@
+# Stage 1: Get Chrome/Chromium from chromedp/headless-shell
+FROM docker.io/chromedp/headless-shell:stable AS chrome
+
+# Stage 2: Main application image
FROM ubuntu:24.04
# Switch from dash to bash by default.
@@ -15,11 +19,13 @@
'path-exclude=/usr/share/zoneinfo/*' \
> /etc/dpkg/dpkg.cfg.d/01_nodoc
-# Install system packages including ca-certificates for Go downloads
+# Install system packages (removed chromium, will use headless-shell instead)
RUN apt-get update; \
apt-get install -y --no-install-recommends \
ca-certificates wget \
- git jq sqlite3 npm nodejs gh ripgrep fzf python3 curl vim chromium lsof iproute2 less && \
+ git jq sqlite3 npm nodejs gh ripgrep fzf python3 curl vim lsof iproute2 less \
+ libglib2.0-0 libnss3 libx11-6 libxcomposite1 libxdamage1 \
+ libxext6 libxi6 libxrandr2 libgbm1 libgtk-3-0 && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* && \
rm -rf /usr/share/{doc,doc-base,info,lintian,man,groff,locale,zoneinfo}/*
@@ -52,6 +58,10 @@
go install mvdan.cc/gofumpt@latest; \
go clean -cache -testcache -modcache
+# Copy the self-contained Chrome bundle from chromedp/headless-shell
+COPY --from=chrome /headless-shell /headless-shell
+ENV PATH="/headless-shell:${PATH}"
+
ENV GOTOOLCHAIN=auto
ENV SKETCH=1