Commit
·
3b9d25e
1
Parent(s):
516ca8d
move postgres files to persistent directory + create directories at runtime, not buildtime
Browse files- Dockerfile +20 -13
Dockerfile
CHANGED
|
@@ -8,13 +8,6 @@ RUN apk update && apk add --no-cache \
|
|
| 8 |
postgresql \
|
| 9 |
postgresql-contrib
|
| 10 |
|
| 11 |
-
# Create postgres user and data directory with proper permissions
|
| 12 |
-
RUN echo "Creating postgres user and data directory..."
|
| 13 |
-
RUN mkdir -p /var/lib/postgresql/data /run/postgresql && \
|
| 14 |
-
chown -R postgres:postgres /var/lib/postgresql/data /run/postgresql && \
|
| 15 |
-
chmod 0700 /var/lib/postgresql/data && \
|
| 16 |
-
chmod 0755 /run/postgresql
|
| 17 |
-
|
| 18 |
# Set up environment variables
|
| 19 |
RUN echo "Setting up environment variables..."
|
| 20 |
ENV DATABASE_URL=postgresql://postgres:postgres@localhost:5432/postgres
|
|
@@ -23,22 +16,36 @@ ENV SALT=mysalt
|
|
| 23 |
ENV ENCRYPTION_KEY=0000000000000000000000000000000000000000000000000000000000000000
|
| 24 |
ENV NEXTAUTH_URL=http://localhost:3000
|
| 25 |
|
| 26 |
-
# Simplified wrapper script
|
| 27 |
RUN echo "Creating wrapper script..."
|
| 28 |
COPY <<EOF /docker-entrypoint-wrapper.sh
|
| 29 |
#!/bin/sh
|
| 30 |
|
| 31 |
-
#
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
# Wait for PostgreSQL to be ready
|
| 37 |
-
until pg_isready; do
|
| 38 |
echo "Waiting for PostgreSQL to be ready..."
|
| 39 |
sleep 1
|
| 40 |
done
|
| 41 |
|
|
|
|
|
|
|
|
|
|
| 42 |
# Run the original entrypoint script
|
| 43 |
./web/entrypoint.sh node ./web/server.js --keepAliveTimeout 110000
|
| 44 |
EOF
|
|
|
|
| 8 |
postgresql \
|
| 9 |
postgresql-contrib
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
# Set up environment variables
|
| 12 |
RUN echo "Setting up environment variables..."
|
| 13 |
ENV DATABASE_URL=postgresql://postgres:postgres@localhost:5432/postgres
|
|
|
|
| 16 |
ENV ENCRYPTION_KEY=0000000000000000000000000000000000000000000000000000000000000000
|
| 17 |
ENV NEXTAUTH_URL=http://localhost:3000
|
| 18 |
|
| 19 |
+
# Simplified wrapper script using /data for persistence
|
| 20 |
RUN echo "Creating wrapper script..."
|
| 21 |
COPY <<EOF /docker-entrypoint-wrapper.sh
|
| 22 |
#!/bin/sh
|
| 23 |
|
| 24 |
+
# Create necessary directories in the persistent /data volume
|
| 25 |
+
mkdir -p /data/postgresql/data /data/postgresql/run
|
| 26 |
+
chmod 0700 /data/postgresql/data
|
| 27 |
+
chmod 0755 /data/postgresql/run
|
| 28 |
+
|
| 29 |
+
# Initialize PostgreSQL if not already initialized
|
| 30 |
+
if [ ! -f "/data/postgresql/data/PG_VERSION" ]; then
|
| 31 |
+
initdb -D /data/postgresql/data
|
| 32 |
+
fi
|
| 33 |
+
|
| 34 |
+
# Start PostgreSQL with the persistent directories
|
| 35 |
+
pg_ctl -D /data/postgresql/data -o "-c listen_addresses='*' -c unix_socket_directories='/data/postgresql/run'" start
|
| 36 |
+
|
| 37 |
+
# Create database if it doesn't exist
|
| 38 |
+
createdb -h /data/postgresql/run -U postgres postgres || true
|
| 39 |
|
| 40 |
# Wait for PostgreSQL to be ready
|
| 41 |
+
until pg_isready -h /data/postgresql/run; do
|
| 42 |
echo "Waiting for PostgreSQL to be ready..."
|
| 43 |
sleep 1
|
| 44 |
done
|
| 45 |
|
| 46 |
+
# Update DATABASE_URL to use the correct socket directory
|
| 47 |
+
export DATABASE_URL="postgresql://postgres:postgres@%2Fdata%2Fpostgresql%2Frun:5432/postgres"
|
| 48 |
+
|
| 49 |
# Run the original entrypoint script
|
| 50 |
./web/entrypoint.sh node ./web/server.js --keepAliveTimeout 110000
|
| 51 |
EOF
|