Update Dockerfile
Browse files- Dockerfile +63 -5
Dockerfile
CHANGED
|
@@ -10,7 +10,9 @@ ENV POETRY_VERSION=1.8.4 \
|
|
| 10 |
PYTHONDONTWRITEBYTECODE=1 \
|
| 11 |
LANG=en_US.UTF-8 \
|
| 12 |
LANGUAGE=en_US:en \
|
| 13 |
-
LC_ALL=en_US.UTF-8
|
|
|
|
|
|
|
| 14 |
|
| 15 |
# Create user first (HF Spaces requirement)
|
| 16 |
RUN useradd -m -u 1000 user
|
|
@@ -29,6 +31,7 @@ RUN apt-get update && apt-get install -y \
|
|
| 29 |
postgresql \
|
| 30 |
postgresql-contrib \
|
| 31 |
locales \
|
|
|
|
| 32 |
&& rm -rf /var/lib/apt/lists/* \
|
| 33 |
&& pip install --no-cache-dir "poetry==${POETRY_VERSION}" \
|
| 34 |
&& sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen \
|
|
@@ -44,6 +47,56 @@ RUN mkdir -p /app/api /app/web /data/storage && \
|
|
| 44 |
chown -R user:user /app /data && \
|
| 45 |
chmod 777 /data /app
|
| 46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
# Switch to user for remaining operations
|
| 48 |
USER user
|
| 49 |
|
|
@@ -88,8 +141,8 @@ ENV FLASK_APP=app.py \
|
|
| 88 |
CONSOLE_WEB_URL=https://${SPACE_ID}.hf.space \
|
| 89 |
SERVICE_API_URL=https://${SPACE_ID}.hf.space \
|
| 90 |
APP_WEB_URL=https://${SPACE_ID}.hf.space \
|
| 91 |
-
DIFY_PORT=
|
| 92 |
-
DIFY_BIND_ADDRESS=
|
| 93 |
DB_USERNAME=user \
|
| 94 |
DB_PASSWORD=difyai123456 \
|
| 95 |
DB_HOST=localhost \
|
|
@@ -156,14 +209,19 @@ echo "Database connection successful"\n\
|
|
| 156 |
# Start application services\n\
|
| 157 |
cd /app/api && poetry run python -m flask db upgrade\n\
|
| 158 |
\n\
|
|
|
|
| 159 |
cd /app/api && poetry run python -m gunicorn app:app \\\n\
|
| 160 |
-
--bind ${DIFY_BIND_ADDRESS:-
|
| 161 |
--worker-class gevent \\\n\
|
| 162 |
--workers 1 \\\n\
|
| 163 |
--timeout 300 \\\n\
|
| 164 |
--preload &\n\
|
| 165 |
\n\
|
| 166 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
\n\
|
| 168 |
wait' > /app/entrypoint.sh && \
|
| 169 |
chmod +x /app/entrypoint.sh
|
|
|
|
| 10 |
PYTHONDONTWRITEBYTECODE=1 \
|
| 11 |
LANG=en_US.UTF-8 \
|
| 12 |
LANGUAGE=en_US:en \
|
| 13 |
+
LC_ALL=en_US.UTF-8 \
|
| 14 |
+
PORT=7860 \
|
| 15 |
+
NODE_ENV=production
|
| 16 |
|
| 17 |
# Create user first (HF Spaces requirement)
|
| 18 |
RUN useradd -m -u 1000 user
|
|
|
|
| 31 |
postgresql \
|
| 32 |
postgresql-contrib \
|
| 33 |
locales \
|
| 34 |
+
nginx \
|
| 35 |
&& rm -rf /var/lib/apt/lists/* \
|
| 36 |
&& pip install --no-cache-dir "poetry==${POETRY_VERSION}" \
|
| 37 |
&& sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen \
|
|
|
|
| 47 |
chown -R user:user /app /data && \
|
| 48 |
chmod 777 /data /app
|
| 49 |
|
| 50 |
+
# Configure nginx
|
| 51 |
+
COPY <<EOF /etc/nginx/nginx.conf
|
| 52 |
+
user user;
|
| 53 |
+
worker_processes auto;
|
| 54 |
+
error_log /var/log/nginx/error.log;
|
| 55 |
+
pid /run/nginx.pid;
|
| 56 |
+
|
| 57 |
+
events {
|
| 58 |
+
worker_connections 1024;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
http {
|
| 62 |
+
include /etc/nginx/mime.types;
|
| 63 |
+
default_type application/octet-stream;
|
| 64 |
+
access_log /var/log/nginx/access.log combined;
|
| 65 |
+
sendfile on;
|
| 66 |
+
keepalive_timeout 65;
|
| 67 |
+
|
| 68 |
+
server {
|
| 69 |
+
listen 7860;
|
| 70 |
+
server_name _;
|
| 71 |
+
|
| 72 |
+
location / {
|
| 73 |
+
proxy_pass http://127.0.0.1:3000;
|
| 74 |
+
proxy_http_version 1.1;
|
| 75 |
+
proxy_set_header Upgrade \$http_upgrade;
|
| 76 |
+
proxy_set_header Connection 'upgrade';
|
| 77 |
+
proxy_set_header Host \$host;
|
| 78 |
+
proxy_cache_bypass \$http_upgrade;
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
location /api {
|
| 82 |
+
proxy_pass http://127.0.0.1:5001;
|
| 83 |
+
proxy_http_version 1.1;
|
| 84 |
+
proxy_set_header Upgrade \$http_upgrade;
|
| 85 |
+
proxy_set_header Connection 'upgrade';
|
| 86 |
+
proxy_set_header Host \$host;
|
| 87 |
+
proxy_cache_bypass \$http_upgrade;
|
| 88 |
+
}
|
| 89 |
+
}
|
| 90 |
+
}
|
| 91 |
+
EOF
|
| 92 |
+
|
| 93 |
+
RUN mkdir -p /var/log/nginx && \
|
| 94 |
+
chown -R user:user /var/log/nginx && \
|
| 95 |
+
chown -R user:user /var/lib/nginx && \
|
| 96 |
+
chown -R user:user /etc/nginx && \
|
| 97 |
+
touch /run/nginx.pid && \
|
| 98 |
+
chown -R user:user /run/nginx.pid
|
| 99 |
+
|
| 100 |
# Switch to user for remaining operations
|
| 101 |
USER user
|
| 102 |
|
|
|
|
| 141 |
CONSOLE_WEB_URL=https://${SPACE_ID}.hf.space \
|
| 142 |
SERVICE_API_URL=https://${SPACE_ID}.hf.space \
|
| 143 |
APP_WEB_URL=https://${SPACE_ID}.hf.space \
|
| 144 |
+
DIFY_PORT=5001 \
|
| 145 |
+
DIFY_BIND_ADDRESS=127.0.0.1 \
|
| 146 |
DB_USERNAME=user \
|
| 147 |
DB_PASSWORD=difyai123456 \
|
| 148 |
DB_HOST=localhost \
|
|
|
|
| 209 |
# Start application services\n\
|
| 210 |
cd /app/api && poetry run python -m flask db upgrade\n\
|
| 211 |
\n\
|
| 212 |
+
# Start API server\n\
|
| 213 |
cd /app/api && poetry run python -m gunicorn app:app \\\n\
|
| 214 |
+
--bind ${DIFY_BIND_ADDRESS:-127.0.0.1}:${DIFY_PORT:-5001} \\\n\
|
| 215 |
--worker-class gevent \\\n\
|
| 216 |
--workers 1 \\\n\
|
| 217 |
--timeout 300 \\\n\
|
| 218 |
--preload &\n\
|
| 219 |
\n\
|
| 220 |
+
# Start frontend server\n\
|
| 221 |
+
cd /app/web && PORT=3000 node server.js &\n\
|
| 222 |
+
\n\
|
| 223 |
+
# Start nginx\n\
|
| 224 |
+
nginx -g "daemon off;" &\n\
|
| 225 |
\n\
|
| 226 |
wait' > /app/entrypoint.sh && \
|
| 227 |
chmod +x /app/entrypoint.sh
|