LarryHopeCode
LarryHopeCode•10mo ago

Any document or tips to deploy convex production environment to Google Cloud Run or any other docker

Trying to use Convex and Python Fastapi together in docker container, here is the Dockerfile.
FROM python:3.12.2-slim-bullseye as runner

COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
COPY --from=builder /app /app

WORKDIR /app

# Install Node.js and npm in the runner stage
RUN apt-get update && \
apt-get install -y nodejs npm && \
rm -rf /var/lib/apt/lists/*

# Set Convex deploy key environment variable
ENV CONVEX_DEPLOY_KEY="xxxxxxxx"

# Deploy your Convex project before starting the FastAPI application
RUN npx convex deploy -y

# Set the correct entrypoint for the FastAPI application
ENTRYPOINT ["python"]
CMD ["-m", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080"]
FROM python:3.12.2-slim-bullseye as runner

COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
COPY --from=builder /app /app

WORKDIR /app

# Install Node.js and npm in the runner stage
RUN apt-get update && \
apt-get install -y nodejs npm && \
rm -rf /var/lib/apt/lists/*

# Set Convex deploy key environment variable
ENV CONVEX_DEPLOY_KEY="xxxxxxxx"

# Deploy your Convex project before starting the FastAPI application
RUN npx convex deploy -y

# Set the correct entrypoint for the FastAPI application
ENTRYPOINT ["python"]
CMD ["-m", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080"]
And this python program work with Convex in Dev environment very well.
6 Replies
LarryHopeCode
LarryHopeCodeOP•10mo ago
And I believe python part is not important, key point is if we don't want to deploy to Vercel or Netflify, could we deploy convex production on docker environement? it should work because it is kinda node.js program (?) :convex:
ballingt
ballingt•10mo ago
This seems reasonable, yeah! You don't really need to CLI deploy to take place in the docker container, since the only point of that is to deploy the (hosted) Convex deployment.
LarryHopeCode
LarryHopeCodeOP•10mo ago
So any suggestion or reference in this good direction? I think once this is done or as example, a lot of good fella will use it. 😉 The first test image size is kind of big, any information of what EXACTLY node version npx convex deploy need and if there is any other packages I could remove, will be great.
ballingt
ballingt•10mo ago
There doesn't need to be anything in this docker file specific to Convex: your Python program just needs the production CONVEX_URL
LarryHopeCode
LarryHopeCodeOP•10mo ago
I like this design. Really flexible!
ballingt
ballingt•10mo ago
generally I'd run that npx convex deploy -y on your own machine instead but if you want to use docker for it then just having node, convex, and your convex functions dependencies installed are all that's required If you care about image size I'd use two different containers for the two tasks

Did you find this page helpful?