Severian commited on
Commit
443bf8a
1 Parent(s): b563962

Update Dockerfile for correct directory structure

Browse files
Files changed (1) hide show
  1. Dockerfile +28 -14
Dockerfile CHANGED
@@ -58,6 +58,9 @@ RUN poetry config virtualenvs.create false && \
58
  # Final stage
59
  FROM python:3.10-slim-bookworm
60
 
 
 
 
61
  # Install runtime dependencies in a single layer
62
  RUN apt-get update && \
63
  apt-get install -y --no-install-recommends \
@@ -65,17 +68,25 @@ RUN apt-get update && \
65
  npm \
66
  && rm -rf /var/lib/apt/lists/*
67
 
68
- WORKDIR /app
 
 
 
 
 
69
 
70
- # Copy Python environment
71
- COPY --from=python-builder /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages
72
- COPY api/ /app/api/
73
 
74
- # Copy web build artifacts
75
- COPY --from=web-builder /app/web/.next /app/web/.next
76
- COPY --from=web-builder /app/web/public /app/web/public
77
- COPY --from=web-builder /app/web/node_modules /app/web/node_modules
78
- COPY --from=web-builder /app/web/package.json /app/web/package.json
 
 
 
 
79
 
80
  # Set environment variables
81
  ENV FLASK_APP=app.py \
@@ -87,11 +98,14 @@ ENV FLASK_APP=app.py \
87
  APP_WEB_URL=http://127.0.0.1:3000 \
88
  NODE_ENV=production
89
 
90
- # Expose ports
91
- EXPOSE 3000 5001
 
 
 
92
 
93
  # Setup entrypoint
94
- COPY docker/entrypoint.sh /entrypoint.sh
95
- RUN chmod +x /entrypoint.sh
96
 
97
- CMD ["/entrypoint.sh"]
 
58
  # Final stage
59
  FROM python:3.10-slim-bookworm
60
 
61
+ # Set up a new user named "user" with user ID 1000 (required by Hugging Face)
62
+ RUN useradd -m -u 1000 user
63
+
64
  # Install runtime dependencies in a single layer
65
  RUN apt-get update && \
66
  apt-get install -y --no-install-recommends \
 
68
  npm \
69
  && rm -rf /var/lib/apt/lists/*
70
 
71
+ # Set home to the user's home directory
72
+ ENV HOME=/home/user \
73
+ PATH=/home/user/.local/bin:$PATH
74
+
75
+ # Set the working directory to the user's home directory
76
+ WORKDIR $HOME/app
77
 
78
+ # Install gunicorn
79
+ RUN pip install --no-cache-dir gunicorn gevent
 
80
 
81
+ # Copy Python environment and set permissions
82
+ COPY --from=python-builder --chown=user /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages
83
+ COPY --chown=user api/ $HOME/app/api/
84
+
85
+ # Copy web build artifacts with correct permissions
86
+ COPY --from=web-builder --chown=user /app/web/.next $HOME/app/web/.next
87
+ COPY --from=web-builder --chown=user /app/web/public $HOME/app/web/public
88
+ COPY --from=web-builder --chown=user /app/web/node_modules $HOME/app/web/node_modules
89
+ COPY --from=web-builder --chown=user /app/web/package.json $HOME/app/web/package.json
90
 
91
  # Set environment variables
92
  ENV FLASK_APP=app.py \
 
98
  APP_WEB_URL=http://127.0.0.1:3000 \
99
  NODE_ENV=production
100
 
101
+ # Switch to the non-root user
102
+ USER user
103
+
104
+ # Expose port 7860 as required by Hugging Face Spaces
105
+ EXPOSE 7860
106
 
107
  # Setup entrypoint
108
+ COPY --chown=user docker/entrypoint.sh $HOME/app/entrypoint.sh
109
+ RUN chmod +x $HOME/app/entrypoint.sh
110
 
111
+ CMD ["./entrypoint.sh"]