Spaces:
Build error
Build error
Update Dockerfile
Browse files- Dockerfile +37 -63
Dockerfile
CHANGED
@@ -1,51 +1,38 @@
|
|
1 |
-
# Base stage for git operations
|
2 |
-
FROM alpine/git AS repo
|
3 |
-
WORKDIR /app
|
4 |
-
RUN git clone https://github.com/langgenius/dify.git .
|
5 |
-
|
6 |
-
# Web builder stage
|
7 |
-
FROM node:20.11-alpine3.19 AS web-builder
|
8 |
-
WORKDIR /app
|
9 |
|
10 |
-
#
|
11 |
-
|
12 |
-
WORKDIR /app/web
|
13 |
|
14 |
-
# Configure
|
15 |
ENV NODE_OPTIONS="--max_old_space_size=2048" \
|
16 |
NEXT_TELEMETRY_DISABLED=1 \
|
17 |
-
NODE_ENV=production
|
|
|
|
|
|
|
|
|
18 |
|
19 |
-
#
|
20 |
-
|
21 |
-
yarn add --dev @types/node @types/react && \
|
22 |
-
yarn build
|
23 |
|
24 |
-
|
25 |
-
FROM python:3.10-slim-bookworm AS python-builder
|
26 |
|
27 |
-
#
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
git \
|
32 |
-
&& rm -rf /var/lib/apt/lists/*
|
33 |
|
34 |
-
|
|
|
35 |
|
36 |
-
# Copy repository API files
|
37 |
-
COPY --from=repo /app/api ./api/
|
38 |
WORKDIR /app/api
|
39 |
|
40 |
-
#
|
41 |
-
|
42 |
-
poetry config virtualenvs.create false && \
|
43 |
-
poetry install --no-dev --no-interaction --no-ansi
|
44 |
|
45 |
# Final stage
|
46 |
FROM python:3.10-slim-bookworm
|
47 |
|
48 |
-
#
|
49 |
RUN useradd -m -u 1000 user
|
50 |
|
51 |
# Install runtime dependencies
|
@@ -53,37 +40,20 @@ RUN apt-get update && \
|
|
53 |
apt-get install -y --no-install-recommends \
|
54 |
nodejs \
|
55 |
npm \
|
56 |
-
postgresql-client \
|
57 |
-
redis-tools \
|
58 |
&& rm -rf /var/lib/apt/lists/*
|
59 |
|
60 |
-
#
|
61 |
WORKDIR /app
|
62 |
-
RUN mkdir -p api web
|
63 |
-
|
64 |
-
# Copy
|
65 |
-
COPY --from=
|
66 |
-
COPY --from=
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
#
|
72 |
-
COPY --from=repo --chown=user /app/api/docker/entrypoint.sh /app/api/entrypoint.sh
|
73 |
-
COPY --from=repo --chown=user /app/web/docker/entrypoint.sh /app/web/entrypoint.sh
|
74 |
-
RUN chmod +x /app/api/entrypoint.sh /app/web/entrypoint.sh
|
75 |
-
|
76 |
-
# Create startup script
|
77 |
-
RUN echo '#!/bin/bash\n\
|
78 |
-
/app/api/entrypoint.sh & \n\
|
79 |
-
/app/web/entrypoint.sh & \n\
|
80 |
-
wait' > /app/start.sh && \
|
81 |
-
chmod +x /app/start.sh
|
82 |
-
|
83 |
-
# Install additional Python packages
|
84 |
-
RUN pip install --no-cache-dir gunicorn gevent psycopg2-binary redis
|
85 |
-
|
86 |
-
# Set environment variables
|
87 |
ENV FLASK_APP=app.py \
|
88 |
EDITION=SELF_HOSTED \
|
89 |
DEPLOY_ENV=PRODUCTION \
|
@@ -97,9 +67,13 @@ ENV FLASK_APP=app.py \
|
|
97 |
# Switch to non-root user
|
98 |
USER user
|
99 |
|
100 |
-
# Expose Hugging Face required port
|
101 |
EXPOSE 7860 3000
|
102 |
|
|
|
|
|
|
|
|
|
103 |
WORKDIR /app
|
104 |
|
105 |
-
CMD ["./
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
|
2 |
+
# Base stage with shared configuration
|
3 |
+
FROM node:20.11-alpine3.19 AS base
|
|
|
4 |
|
5 |
+
# Configure shared environment variables
|
6 |
ENV NODE_OPTIONS="--max_old_space_size=2048" \
|
7 |
NEXT_TELEMETRY_DISABLED=1 \
|
8 |
+
NODE_ENV=production \
|
9 |
+
PYTHONDONTWRITEBYTECODE=1 \
|
10 |
+
POETRY_NO_INTERACTION=1 \
|
11 |
+
POETRY_VIRTUALENVS_CREATE=false \
|
12 |
+
POETRY_CACHE_DIR=/cache/poetry
|
13 |
|
14 |
+
# Web builder stage
|
15 |
+
FROM langgenius/dify-web:latest AS web-builder
|
|
|
|
|
16 |
|
17 |
+
WORKDIR /app/web
|
|
|
18 |
|
19 |
+
# Copy web artifacts
|
20 |
+
COPY --from=langgenius/dify-web:latest /app/web/.next /app/web/.next
|
21 |
+
COPY --from=langgenius/dify-web:latest /app/web/public /app/web/public
|
22 |
+
COPY --from=langgenius/dify-web:latest /app/web/package.json /app/web/package.json
|
|
|
|
|
23 |
|
24 |
+
# API builder stage
|
25 |
+
FROM langgenius/dify-api:latest AS api-builder
|
26 |
|
|
|
|
|
27 |
WORKDIR /app/api
|
28 |
|
29 |
+
# Copy API artifacts
|
30 |
+
COPY --from=langgenius/dify-api:latest /app/api /app/api/
|
|
|
|
|
31 |
|
32 |
# Final stage
|
33 |
FROM python:3.10-slim-bookworm
|
34 |
|
35 |
+
# Create non-root user (required by Hugging Face)
|
36 |
RUN useradd -m -u 1000 user
|
37 |
|
38 |
# Install runtime dependencies
|
|
|
40 |
apt-get install -y --no-install-recommends \
|
41 |
nodejs \
|
42 |
npm \
|
|
|
|
|
43 |
&& rm -rf /var/lib/apt/lists/*
|
44 |
|
45 |
+
# Set up directory structure
|
46 |
WORKDIR /app
|
47 |
+
RUN mkdir -p api web && chown -R user:user /app
|
48 |
+
|
49 |
+
# Copy artifacts from builders
|
50 |
+
COPY --from=api-builder --chown=user /app/api /app/api/
|
51 |
+
COPY --from=web-builder --chown=user /app/web /app/web
|
52 |
+
|
53 |
+
# Install Python requirements
|
54 |
+
RUN pip install --no-cache-dir gunicorn gevent
|
55 |
+
|
56 |
+
# Set environment variables for Hugging Face Spaces
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
ENV FLASK_APP=app.py \
|
58 |
EDITION=SELF_HOSTED \
|
59 |
DEPLOY_ENV=PRODUCTION \
|
|
|
67 |
# Switch to non-root user
|
68 |
USER user
|
69 |
|
70 |
+
# Expose Hugging Face Spaces required port
|
71 |
EXPOSE 7860 3000
|
72 |
|
73 |
+
# Setup entrypoint
|
74 |
+
COPY --chown=user docker/entrypoint.sh /app/entrypoint.sh
|
75 |
+
RUN chmod +x /app/entrypoint.sh
|
76 |
+
|
77 |
WORKDIR /app
|
78 |
|
79 |
+
CMD ["./entrypoint.sh"]
|