Update Dockerfile
Browse files- Dockerfile +18 -18
Dockerfile
CHANGED
@@ -91,17 +91,17 @@ ENV FLASK_APP=app.py \
|
|
91 |
DEBUG=false \
|
92 |
FLASK_DEBUG=false \
|
93 |
SECRET_KEY=sk-9f73s3ljTXVcMT3Blb3ljTqtsKiGHXVcMT3BlbkFJLK7U \
|
94 |
-
CONSOLE_API_URL=
|
95 |
-
CONSOLE_WEB_URL=
|
96 |
-
SERVICE_API_URL=
|
97 |
-
APP_WEB_URL=
|
98 |
DIFY_PORT=7860 \
|
99 |
DIFY_BIND_ADDRESS=0.0.0.0 \
|
100 |
-
DB_USERNAME
|
101 |
-
DB_PASSWORD
|
102 |
-
DB_HOST
|
103 |
-
DB_PORT
|
104 |
-
DB_DATABASE
|
105 |
REDIS_HOST=localhost \
|
106 |
REDIS_PORT=6379 \
|
107 |
REDIS_PASSWORD=difyai123456 \
|
@@ -116,26 +116,26 @@ EXPOSE 7860 3000
|
|
116 |
RUN echo '#!/bin/bash\n\
|
117 |
echo "===== Application Startup at $(date "+%Y-%m-%d %H:%M:%S") ====="\n\
|
118 |
\n\
|
119 |
-
# Start PostgreSQL
|
120 |
-
|
|
|
|
|
121 |
\n\
|
122 |
max_tries=30\n\
|
123 |
count=0\n\
|
124 |
echo "Checking database connection..."\n\
|
125 |
-
until PGPASSWORD
|
126 |
-
echo "Waiting for database connection..."\n\
|
127 |
sleep 2\n\
|
128 |
count=$((count+1))\n\
|
129 |
if [ $count -gt $max_tries ]; then\n\
|
130 |
-
echo "Failed to connect to database after $max_tries attempts"\n\
|
131 |
exit 1\n\
|
132 |
fi\n\
|
133 |
done\n\
|
134 |
\n\
|
135 |
-
# Create database
|
136 |
-
PGPASSWORD
|
137 |
-
PGPASSWORD=$DB_PASSWORD psql -h localhost -U postgres -c "CREATE USER $DB_USERNAME WITH PASSWORD '\''$DB_PASSWORD'\'';" || true\n\
|
138 |
-
PGPASSWORD=$DB_PASSWORD psql -h localhost -U postgres -c "GRANT ALL PRIVILEGES ON DATABASE $DB_DATABASE TO $DB_USERNAME;" || true\n\
|
139 |
\n\
|
140 |
echo "Database connection successful"\n\
|
141 |
\n\
|
|
|
91 |
DEBUG=false \
|
92 |
FLASK_DEBUG=false \
|
93 |
SECRET_KEY=sk-9f73s3ljTXVcMT3Blb3ljTqtsKiGHXVcMT3BlbkFJLK7U \
|
94 |
+
CONSOLE_API_URL=https://${SPACE_ID}.hf.space \
|
95 |
+
CONSOLE_WEB_URL=https://${SPACE_ID}.hf.space \
|
96 |
+
SERVICE_API_URL=https://${SPACE_ID}.hf.space \
|
97 |
+
APP_WEB_URL=https://${SPACE_ID}.hf.space \
|
98 |
DIFY_PORT=7860 \
|
99 |
DIFY_BIND_ADDRESS=0.0.0.0 \
|
100 |
+
DB_USERNAME=${POSTGRES_USER:-postgres} \
|
101 |
+
DB_PASSWORD=${POSTGRES_PASSWORD:-difyai123456} \
|
102 |
+
DB_HOST=${POSTGRES_HOST:-localhost} \
|
103 |
+
DB_PORT=${POSTGRES_PORT:-5432} \
|
104 |
+
DB_DATABASE=${POSTGRES_DB:-dify} \
|
105 |
REDIS_HOST=localhost \
|
106 |
REDIS_PORT=6379 \
|
107 |
REDIS_PASSWORD=difyai123456 \
|
|
|
116 |
RUN echo '#!/bin/bash\n\
|
117 |
echo "===== Application Startup at $(date "+%Y-%m-%d %H:%M:%S") ====="\n\
|
118 |
\n\
|
119 |
+
# Start PostgreSQL with proper permissions\n\
|
120 |
+
mkdir -p /var/log/postgresql\n\
|
121 |
+
chown postgres:postgres /var/log/postgresql\n\
|
122 |
+
su - postgres -c "/usr/lib/postgresql/15/bin/pg_ctl -D /var/lib/postgresql/data -l /var/log/postgresql/postgresql.log start"\n\
|
123 |
\n\
|
124 |
max_tries=30\n\
|
125 |
count=0\n\
|
126 |
echo "Checking database connection..."\n\
|
127 |
+
until PGPASSWORD="${DB_PASSWORD}" psql -h "${DB_HOST}" -p "${DB_PORT}" -U "${DB_USERNAME}" -d postgres -c "SELECT 1" > /dev/null 2>&1; do\n\
|
128 |
+
echo "Waiting for database connection... (${count}/${max_tries})"\n\
|
129 |
sleep 2\n\
|
130 |
count=$((count+1))\n\
|
131 |
if [ $count -gt $max_tries ]; then\n\
|
132 |
+
echo "Failed to connect to database after ${max_tries} attempts"\n\
|
133 |
exit 1\n\
|
134 |
fi\n\
|
135 |
done\n\
|
136 |
\n\
|
137 |
+
# Create database if it doesnt exist\n\
|
138 |
+
PGPASSWORD="${DB_PASSWORD}" psql -h "${DB_HOST}" -p "${DB_PORT}" -U "${DB_USERNAME}" -d postgres -c "CREATE DATABASE ${DB_DATABASE};" || true\n\
|
|
|
|
|
139 |
\n\
|
140 |
echo "Database connection successful"\n\
|
141 |
\n\
|