Spaces:
Build error
Build error
Update Dockerfile
Browse files- Dockerfile +35 -46
Dockerfile
CHANGED
@@ -1,84 +1,73 @@
|
|
1 |
-
# Base stage
|
2 |
-
FROM
|
3 |
-
|
4 |
-
|
5 |
-
ENV NODE_OPTIONS="--max_old_space_size=2048" \
|
6 |
-
NEXT_TELEMETRY_DISABLED=1 \
|
7 |
-
NODE_ENV=production \
|
8 |
-
PYTHONDONTWRITEBYTECODE=1 \
|
9 |
-
POETRY_NO_INTERACTION=1 \
|
10 |
-
POETRY_VIRTUALENVS_CREATE=false \
|
11 |
-
POETRY_CACHE_DIR=/cache/poetry
|
12 |
|
13 |
# Web builder stage
|
14 |
-
FROM
|
15 |
-
|
16 |
WORKDIR /app/web
|
17 |
|
18 |
-
# Copy
|
19 |
-
COPY
|
20 |
|
21 |
-
#
|
22 |
-
|
|
|
|
|
23 |
|
24 |
-
# Install
|
25 |
RUN yarn install --frozen-lockfile --network-timeout 300000 && \
|
26 |
-
yarn add --dev @types/node @types/react
|
27 |
-
|
28 |
-
# Copy source files
|
29 |
-
COPY web/ .
|
30 |
-
|
31 |
-
# Build the application with standalone output
|
32 |
-
RUN NODE_PATH=/usr/local/lib/node_modules yarn build
|
33 |
|
34 |
# Python builder stage
|
35 |
FROM python:3.10-slim-bookworm AS python-builder
|
36 |
|
37 |
-
# Install build dependencies
|
38 |
RUN apt-get update && \
|
39 |
apt-get install -y --no-install-recommends \
|
40 |
build-essential \
|
|
|
41 |
&& rm -rf /var/lib/apt/lists/*
|
42 |
|
43 |
WORKDIR /app/api
|
44 |
|
45 |
-
#
|
46 |
-
|
47 |
|
48 |
-
#
|
49 |
-
|
50 |
-
|
51 |
poetry install --no-dev --no-interaction --no-ansi
|
52 |
|
53 |
# Final stage
|
54 |
FROM python:3.10-slim-bookworm
|
55 |
|
56 |
-
# Set up
|
57 |
RUN useradd -m -u 1000 user
|
58 |
|
59 |
-
# Install runtime dependencies
|
60 |
RUN apt-get update && \
|
61 |
apt-get install -y --no-install-recommends \
|
62 |
nodejs \
|
63 |
npm \
|
|
|
|
|
64 |
&& rm -rf /var/lib/apt/lists/*
|
65 |
|
66 |
# Create app directory structure
|
67 |
WORKDIR /app
|
68 |
-
RUN mkdir -p api web && chown -R user:user /app
|
69 |
|
70 |
-
# Copy
|
71 |
COPY --from=python-builder --chown=user /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages
|
72 |
-
COPY --chown=user api
|
73 |
-
|
74 |
-
# Copy web build artifacts with correct permissions
|
75 |
COPY --from=web-builder --chown=user /app/web/.next /app/web/.next
|
76 |
COPY --from=web-builder --chown=user /app/web/public /app/web/public
|
77 |
-
COPY --from=web-builder --chown=user /app/web/node_modules /app/web/node_modules
|
78 |
COPY --from=web-builder --chown=user /app/web/package.json /app/web/package.json
|
79 |
|
80 |
-
# Install
|
81 |
-
RUN pip install --no-cache-dir gunicorn gevent
|
82 |
|
83 |
# Set environment variables
|
84 |
ENV FLASK_APP=app.py \
|
@@ -91,14 +80,14 @@ ENV FLASK_APP=app.py \
|
|
91 |
NODE_ENV=production \
|
92 |
HOME=/app
|
93 |
|
94 |
-
# Switch to
|
95 |
USER user
|
96 |
|
97 |
-
# Expose
|
98 |
-
EXPOSE 7860
|
99 |
|
100 |
-
#
|
101 |
-
COPY --chown=user docker/entrypoint.sh /app/entrypoint.sh
|
102 |
RUN chmod +x /app/entrypoint.sh
|
103 |
|
104 |
WORKDIR /app
|
|
|
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/web
|
9 |
|
10 |
+
# Copy repository web files
|
11 |
+
COPY --from=repo /app/web ./
|
12 |
|
13 |
+
# Configure build environment
|
14 |
+
ENV NODE_OPTIONS="--max_old_space_size=2048" \
|
15 |
+
NEXT_TELEMETRY_DISABLED=1 \
|
16 |
+
NODE_ENV=production
|
17 |
|
18 |
+
# Install dependencies and build
|
19 |
RUN yarn install --frozen-lockfile --network-timeout 300000 && \
|
20 |
+
yarn add --dev @types/node @types/react && \
|
21 |
+
yarn build
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
# Python builder stage
|
24 |
FROM python:3.10-slim-bookworm AS python-builder
|
25 |
|
26 |
+
# Install build dependencies
|
27 |
RUN apt-get update && \
|
28 |
apt-get install -y --no-install-recommends \
|
29 |
build-essential \
|
30 |
+
git \
|
31 |
&& rm -rf /var/lib/apt/lists/*
|
32 |
|
33 |
WORKDIR /app/api
|
34 |
|
35 |
+
# Copy repository API files
|
36 |
+
COPY --from=repo /app/api ./
|
37 |
|
38 |
+
# Install poetry and dependencies
|
39 |
+
RUN pip install --no-cache-dir poetry && \
|
40 |
+
poetry config virtualenvs.create false && \
|
41 |
poetry install --no-dev --no-interaction --no-ansi
|
42 |
|
43 |
# Final stage
|
44 |
FROM python:3.10-slim-bookworm
|
45 |
|
46 |
+
# Set up user (required by Hugging Face)
|
47 |
RUN useradd -m -u 1000 user
|
48 |
|
49 |
+
# Install runtime dependencies
|
50 |
RUN apt-get update && \
|
51 |
apt-get install -y --no-install-recommends \
|
52 |
nodejs \
|
53 |
npm \
|
54 |
+
postgresql-client \
|
55 |
+
redis-tools \
|
56 |
&& rm -rf /var/lib/apt/lists/*
|
57 |
|
58 |
# Create app directory structure
|
59 |
WORKDIR /app
|
60 |
+
RUN mkdir -p api web storage/files && chown -R user:user /app
|
61 |
|
62 |
+
# Copy built artifacts
|
63 |
COPY --from=python-builder --chown=user /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages
|
64 |
+
COPY --from=repo --chown=user /app/api /app/api/
|
|
|
|
|
65 |
COPY --from=web-builder --chown=user /app/web/.next /app/web/.next
|
66 |
COPY --from=web-builder --chown=user /app/web/public /app/web/public
|
|
|
67 |
COPY --from=web-builder --chown=user /app/web/package.json /app/web/package.json
|
68 |
|
69 |
+
# Install additional Python packages
|
70 |
+
RUN pip install --no-cache-dir gunicorn gevent psycopg2-binary redis
|
71 |
|
72 |
# Set environment variables
|
73 |
ENV FLASK_APP=app.py \
|
|
|
80 |
NODE_ENV=production \
|
81 |
HOME=/app
|
82 |
|
83 |
+
# Switch to non-root user
|
84 |
USER user
|
85 |
|
86 |
+
# Expose Hugging Face required port
|
87 |
+
EXPOSE 7860
|
88 |
|
89 |
+
# Copy and setup entrypoint
|
90 |
+
COPY --from=repo --chown=user /app/docker/entrypoint.sh /app/entrypoint.sh
|
91 |
RUN chmod +x /app/entrypoint.sh
|
92 |
|
93 |
WORKDIR /app
|