Severian commited on
Commit
fbcb88a
·
verified ·
1 Parent(s): a7917aa

Update entrypoint.sh

Browse files
Files changed (1) hide show
  1. entrypoint.sh +35 -63
entrypoint.sh CHANGED
@@ -1,84 +1,59 @@
1
- # Base Python image with correct version
2
- FROM python:3.12-slim-bookworm
3
 
4
  # Create non-root user early (HF requirement)
5
  RUN useradd -m -u 1000 user
6
 
7
- # Set up environment variables
8
- ENV PYTHONDONTWRITEBYTECODE=1 \
9
- POETRY_VERSION=1.8.4 \
10
- POETRY_HOME=/opt/poetry \
11
- POETRY_CACHE_DIR=/tmp/poetry_cache \
12
- POETRY_NO_INTERACTION=1 \
13
- POETRY_VIRTUALENVS_IN_PROJECT=true \
14
- POETRY_VIRTUALENVS_CREATE=true \
15
- POETRY_REQUESTS_TIMEOUT=15 \
16
- PYTHONPATH=/app/api \
17
- FLASK_APP=/app/api/app.py
18
 
19
- WORKDIR /app
 
 
 
 
 
 
 
20
 
21
  # Install system dependencies
22
- RUN pip install --no-cache-dir "poetry==${POETRY_VERSION}" && \
23
- apt-get update && \
24
  apt-get install -y --no-install-recommends \
25
  gcc g++ libc-dev libffi-dev libgmp-dev libmpfr-dev libmpc-dev \
26
  postgresql postgresql-contrib postgresql-server-dev-all \
27
  curl git nodejs npm && \
28
- rm -rf /var/lib/apt/lists/*
29
-
30
- # Copy application code with correct permissions
31
- COPY --chown=user . /app/api
32
- WORKDIR /app/api
33
-
34
- # Install Python dependencies including Flask-Migrate
35
- RUN pip install --no-cache-dir flask==3.0.1 \
36
- gunicorn==22.0.0 \
37
- gevent==24.11.1 \
38
- celery==5.4.0 \
39
- redis==5.0.3 \
40
- psycopg2-binary==2.9.6 \
41
- sqlalchemy==2.0.29 \
42
- flask-migrate==4.0.5 \
43
- flask-sqlalchemy==3.1.1
44
-
45
- # Create and set up entrypoint script
46
- RUN echo '#!/bin/bash\n\
47
- set -e\n\
48
- \n\
49
- if [[ "${MIGRATION_ENABLED}" == "true" ]]; then\n\
50
- echo "Running migrations"\n\
51
- cd /app/api && poetry run flask db upgrade\n\
52
- fi\n\
53
- \n\
54
- if [[ "${DEBUG}" == "true" ]]; then\n\
55
- exec poetry run flask run --host=${DIFY_BIND_ADDRESS:-0.0.0.0} --port=7860 --debug\n\
56
- else\n\
57
- exec poetry run gunicorn \\\n\
58
- --bind "0.0.0.0:7860" \\\n\
59
- --workers ${SERVER_WORKER_AMOUNT:-1} \\\n\
60
- --worker-class ${SERVER_WORKER_CLASS:-gevent} \\\n\
61
- --timeout ${GUNICORN_TIMEOUT:-200} \\\n\
62
- --preload \\\n\
63
- app:app\n\
64
- fi' > /entrypoint.sh && \
65
- chmod +x /entrypoint.sh && \
66
- chown user:user /entrypoint.sh
67
 
68
  # Set up directories and permissions
69
  RUN mkdir -p /var/run/postgresql /var/lib/postgresql/data /data/storage && \
70
  chown -R postgres:postgres /var/run/postgresql /var/lib/postgresql/data && \
71
  chmod 2777 /var/run/postgresql && \
72
- chmod 700 /var/lib/postgresql/data && \
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  chown -R user:user /app
74
 
75
  # Switch to user
76
  USER user
77
 
78
- # Set up user environment (HF requirement)
79
- ENV HOME=/home/user \
80
- PATH=/home/user/.local/bin:$PATH
81
-
82
  # Set required environment variables
83
  ENV EDITION=SELF_HOSTED \
84
  DEPLOY_ENV=PRODUCTION \
@@ -90,10 +65,7 @@ ENV EDITION=SELF_HOSTED \
90
  DB_DATABASE=dify \
91
  MIGRATION_ENABLED=true
92
 
93
- # Expose HF required port
94
  EXPOSE 7860
95
 
96
- WORKDIR /app/api
97
-
98
  ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]
99
 
 
1
+ # base image
2
+ FROM python:3.12-slim-bookworm AS base
3
 
4
  # Create non-root user early (HF requirement)
5
  RUN useradd -m -u 1000 user
6
 
7
+ WORKDIR /app/api
 
 
 
 
 
 
 
 
 
 
8
 
9
+ # Install Poetry
10
+ ENV POETRY_VERSION=1.8.4
11
+ ENV POETRY_HOME=/opt/poetry
12
+ ENV POETRY_CACHE_DIR=/tmp/poetry_cache
13
+ ENV POETRY_NO_INTERACTION=1
14
+ ENV POETRY_VIRTUALENVS_IN_PROJECT=true
15
+ ENV POETRY_VIRTUALENVS_CREATE=true
16
+ ENV POETRY_REQUESTS_TIMEOUT=15
17
 
18
  # Install system dependencies
19
+ RUN apt-get update && \
 
20
  apt-get install -y --no-install-recommends \
21
  gcc g++ libc-dev libffi-dev libgmp-dev libmpfr-dev libmpc-dev \
22
  postgresql postgresql-contrib postgresql-server-dev-all \
23
  curl git nodejs npm && \
24
+ rm -rf /var/lib/apt/lists/* && \
25
+ pip install --no-cache-dir "poetry==${POETRY_VERSION}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
  # Set up directories and permissions
28
  RUN mkdir -p /var/run/postgresql /var/lib/postgresql/data /data/storage && \
29
  chown -R postgres:postgres /var/run/postgresql /var/lib/postgresql/data && \
30
  chmod 2777 /var/run/postgresql && \
31
+ chmod 700 /var/lib/postgresql/data
32
+
33
+ # Copy Poetry files
34
+ COPY --chown=user pyproject.toml poetry.lock ./
35
+
36
+ # Install dependencies
37
+ RUN poetry install --no-root
38
+
39
+ # Copy application code
40
+ COPY --chown=user . .
41
+
42
+ # Set environment variables
43
+ ENV FLASK_APP=/app/api/app.py
44
+ ENV PYTHONPATH=/app/api
45
+ ENV HOME=/home/user
46
+ ENV PATH=/home/user/.local/bin:$PATH
47
+
48
+ # Create and set up entrypoint script
49
+ COPY docker/entrypoint.sh /entrypoint.sh
50
+ RUN chmod +x /entrypoint.sh && \
51
+ chown user:user /entrypoint.sh && \
52
  chown -R user:user /app
53
 
54
  # Switch to user
55
  USER user
56
 
 
 
 
 
57
  # Set required environment variables
58
  ENV EDITION=SELF_HOSTED \
59
  DEPLOY_ENV=PRODUCTION \
 
65
  DB_DATABASE=dify \
66
  MIGRATION_ENABLED=true
67
 
 
68
  EXPOSE 7860
69
 
 
 
70
  ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]
71