Severian commited on
Commit
73efd4a
·
verified ·
1 Parent(s): e830ccd

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +35 -20
Dockerfile CHANGED
@@ -24,6 +24,20 @@ RUN pip install --no-cache-dir "poetry==${POETRY_VERSION}" && \
24
  postgresql postgresql-contrib curl git nodejs npm && \
25
  rm -rf /var/lib/apt/lists/*
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 && \
@@ -31,33 +45,34 @@ RUN mkdir -p /var/run/postgresql /var/lib/postgresql/data /data/storage && \
31
  chmod 700 /var/lib/postgresql/data && \
32
  chown -R user:user /app /opt/poetry /tmp/poetry_cache
33
 
34
- # Switch to user for Poetry operations
35
- USER user
36
-
37
- # Copy dependency files with correct ownership
38
- COPY --chown=user pyproject.toml poetry.lock poetry.toml ./
39
-
40
- # Install Python dependencies
41
- RUN poetry install --no-root --no-dev
42
-
43
- # Initialize PostgreSQL as postgres user
44
- USER postgres
45
- RUN /usr/lib/postgresql/15/bin/initdb -D /var/lib/postgresql/data && \
46
- echo "host all all 0.0.0.0/0 md5" >> /var/lib/postgresql/data/pg_hba.conf && \
47
- echo "listen_addresses='*'" >> /var/lib/postgresql/data/postgresql.conf
48
-
49
- # Switch back to user
50
  USER user
51
 
52
  # Set up user environment (HF requirement)
53
  ENV HOME=/home/user \
54
  PATH=/home/user/.local/bin:$PATH
55
 
56
- # Copy source code
57
- COPY --chown=user . .
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
 
59
- # Copy entrypoint script
60
- COPY entrypoint.sh /entrypoint.sh
61
  RUN chmod +x /entrypoint.sh
62
 
63
  # Set required environment variables
 
24
  postgresql postgresql-contrib curl git nodejs npm && \
25
  rm -rf /var/lib/apt/lists/*
26
 
27
+ # Create a requirements.txt from poetry dependencies
28
+ RUN echo "flask==3.0.1\n\
29
+ gunicorn==22.0.0\n\
30
+ gevent==24.11.1\n\
31
+ celery==5.4.0\n\
32
+ redis==5.0.3\n\
33
+ psycopg2-binary==2.9.6\n\
34
+ sqlalchemy==2.0.29\n\
35
+ flask-migrate==4.0.5\n\
36
+ flask-sqlalchemy==3.1.1" > requirements.txt
37
+
38
+ # Install Python dependencies
39
+ RUN pip install --no-cache-dir -r requirements.txt
40
+
41
  # Set up directories and permissions
42
  RUN mkdir -p /var/run/postgresql /var/lib/postgresql/data /data/storage && \
43
  chown -R postgres:postgres /var/run/postgresql /var/lib/postgresql/data && \
 
45
  chmod 700 /var/lib/postgresql/data && \
46
  chown -R user:user /app /opt/poetry /tmp/poetry_cache
47
 
48
+ # Switch to user
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  USER user
50
 
51
  # Set up user environment (HF requirement)
52
  ENV HOME=/home/user \
53
  PATH=/home/user/.local/bin:$PATH
54
 
55
+ # Create and copy entrypoint script
56
+ RUN echo '#!/bin/bash\n\
57
+ set -e\n\
58
+ \n\
59
+ if [[ "${MIGRATION_ENABLED}" == "true" ]]; then\n\
60
+ echo "Running migrations"\n\
61
+ flask upgrade-db\n\
62
+ fi\n\
63
+ \n\
64
+ if [[ "${DEBUG}" == "true" ]]; then\n\
65
+ exec flask run --host=${DIFY_BIND_ADDRESS:-0.0.0.0} --port=7860 --debug\n\
66
+ else\n\
67
+ exec gunicorn \\\n\
68
+ --bind "0.0.0.0:7860" \\\n\
69
+ --workers ${SERVER_WORKER_AMOUNT:-1} \\\n\
70
+ --worker-class ${SERVER_WORKER_CLASS:-gevent} \\\n\
71
+ --timeout ${GUNICORN_TIMEOUT:-200} \\\n\
72
+ --preload \\\n\
73
+ app:app\n\
74
+ fi' > /entrypoint.sh
75
 
 
 
76
  RUN chmod +x /entrypoint.sh
77
 
78
  # Set required environment variables