4 months ago
Hi Railway/Nixpacks team! Need help getting SeleniumBase(uc=True)
working in a Nixpacks deployment.
Goal: Headless Chromium logs into Google, gets cookies.
Problem:Driver(uc=True, headless=True)
fails during init in Railway deployment. Base FastAPI app works fine.
Environment: Railway, Nixpacks (Python), python:3.9-slim
base, seleniumbase
, fastapi
, uvicorn
, supabase
.
nixpacks.toml
:
[phases.setup]
nixPkgs = ["chromium", "nss"]
(Dockerfile apt-get install chrome
is commented out).
Status & What Fails:
SSH confirms Nix-installed
chromium
runs, network/permissions seem OK.Error shifted after adding
nss
: Previouslyuc_driver
exited (Status 127 - likely missing libs, friend saw[libnss3.so](libnss3.so)
error). Nowuc_driver
file isn't found/saved inseleniumbase/drivers/
at all.Crucially: Adding a larger list of potential libs (e.g.,
gtk+3
,libX11
) tonixPkgs
caused the Nixpacks build itself to fail.
Questions:
What's the correct way to include all required shared libraries for
chromium
&uc_driver
vianixPkgs
?Why might adding many common libs break the Nixpacks build? (Known conflicts/issues?)
How best to debug the
uc_driver
startup failure within the Nixpacks runtime?
Using seleniumbase.Driver(uc=True, headless=True)
in Python. Any pointers on the Nixpacks config for headless browsers would be great! Thanks!
0 Replies
4 months ago
have you tried using Browserless instead? -
Did not know this was a thing, I'll try it today, will keep this thread updated
Now it doesnt work locally, as when i use browserless google detects that its a selenium based browser. The point of using selenium base with undetectable mode was so that i am able to sign into a google account. The old code still works locally, just fails to deploy due to missing libraries. Does browserless support seleniumbase?
Deployment to Render has succeeded. Still no luck on railway. Is there a way to just fix this missing libraries error? Its extremely specific to railway and the way railway initializes chromium/selenium. works like butter deploying locally, even works on render with a couple of minor adjustments
4 months ago
you could write a Dockerfile
thats exactly what im doing, works perfectly fine locally but fails to deploy on railway despite working fine locally
here's the current dockerfile:
# Base image with Python
FROM python:3.9-slim
# Set environment variables
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=1
# Install system dependencies
RUN apt-get update && apt-get install -y \
wget \
gnupg \
unzip \
curl \
&& rm -rf /var/lib/apt/lists/*
# Install Google Chrome
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& echo "deb [arch=amd64] 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/*
# Set up working directory
WORKDIR /app
# Install Python dependencies
COPY requirements.txt .
RUN pip install --upgrade pip && \
pip install -r requirements.txt && \
pip install python-dotenv # Add python-dotenv for .env support
# Copy application code and .env file
COPY . .
# No need to copy .env separately since it's already included in the previous COPY command
# Expose port
EXPOSE 8000
# Command to run the application
CMD ["python", "main.py"]
4 months ago
may i ask why nixpacks was mentioned then? nixpacks and dockerfiles are mutually exclusive
I'm not a super experienced dev, when i was facing this issue with docker i did a bunch of debugging with ai, it told me to use dockerfile for everything (except chromium) and add chromium only via nixpacks
do you suggest running locally with nixpacks? as local docker works fine and fails in deployment - and im assuming since railway uses nixpacks it'd be more productive to run what railway runs locally?
4 months ago
if you have a working dockerfile locally then using that on railway is going to be most productive.. does your dockerfile work locally?
Exactly what im thinking! Dockerfile works perfectly locally, sent it to a friend, and it worked like a charm on his machine as well! However deployment to railway shows drivers missing error
4 months ago
are you building with buildkit locally too?
4 months ago
try with buildkit, since thats what we build with
To resend the message i sent on general, since mods asked me to keep my questions contained to this thread:
What about caching? Suppose im building a custom docker image
Does the build get cached? The build time initially on my local machine is 2 minutes, and subsequent builds are <2s
Will the same be reflected on railway?
Or should i upload this to a public registry and pull from there
Thank you so much for the help so far, this has been incredibly helpful
I managed to get the server deployed - just need to optimise for build times now
4 months ago
awsome, im glad you solved it, but what was the issue if you dont mind me asking?
it was incredibly stupid, get this: i never realised railway wasnt using the dockerfile. after you mentioned the buildkit thing i figured out that you have to explicitly define the dockerfile path to use it to build
so sorry 😭
4 months ago
Well that would do it, unless its named Dockerfile and at the root, then you would need to tell us what to use.
yeah it was at root but named dockerfile not Dockerfile, so ig thts why it didnt pick it up
4 months ago
if you are using a custom docker image, there is no build step.
do you perhaps mean custom dockerfile?
4 months ago
then yes, layers are still cached, but your build could end up on a machine that doesn't have the cache and thus no cache will be used for that particular build since we don't yet have a global cache
So what's the best approach for minimising build times if the build ending up on a different machine is a possiblity? ghcr?
4 months ago
yeah you could build your image on ghcr, but it's really not worth it with what you lose imo
4 months ago
you lose the auto deploys on push, i recommend keep deploying from github as you have been
4 months ago
sounds good!
4 months ago
good to mark this as solved?
4 months ago
!s
Status changed to Solved brody • 4 months ago