dioarafii commited on
Commit
a96f622
·
verified ·
1 Parent(s): a145d7c

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +32 -8
Dockerfile CHANGED
@@ -1,14 +1,38 @@
1
- # read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
2
- # you will also find guides on how best to write your Dockerfile
3
 
4
- FROM python:3.9
 
 
5
 
6
- WORKDIR /code
 
 
 
 
 
 
 
 
7
 
8
- COPY ./requirements.txt /code/requirements.txt
 
9
 
10
- RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
11
 
12
- COPY . .
 
13
 
14
- CMD ["python", "main.py", "--host", "0.0.0.0", "--port", "7860"]
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Stage 1: Building Environment
2
+ FROM python:3.9-alpine AS builder
3
 
4
+ ARG BUILD_USERNAME=builder
5
+ ARG BUILD_UID=1000
6
+ ARG BUILD_GID=1000
7
 
8
+ RUN apk add --no-cache --update --virtual .build-deps \
9
+ gcc musl-dev openssl-dev cargo \
10
+ && pip install --no-cache-dir --upgrade pip \
11
+ && pip install --no-cache-dir --disable-pip-version-check wheel \
12
+ && mkdir -p /runner \
13
+ && chown -R "${BUILD_UID}:${BUILD_GID}" /runner \
14
+ && echo "Flask==2.1.1\ntransformers==4.23.0" > /runner/requirements.builder.txt \
15
+ && pip install --no-cache-dir --exists-action i --target /runner --disable-pip-version-check -r /runner/requirements.builder.txt \
16
+ && apk del .build-deps
17
 
18
+ # Stage 2: Production Environment
19
+ FROM python:3.9-alpine
20
 
21
+ ENV HOME=/app
22
 
23
+ RUN addgroup --system --gid 1000 app && adduser --system --uid 1000 --gid 1000 --gecos '' app
24
+ WORKDIR ${HOME}
25
 
26
+ COPY --chown=${BUILD_UID}:${BUILD_GID} --from=builder /runner /app
27
+
28
+ COPY --chown=app:app . .
29
+
30
+ RUN pip install --no-cache-dir --user --upgrade pip \
31
+ && pip install --no-cache-dir --user -r /app/requirements.txt \
32
+ && apk del --purge gcc musl-dev openssl-dev cargo
33
+
34
+ USER app
35
+
36
+ EXPOSE 7860
37
+
38
+ CMD ["python", "main.py", "--host", "0.0.0.0", "--port", "7860"]