fix: Resolve yarn installation and build issues
Browse files- Add proper yarn installation via npm
- Configure yarn cache and network timeout
- Add build optimization flags
- Implement BuildKit caching
- Add .dockerignore for build optimization
- .dockerignore +8 -0
- Dockerfile +13 -169
- scripts/build.sh +13 -0
.dockerignore
CHANGED
@@ -2,6 +2,14 @@
|
|
2 |
.git
|
3 |
.gitignore
|
4 |
.gitattributes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
# Dependencies
|
7 |
**/node_modules
|
|
|
2 |
.git
|
3 |
.gitignore
|
4 |
.gitattributes
|
5 |
+
**/node_modules
|
6 |
+
**/.next
|
7 |
+
**/dist
|
8 |
+
**/__pycache__
|
9 |
+
**/*.pyc
|
10 |
+
.git
|
11 |
+
.env*
|
12 |
+
.vscode
|
13 |
|
14 |
# Dependencies
|
15 |
**/node_modules
|
Dockerfile
CHANGED
@@ -1,169 +1,13 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
# Install only essential build dependencies
|
16 |
-
RUN apt-get update && apt-get install -y --no-install-recommends \
|
17 |
-
build-essential \
|
18 |
-
curl \
|
19 |
-
gnupg \
|
20 |
-
libgmp-dev \
|
21 |
-
libmpfr-dev \
|
22 |
-
libmpc-dev \
|
23 |
-
libssl-dev \
|
24 |
-
postgresql-client \
|
25 |
-
redis-tools \
|
26 |
-
&& rm -rf /var/lib/apt/lists/*
|
27 |
-
|
28 |
-
# Install Node.js efficiently
|
29 |
-
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
|
30 |
-
apt-get install -y nodejs && \
|
31 |
-
npm install -g npm@latest && \
|
32 |
-
apt-get clean && \
|
33 |
-
rm -rf /var/lib/apt/lists/*
|
34 |
-
|
35 |
-
# ============================================
|
36 |
-
# Web builder stage - optimized
|
37 |
-
# ============================================
|
38 |
-
FROM base AS web-builder
|
39 |
-
|
40 |
-
WORKDIR /app
|
41 |
-
|
42 |
-
# Copy web directory first
|
43 |
-
COPY web/ web/
|
44 |
-
|
45 |
-
WORKDIR /app/web
|
46 |
-
|
47 |
-
# Install dependencies and build
|
48 |
-
RUN yarn install --frozen-lockfile && \
|
49 |
-
yarn add --dev autoprefixer postcss tailwindcss code-inspector-plugin && \
|
50 |
-
NEXT_TELEMETRY_DISABLED=1 yarn build && \
|
51 |
-
mkdir -p .next/standalone && \
|
52 |
-
cp -r .next/static .next/standalone/.next/ && \
|
53 |
-
cp -r public .next/standalone/ && \
|
54 |
-
yarn cache clean
|
55 |
-
|
56 |
-
# ============================================
|
57 |
-
# Python builder stage - optimized
|
58 |
-
# ============================================
|
59 |
-
FROM base AS python-builder
|
60 |
-
|
61 |
-
WORKDIR /app
|
62 |
-
|
63 |
-
COPY api/pyproject.toml api/poetry.lock ./
|
64 |
-
RUN pip install --no-cache-dir poetry==1.8.3 && \
|
65 |
-
poetry config virtualenvs.create false && \
|
66 |
-
poetry install --no-dev --no-interaction --no-ansi
|
67 |
-
|
68 |
-
# Install core dependencies first
|
69 |
-
RUN pip install --no-cache-dir \
|
70 |
-
gunicorn \
|
71 |
-
gevent \
|
72 |
-
flask \
|
73 |
-
flask-cors \
|
74 |
-
Flask-SQLAlchemy==3.1.1 \
|
75 |
-
Flask-Migrate==4.0.7 \
|
76 |
-
redis \
|
77 |
-
psycopg2-binary
|
78 |
-
|
79 |
-
# Install ML dependencies separately with --no-deps
|
80 |
-
RUN pip install --no-cache-dir --no-deps \
|
81 |
-
numpy \
|
82 |
-
pandas \
|
83 |
-
torch \
|
84 |
-
transformers
|
85 |
-
|
86 |
-
# ============================================
|
87 |
-
# Final stage - minimal runtime
|
88 |
-
# ============================================
|
89 |
-
FROM base
|
90 |
-
|
91 |
-
# Create non-root user and storage directory
|
92 |
-
RUN apt-get update && \
|
93 |
-
useradd -m -u 1000 user && \
|
94 |
-
mkdir -p /storage/files /storage/cache /storage/logs && \
|
95 |
-
chown -R user:user /storage && \
|
96 |
-
mkdir -p /app/api && \
|
97 |
-
chown -R user:user /app
|
98 |
-
|
99 |
-
# Install runtime dependencies with proper repository update
|
100 |
-
RUN apt-get update && \
|
101 |
-
apt-get install -y --no-install-recommends \
|
102 |
-
build-essential \
|
103 |
-
curl \
|
104 |
-
gnupg \
|
105 |
-
libgmp-dev \
|
106 |
-
libmpfr-dev \
|
107 |
-
libmpc-dev \
|
108 |
-
libssl-dev \
|
109 |
-
postgresql-client \
|
110 |
-
redis-tools && \
|
111 |
-
# Install Node.js from NodeSource
|
112 |
-
curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
|
113 |
-
apt-get install -y nodejs && \
|
114 |
-
# Install npm separately
|
115 |
-
npm install -g npm@latest && \
|
116 |
-
# Cleanup
|
117 |
-
apt-get clean && \
|
118 |
-
rm -rf /var/lib/apt/lists/*
|
119 |
-
|
120 |
-
# Set up directory structure
|
121 |
-
WORKDIR /app
|
122 |
-
RUN mkdir -p api web && chown -R user:user /app
|
123 |
-
|
124 |
-
# Copy Python environment and files
|
125 |
-
COPY --from=python-builder --chown=user /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages
|
126 |
-
COPY --chown=user api/ /app/api/
|
127 |
-
|
128 |
-
# Copy Next.js files with explicit directory creation
|
129 |
-
RUN mkdir -p /app/web/.next/standalone /app/web/.next/static
|
130 |
-
COPY --from=web-builder --chown=user /app/web/.next/standalone /app/web/.next/standalone
|
131 |
-
COPY --from=web-builder --chown=user /app/web/.next/static /app/web/.next/static
|
132 |
-
COPY --from=web-builder --chown=user /app/web/public /app/web/public
|
133 |
-
|
134 |
-
# Set environment variables for HF Spaces compatibility
|
135 |
-
ENV FLASK_APP=app.py \
|
136 |
-
EDITION=SELF_HOSTED \
|
137 |
-
DEPLOY_ENV=PRODUCTION \
|
138 |
-
PYTHONPATH=/app/api \
|
139 |
-
PATH="/usr/local/bin:${PATH}" \
|
140 |
-
STORAGE_DIR=/storage \
|
141 |
-
# Database configuration - match docker-compose.yaml
|
142 |
-
DB_USERNAME=postgres \
|
143 |
-
DB_PASSWORD=difyai123456 \
|
144 |
-
DB_HOST=db \
|
145 |
-
DB_PORT=5432 \
|
146 |
-
DB_DATABASE=dify \
|
147 |
-
SQLALCHEMY_POOL_SIZE=30 \
|
148 |
-
SQLALCHEMY_POOL_RECYCLE=3600 \
|
149 |
-
# Redis configuration - match docker-compose.yaml
|
150 |
-
REDIS_HOST=redis \
|
151 |
-
REDIS_PORT=6379 \
|
152 |
-
REDIS_PASSWORD=difyai123456 \
|
153 |
-
REDIS_DB=0
|
154 |
-
|
155 |
-
# Copy entrypoint script
|
156 |
-
COPY docker/entrypoint.sh /app/entrypoint.sh
|
157 |
-
RUN chmod +x /app/entrypoint.sh
|
158 |
-
|
159 |
-
# Switch to non-root user
|
160 |
-
USER user
|
161 |
-
|
162 |
-
# HF Spaces uses port 7860
|
163 |
-
EXPOSE 7860 3000
|
164 |
-
|
165 |
-
# Set up storage volumes
|
166 |
-
VOLUME ["/storage/files", "/storage/cache", "/storage/logs"]
|
167 |
-
|
168 |
-
WORKDIR /app
|
169 |
-
CMD ["./entrypoint.sh"]
|
|
|
1 |
+
#!/bin/bash
|
2 |
+
set -e
|
3 |
+
|
4 |
+
# Build with BuildKit enabled
|
5 |
+
export DOCKER_BUILDKIT=1
|
6 |
+
export COMPOSE_DOCKER_CLI_BUILD=1
|
7 |
+
|
8 |
+
# Build the image with caching
|
9 |
+
docker build \
|
10 |
+
--build-arg BUILDKIT_INLINE_CACHE=1 \
|
11 |
+
--cache-from type=registry,ref=user/dify:cache \
|
12 |
+
--cache-to type=registry,ref=user/dify:cache,mode=max \
|
13 |
+
-t dify .
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
scripts/build.sh
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/bin/bash
|
2 |
+
set -e
|
3 |
+
|
4 |
+
# Build with BuildKit enabled
|
5 |
+
export DOCKER_BUILDKIT=1
|
6 |
+
export COMPOSE_DOCKER_CLI_BUILD=1
|
7 |
+
|
8 |
+
# Build the image with caching
|
9 |
+
docker build \
|
10 |
+
--build-arg BUILDKIT_INLINE_CACHE=1 \
|
11 |
+
--cache-from type=registry,ref=user/dify:cache \
|
12 |
+
--cache-to type=registry,ref=user/dify:cache,mode=max \
|
13 |
+
-t dify .
|