Severian commited on
Commit
a36ef66
·
verified ·
1 Parent(s): e7a94f7

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +32 -22
Dockerfile CHANGED
@@ -7,7 +7,8 @@ ENV POETRY_VERSION=1.8.4 \
7
  POETRY_VIRTUALENVS_CREATE=true \
8
  POETRY_VIRTUALENVS_IN_PROJECT=true \
9
  POETRY_CACHE_DIR=/tmp/poetry_cache \
10
- PYTHONDONTWRITEBYTECODE=1
 
11
 
12
  # Create user first (HF Spaces requirement)
13
  RUN useradd -m -u 1000 user
@@ -23,15 +24,16 @@ RUN apt-get update && apt-get install -y \
23
  libmpc-dev \
24
  nodejs \
25
  npm \
26
- postgresql \
27
- postgresql-contrib \
 
28
  && rm -rf /var/lib/apt/lists/* \
29
  && pip install --no-cache-dir "poetry==${POETRY_VERSION}"
30
 
31
  # Set up PostgreSQL directories and permissions
32
- RUN mkdir -p /var/run/postgresql /var/lib/postgresql/data /var/log/postgresql && \
33
- chown -R user:user /var/run/postgresql /var/lib/postgresql/data /var/log/postgresql && \
34
- chmod 700 /var/lib/postgresql/data
35
 
36
  # Create application directories
37
  RUN mkdir -p /app/api /app/web /data/storage && \
@@ -43,7 +45,8 @@ USER user
43
 
44
  # Set environment for user
45
  ENV HOME=/home/user \
46
- PATH=/home/user/.local/bin:$PATH
 
47
 
48
  # Pull official images
49
  FROM langgenius/dify-web:latest AS web
@@ -97,21 +100,24 @@ EXPOSE 7860
97
  RUN echo '#!/bin/bash\n\
98
  echo "===== Application Startup at $(date "+%Y-%m-%d %H:%M:%S") ====="\n\
99
  \n\
100
- # Initialize PostgreSQL database\n\
101
- initdb -D $HOME/postgresql/data\n\
102
- \n\
103
- # Configure PostgreSQL\n\
104
- echo "host all all 0.0.0.0/0 md5" >> $HOME/postgresql/data/pg_hba.conf\n\
105
- echo "listen_addresses='\''*'\''" >> $HOME/postgresql/data/postgresql.conf\n\
 
 
 
106
  \n\
107
  # Start PostgreSQL\n\
108
- pg_ctl -D $HOME/postgresql/data -l $HOME/postgresql/logfile start\n\
109
  \n\
110
  # Wait for PostgreSQL to start\n\
111
  max_tries=30\n\
112
  count=0\n\
113
  echo "Checking database connection..."\n\
114
- until psql -h localhost -p 5432 -U user -d postgres -c "SELECT 1" > /dev/null 2>&1; do\n\
115
  echo "Waiting for database connection... (${count}/${max_tries})"\n\
116
  sleep 2\n\
117
  count=$((count+1))\n\
@@ -121,19 +127,23 @@ until psql -h localhost -p 5432 -U user -d postgres -c "SELECT 1" > /dev/null 2>
121
  fi\n\
122
  done\n\
123
  \n\
124
- # Create database\n\
125
- createdb ${DB_DATABASE}\n\
 
 
 
 
126
  \n\
127
  echo "Database connection successful"\n\
128
  \n\
129
  # Start application services\n\
130
  cd /app/api && poetry run python -m flask db upgrade\n\
131
  \n\
132
- cd /app/api && poetry run python -m gunicorn app:app \
133
- --bind ${DIFY_BIND_ADDRESS:-0.0.0.0}:${DIFY_PORT:-7860} \
134
- --worker-class gevent \
135
- --workers 1 \
136
- --timeout 300 \
137
  --preload &\n\
138
  \n\
139
  cd /app/web && node server.js &\n\
 
7
  POETRY_VIRTUALENVS_CREATE=true \
8
  POETRY_VIRTUALENVS_IN_PROJECT=true \
9
  POETRY_CACHE_DIR=/tmp/poetry_cache \
10
+ PYTHONDONTWRITEBYTECODE=1 \
11
+ PATH=/usr/lib/postgresql/15/bin:$PATH
12
 
13
  # Create user first (HF Spaces requirement)
14
  RUN useradd -m -u 1000 user
 
24
  libmpc-dev \
25
  nodejs \
26
  npm \
27
+ postgresql-15 \
28
+ postgresql-contrib-15 \
29
+ postgresql-client-15 \
30
  && rm -rf /var/lib/apt/lists/* \
31
  && pip install --no-cache-dir "poetry==${POETRY_VERSION}"
32
 
33
  # Set up PostgreSQL directories and permissions
34
+ RUN mkdir -p /home/user/postgresql/data /home/user/postgresql/logs && \
35
+ chown -R user:user /home/user/postgresql && \
36
+ chmod 700 /home/user/postgresql/data
37
 
38
  # Create application directories
39
  RUN mkdir -p /app/api /app/web /data/storage && \
 
45
 
46
  # Set environment for user
47
  ENV HOME=/home/user \
48
+ PATH=/usr/lib/postgresql/15/bin:/home/user/.local/bin:$PATH \
49
+ PGDATA=/home/user/postgresql/data
50
 
51
  # Pull official images
52
  FROM langgenius/dify-web:latest AS web
 
100
  RUN echo '#!/bin/bash\n\
101
  echo "===== Application Startup at $(date "+%Y-%m-%d %H:%M:%S") ====="\n\
102
  \n\
103
+ # Initialize PostgreSQL database if not already initialized\n\
104
+ if [ ! -f "$PGDATA/PG_VERSION" ]; then\n\
105
+ echo "Initializing PostgreSQL database..."\n\
106
+ initdb --auth=trust --encoding=UTF8 --locale=en_US.UTF-8\n\
107
+ \n\
108
+ # Configure PostgreSQL\n\
109
+ echo "host all all 0.0.0.0/0 md5" >> $PGDATA/pg_hba.conf\n\
110
+ echo "listen_addresses = '\''*'\''" >> $PGDATA/postgresql.conf\n\
111
+ fi\n\
112
  \n\
113
  # Start PostgreSQL\n\
114
+ pg_ctl start -D $PGDATA -l /home/user/postgresql/logs/postgresql.log\n\
115
  \n\
116
  # Wait for PostgreSQL to start\n\
117
  max_tries=30\n\
118
  count=0\n\
119
  echo "Checking database connection..."\n\
120
+ until pg_isready -h localhost -p 5432; do\n\
121
  echo "Waiting for database connection... (${count}/${max_tries})"\n\
122
  sleep 2\n\
123
  count=$((count+1))\n\
 
127
  fi\n\
128
  done\n\
129
  \n\
130
+ # Set up database user and permissions\n\
131
+ psql -v ON_ERROR_STOP=1 --username user --dbname postgres <<-EOSQL\n\
132
+ ALTER USER user WITH PASSWORD '\''difyai123456'\'';\n\
133
+ CREATE DATABASE dify;\n\
134
+ GRANT ALL PRIVILEGES ON DATABASE dify TO user;\n\
135
+ EOSQL\n\
136
  \n\
137
  echo "Database connection successful"\n\
138
  \n\
139
  # Start application services\n\
140
  cd /app/api && poetry run python -m flask db upgrade\n\
141
  \n\
142
+ cd /app/api && poetry run python -m gunicorn app:app \\\n\
143
+ --bind ${DIFY_BIND_ADDRESS:-0.0.0.0}:${DIFY_PORT:-7860} \\\n\
144
+ --worker-class gevent \\\n\
145
+ --workers 1 \\\n\
146
+ --timeout 300 \\\n\
147
  --preload &\n\
148
  \n\
149
  cd /app/web && node server.js &\n\