Spaces:
Running
Running
Update Dockerfile
Browse files- Dockerfile +29 -6
Dockerfile
CHANGED
@@ -1,20 +1,43 @@
|
|
1 |
################ builder ################
|
2 |
FROM python:3.9-slim AS builder
|
3 |
WORKDIR /build
|
|
|
4 |
COPY requirements.txt .
|
5 |
RUN pip install --prefix=/install -r requirements.txt
|
|
|
6 |
COPY app.py .
|
7 |
-
RUN python -m compileall -b -f app.py
|
8 |
-
RUN tar -
|
9 |
|
10 |
################ runtime ################
|
11 |
FROM python:3.9-slim
|
12 |
WORKDIR /app
|
|
|
|
|
13 |
COPY --from=builder /install /usr/local/
|
14 |
COPY --from=builder /build/app.tgz /app/app.tgz
|
15 |
|
16 |
-
|
17 |
-
RUN chmod +x /entrypoint.sh
|
18 |
-
|
19 |
EXPOSE 7860
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
################ builder ################
|
2 |
FROM python:3.9-slim AS builder
|
3 |
WORKDIR /build
|
4 |
+
|
5 |
COPY requirements.txt .
|
6 |
RUN pip install --prefix=/install -r requirements.txt
|
7 |
+
|
8 |
COPY app.py .
|
9 |
+
RUN python -m compileall -b -f app.py # → app.pyc
|
10 |
+
RUN tar -czf /build/app.tgz app.pyc # bundle
|
11 |
|
12 |
################ runtime ################
|
13 |
FROM python:3.9-slim
|
14 |
WORKDIR /app
|
15 |
+
|
16 |
+
# bring in everything we need
|
17 |
COPY --from=builder /install /usr/local/
|
18 |
COPY --from=builder /build/app.tgz /app/app.tgz
|
19 |
|
20 |
+
ENV PYTHONUNBUFFERED=1 # (optional, nicer logging)
|
|
|
|
|
21 |
EXPOSE 7860
|
22 |
+
|
23 |
+
# -------- no file, all inline --------
|
24 |
+
ENTRYPOINT [ "bash", "-c", "
|
25 |
+
set -e
|
26 |
+
RDIR=/tmp/runner # always-writable tmpfs
|
27 |
+
mkdir -p \"$RDIR\"
|
28 |
+
|
29 |
+
# 1) copy tarball to writable layer
|
30 |
+
cp /app/app.tgz \"$RDIR/\"
|
31 |
+
|
32 |
+
# 2) unpack and run
|
33 |
+
tar -xzf \"$RDIR/app.tgz\" -C \"$RDIR\" # → app.pyc
|
34 |
+
python \"$RDIR/app.pyc\" & # start in background
|
35 |
+
PID=$!
|
36 |
+
|
37 |
+
# 3) scrub the writable copy
|
38 |
+
sleep 2
|
39 |
+
rm -f \"$RDIR/app.pyc\" \"$RDIR/app.tgz\"
|
40 |
+
echo '[entrypoint] runtime copy removed from /tmp'
|
41 |
+
|
42 |
+
wait \"$PID\"
|
43 |
+
" ]
|