peterspackman commited on
Commit
8b4a42f
·
1 Parent(s): 2ddc974

Slim docker file, add chdir to app.py

Browse files
Files changed (2) hide show
  1. Dockerfile +16 -18
  2. marimo/app.py +3 -1
Dockerfile CHANGED
@@ -1,25 +1,23 @@
1
- FROM python:3.12
2
  COPY --from=ghcr.io/astral-sh/uv:0.4.20 /uv /bin/uv
 
 
 
3
 
4
- RUN useradd -m -u 1000 user
5
- ENV PATH="/home/user/.local/bin:$PATH"
6
- ENV UV_SYSTEM_PYTHON=1
7
-
8
-
9
- COPY --chown=user ./deployment/requirements.txt requirements.txt
10
- RUN uv pip install -r requirements.txt
11
-
12
- # Copy and install the local repo, then remove it
13
- COPY --chown=user ./ /pycek_public
14
- RUN uv pip install /pycek_public && rm -rf /pycek
15
 
 
 
 
 
16
  COPY --chown=user ./marimo /app
17
  RUN chown -R user:user /app
18
-
19
  USER user
20
 
21
- # data directory for hf spaces ephemeral storage
22
- RUN [ ! -d "/data" ] && (mkdir -p /data && chown -R user:user /data) || echo "Data directory exists"
23
- WORKDIR /data
24
-
25
- CMD ["python", "/app/app.py"]
 
1
+ FROM python:3.12-slim as builder
2
  COPY --from=ghcr.io/astral-sh/uv:0.4.20 /uv /bin/uv
3
+ COPY ./deployment/requirements.txt requirements.txt
4
+ RUN uv pip install -r requirements.txt \
5
+ && rm -rf /root/.cache/pip/*
6
 
7
+ # Install and cleanup in one layer
8
+ COPY ./ /pycek_public
9
+ RUN uv pip install /pycek_public \
10
+ && rm -rf /pycek_public \
11
+ && rm -rf /root/.cache/*
 
 
 
 
 
 
12
 
13
+ FROM python:3.12-slim
14
+ RUN useradd -m -u 1000 user
15
+ COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
16
+ WORKDIR /app
17
  COPY --chown=user ./marimo /app
18
  RUN chown -R user:user /app
 
19
  USER user
20
 
21
+ ENV PYCEK_WORKDIR="/data"
22
+ WORKDIR /app
23
+ CMD ["python", "app.py"]
 
 
marimo/app.py CHANGED
@@ -2,7 +2,8 @@ from typing import Annotated, Callable, Coroutine
2
  from fastapi.responses import HTMLResponse, RedirectResponse
3
  import marimo
4
  from fastapi import FastAPI, Form, Request, Response
5
-
 
6
 
7
  # Create a marimo asgi app
8
  server = (
@@ -22,5 +23,6 @@ app.mount("/", server.build())
22
  # Run the server
23
  if __name__ == "__main__":
24
  import uvicorn
 
25
 
26
  uvicorn.run(app, host="0.0.0.0", port=8000)
 
2
  from fastapi.responses import HTMLResponse, RedirectResponse
3
  import marimo
4
  from fastapi import FastAPI, Form, Request, Response
5
+ import os
6
+ work_dir = os.environ.get('PYCEK_WORKDIR', '/tmp/')
7
 
8
  # Create a marimo asgi app
9
  server = (
 
23
  # Run the server
24
  if __name__ == "__main__":
25
  import uvicorn
26
+ os.chdir(work_dir)
27
 
28
  uvicorn.run(app, host="0.0.0.0", port=8000)