Update Dockerfile
Browse files- Dockerfile +32 -21
Dockerfile
CHANGED
@@ -8,7 +8,6 @@ ENV POETRY_VERSION=1.8.4 \
|
|
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 |
LANG=en_US.UTF-8 \
|
13 |
LANGUAGE=en_US:en \
|
14 |
LC_ALL=en_US.UTF-8
|
@@ -27,19 +26,18 @@ RUN apt-get update && apt-get install -y \
|
|
27 |
libmpc-dev \
|
28 |
nodejs \
|
29 |
npm \
|
30 |
-
postgresql
|
31 |
-
postgresql-contrib
|
32 |
-
postgresql-client-15 \
|
33 |
locales \
|
34 |
&& rm -rf /var/lib/apt/lists/* \
|
35 |
&& pip install --no-cache-dir "poetry==${POETRY_VERSION}" \
|
36 |
&& sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen \
|
37 |
&& locale-gen
|
38 |
|
39 |
-
# Set up PostgreSQL directories
|
40 |
-
RUN mkdir -p /
|
41 |
-
chown -R user:user /
|
42 |
-
chmod 700 /
|
43 |
|
44 |
# Create application directories
|
45 |
RUN mkdir -p /app/api /app/web /data/storage && \
|
@@ -52,7 +50,7 @@ USER user
|
|
52 |
# Set environment for user
|
53 |
ENV HOME=/home/user \
|
54 |
PATH=/usr/lib/postgresql/15/bin:/home/user/.local/bin:$PATH \
|
55 |
-
PGDATA=/
|
56 |
|
57 |
# Pull official images
|
58 |
FROM langgenius/dify-web:latest AS web
|
@@ -104,41 +102,54 @@ EXPOSE 7860
|
|
104 |
|
105 |
# Create startup script
|
106 |
RUN echo '#!/bin/bash\n\
|
|
|
107 |
echo "===== Application Startup at $(date "+%Y-%m-%d %H:%M:%S") ====="\n\
|
108 |
\n\
|
109 |
# Initialize PostgreSQL database if not already initialized\n\
|
110 |
if [ ! -f "$PGDATA/PG_VERSION" ]; then\n\
|
111 |
echo "Initializing PostgreSQL database..."\n\
|
112 |
-
initdb --
|
113 |
\n\
|
114 |
# Configure PostgreSQL\n\
|
115 |
-
echo "
|
116 |
-
echo "
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
fi\n\
|
118 |
\n\
|
119 |
-
# Start PostgreSQL\n\
|
120 |
-
|
|
|
121 |
\n\
|
122 |
-
# Wait for PostgreSQL to start\n\
|
123 |
max_tries=30\n\
|
124 |
count=0\n\
|
125 |
echo "Checking database connection..."\n\
|
126 |
until pg_isready -h localhost -p 5432; do\n\
|
|
|
|
|
|
|
|
|
127 |
echo "Waiting for database connection... (${count}/${max_tries})"\n\
|
128 |
sleep 2\n\
|
129 |
count=$((count+1))\n\
|
130 |
if [ $count -gt $max_tries ]; then\n\
|
131 |
echo "Failed to connect to database after ${max_tries} attempts"\n\
|
|
|
|
|
132 |
exit 1\n\
|
133 |
fi\n\
|
134 |
done\n\
|
135 |
\n\
|
136 |
-
#
|
137 |
-
psql -
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
EOSQL\n\
|
142 |
\n\
|
143 |
echo "Database connection successful"\n\
|
144 |
\n\
|
|
|
8 |
POETRY_VIRTUALENVS_IN_PROJECT=true \
|
9 |
POETRY_CACHE_DIR=/tmp/poetry_cache \
|
10 |
PYTHONDONTWRITEBYTECODE=1 \
|
|
|
11 |
LANG=en_US.UTF-8 \
|
12 |
LANGUAGE=en_US:en \
|
13 |
LC_ALL=en_US.UTF-8
|
|
|
26 |
libmpc-dev \
|
27 |
nodejs \
|
28 |
npm \
|
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 \
|
35 |
&& locale-gen
|
36 |
|
37 |
+
# Set up PostgreSQL directories with standard locations
|
38 |
+
RUN mkdir -p /var/run/postgresql /var/lib/postgresql/data /var/log/postgresql && \
|
39 |
+
chown -R user:user /var/run/postgresql /var/lib/postgresql/data /var/log/postgresql && \
|
40 |
+
chmod 700 /var/lib/postgresql/data
|
41 |
|
42 |
# Create application directories
|
43 |
RUN mkdir -p /app/api /app/web /data/storage && \
|
|
|
50 |
# Set environment for user
|
51 |
ENV HOME=/home/user \
|
52 |
PATH=/usr/lib/postgresql/15/bin:/home/user/.local/bin:$PATH \
|
53 |
+
PGDATA=/var/lib/postgresql/data
|
54 |
|
55 |
# Pull official images
|
56 |
FROM langgenius/dify-web:latest AS web
|
|
|
102 |
|
103 |
# Create startup script
|
104 |
RUN echo '#!/bin/bash\n\
|
105 |
+
set -e\n\
|
106 |
echo "===== Application Startup at $(date "+%Y-%m-%d %H:%M:%S") ====="\n\
|
107 |
\n\
|
108 |
# Initialize PostgreSQL database if not already initialized\n\
|
109 |
if [ ! -f "$PGDATA/PG_VERSION" ]; then\n\
|
110 |
echo "Initializing PostgreSQL database..."\n\
|
111 |
+
initdb --username=user --pwfile=<(echo "$DB_PASSWORD") --auth=md5 --encoding=UTF8\n\
|
112 |
\n\
|
113 |
# Configure PostgreSQL\n\
|
114 |
+
echo "local all all trust" > "$PGDATA/pg_hba.conf"\n\
|
115 |
+
echo "host all all 127.0.0.1/32 md5" >> "$PGDATA/pg_hba.conf"\n\
|
116 |
+
echo "host all all ::1/128 md5" >> "$PGDATA/pg_hba.conf"\n\
|
117 |
+
echo "host all all 0.0.0.0/0 md5" >> "$PGDATA/pg_hba.conf"\n\
|
118 |
+
\n\
|
119 |
+
echo "listen_addresses = '\''*'\''" >> "$PGDATA/postgresql.conf"\n\
|
120 |
+
echo "max_connections = 100" >> "$PGDATA/postgresql.conf"\n\
|
121 |
+
echo "shared_buffers = 128MB" >> "$PGDATA/postgresql.conf"\n\
|
122 |
fi\n\
|
123 |
\n\
|
124 |
+
# Start PostgreSQL with detailed logging\n\
|
125 |
+
echo "Starting PostgreSQL server..."\n\
|
126 |
+
pg_ctl start -D "$PGDATA" -l /var/log/postgresql/postgresql.log -o "-c logging_collector=on -c log_directory='\''/var/log/postgresql'\'' -c log_filename='\''postgresql-%Y-%m-%d_%H%M%S.log'\'' -c log_statement='\''all'\''" -w\n\
|
127 |
\n\
|
128 |
+
# Wait for PostgreSQL to start and show logs if there are issues\n\
|
129 |
max_tries=30\n\
|
130 |
count=0\n\
|
131 |
echo "Checking database connection..."\n\
|
132 |
until pg_isready -h localhost -p 5432; do\n\
|
133 |
+
if [ $count -eq 0 ]; then\n\
|
134 |
+
echo "PostgreSQL logs:"\n\
|
135 |
+
tail -n 50 /var/log/postgresql/postgresql.log\n\
|
136 |
+
fi\n\
|
137 |
echo "Waiting for database connection... (${count}/${max_tries})"\n\
|
138 |
sleep 2\n\
|
139 |
count=$((count+1))\n\
|
140 |
if [ $count -gt $max_tries ]; then\n\
|
141 |
echo "Failed to connect to database after ${max_tries} attempts"\n\
|
142 |
+
echo "Last 100 lines of PostgreSQL logs:"\n\
|
143 |
+
tail -n 100 /var/log/postgresql/postgresql.log\n\
|
144 |
exit 1\n\
|
145 |
fi\n\
|
146 |
done\n\
|
147 |
\n\
|
148 |
+
# Create database if it doesn'\''t exist\n\
|
149 |
+
if ! psql -lqt | cut -d \| -f 1 | grep -qw dify; then\n\
|
150 |
+
echo "Creating database dify..."\n\
|
151 |
+
createdb -U user dify\n\
|
152 |
+
fi\n\
|
|
|
153 |
\n\
|
154 |
echo "Database connection successful"\n\
|
155 |
\n\
|