File size: 2,639 Bytes
c92a454
 
 
 
7ce37bf
0c0d5e5
c92a454
d7a6a99
7e4b3da
c92a454
d7a6a99
 
116ec26
c92a454
 
 
 
b563962
c92a454
4680b44
c92a454
 
7ce37bf
0c0d5e5
 
 
c92a454
4680b44
0c0d5e5
 
c92a454
0c0d5e5
 
d7a6a99
0c0d5e5
c92a454
d7a6a99
 
0c0d5e5
c92a454
 
 
0c0d5e5
 
 
a4bef0b
496ca32
c92a454
443bf8a
 
c92a454
4680b44
0c0d5e5
a4bef0b
 
c92a454
 
0c0d5e5
496ca32
0404cc9
 
c92a454
a4bef0b
c92a454
443bf8a
d7a6a99
0404cc9
 
 
 
d7a6a99
 
 
 
c92a454
 
a4bef0b
 
7ce37bf
 
 
6aed364
7ce37bf
6aed364
7ce37bf
0404cc9
 
a4bef0b
c92a454
443bf8a
 
c92a454
 
a4bef0b
0404cc9
a4bef0b
443bf8a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# Base stage for git operations
FROM alpine/git AS repo
WORKDIR /app
RUN git clone https://github.com/langgenius/dify.git .

# Web builder stage
FROM node:20.11-alpine3.19 AS web-builder
WORKDIR /app

# Copy repository web files
COPY --from=repo /app/web ./web/
WORKDIR /app/web

# Configure build environment
ENV NODE_OPTIONS="--max_old_space_size=2048" \
    NEXT_TELEMETRY_DISABLED=1 \
    NODE_ENV=production

# Install dependencies and build
RUN yarn install --frozen-lockfile --network-timeout 300000 && \
    yarn add --dev @types/node @types/react && \
    yarn build

# Python builder stage
FROM python:3.10-slim-bookworm AS python-builder

# Install build dependencies
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
    build-essential \
    git \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app

# Copy repository API files
COPY --from=repo /app/api ./api/
WORKDIR /app/api

# Install poetry and dependencies
RUN pip install --no-cache-dir poetry && \
    poetry config virtualenvs.create false && \
    poetry install --no-dev --no-interaction --no-ansi

# Final stage
FROM python:3.10-slim-bookworm

# Set up user (required by Hugging Face)
RUN useradd -m -u 1000 user

# Install runtime dependencies
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
    nodejs \
    npm \
    postgresql-client \
    redis-tools \
    && rm -rf /var/lib/apt/lists/*

# Create app directory structure
WORKDIR /app
RUN mkdir -p api web storage/files && chown -R user:user /app

# Copy built artifacts
COPY --from=python-builder --chown=user /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages
COPY --from=python-builder --chown=user /app/api /app/api/
COPY --from=web-builder --chown=user /app/web/.next /app/web/.next
COPY --from=web-builder --chown=user /app/web/public /app/web/public
COPY --from=web-builder --chown=user /app/web/package.json /app/web/package.json

# Copy entrypoint script from repo
COPY --from=repo --chown=user /app/docker/api/entrypoint.sh /app/entrypoint.sh
RUN chmod +x /app/entrypoint.sh

# Install additional Python packages
RUN pip install --no-cache-dir gunicorn gevent psycopg2-binary redis

# Set environment variables
ENV FLASK_APP=app.py \
    EDITION=SELF_HOSTED \
    DEPLOY_ENV=PRODUCTION \
    CONSOLE_API_URL=http://127.0.0.1:7860 \
    CONSOLE_WEB_URL=http://127.0.0.1:3000 \
    SERVICE_API_URL=http://127.0.0.1:7860 \
    APP_WEB_URL=http://127.0.0.1:3000 \
    NODE_ENV=production \
    HOME=/app

# Switch to non-root user
USER user

# Expose Hugging Face required port
EXPOSE 7860

WORKDIR /app

CMD ["./entrypoint.sh"]