Dockerfile 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # Stage 1: init
  2. FROM python:3.11 as init
  3. # Pass `--build-arg API_URL=http://app.example.com:8000` during build
  4. ARG API_URL
  5. # Copy local context to `/app` inside container (see .dockerignore)
  6. WORKDIR /app
  7. COPY . .
  8. # Create virtualenv which will be copied into final container
  9. ENV VIRTUAL_ENV=/app/.venv
  10. ENV PATH="$VIRTUAL_ENV/bin:$PATH"
  11. RUN python3.11 -m venv $VIRTUAL_ENV
  12. # Install app requirements and reflex inside virtualenv
  13. RUN pip install -r requirements.txt
  14. # Deploy templates and prepare app
  15. RUN reflex init
  16. # Export static copy of frontend to /app/.web/_static
  17. RUN reflex export --frontend-only --no-zip
  18. # Copy static files out of /app to save space in backend image
  19. RUN mv .web/_static /tmp/_static
  20. RUN rm -rf .web && mkdir .web
  21. RUN mv /tmp/_static .web/_static
  22. # Stage 2: copy artifacts into slim image
  23. FROM python:3.11-slim
  24. ARG API_URL
  25. WORKDIR /app
  26. RUN adduser --disabled-password --home /app reflex
  27. COPY --chown=reflex --from=init /app /app
  28. USER reflex
  29. ENV PATH="/app/.venv/bin:$PATH" API_URL=$API_URL
  30. CMD reflex db migrate && reflex run --env prod --backend-only