Severian commited on
Commit
c92a454
1 Parent(s): e3a6f0b

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +35 -46
Dockerfile CHANGED
@@ -1,84 +1,73 @@
1
- # Base stage with shared configuration
2
- FROM node:20.11-alpine3.19 AS base
3
-
4
- # Configure build environment
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 base AS web-builder
15
-
16
  WORKDIR /app/web
17
 
18
- # Copy package files first
19
- COPY web/package.json web/yarn.lock ./
20
 
21
- # Install build dependencies globally first
22
- RUN npm install -g code-inspector-plugin autoprefixer postcss tailwindcss
 
 
23
 
24
- # Install project dependencies
25
  RUN yarn install --frozen-lockfile --network-timeout 300000 && \
26
- yarn add --dev @types/node @types/react code-inspector-plugin autoprefixer postcss tailwindcss
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 in a single layer
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
- # Install and configure poetry
46
- RUN pip install --no-cache-dir poetry
47
 
48
- # Copy Python files and install dependencies
49
- COPY api/pyproject.toml api/poetry.lock ./
50
- RUN poetry config virtualenvs.create false && \
51
  poetry install --no-dev --no-interaction --no-ansi
52
 
53
  # Final stage
54
  FROM python:3.10-slim-bookworm
55
 
56
- # Set up a new user named "user" with user ID 1000 (required by Hugging Face)
57
  RUN useradd -m -u 1000 user
58
 
59
- # Install runtime dependencies in a single layer
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 Python environment and set permissions
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/ /app/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 gunicorn
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 the non-root user
95
  USER user
96
 
97
- # Expose port 7860 as required by Hugging Face Spaces
98
- EXPOSE 7860 3000
99
 
100
- # Setup entrypoint
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