postgres shadow
Build and Push Docker Images / build-and-push (push) Failing after 22s

This commit is contained in:
2025-05-21 20:54:15 +02:00
parent c8ec96d448
commit 4e237f1737
2 changed files with 45 additions and 0 deletions
+20
View File
@@ -0,0 +1,20 @@
FROM postgres:15
# Install additional tools
RUN apt-get update && apt-get install -y \
postgresql-client \
&& rm -rf /var/lib/apt/lists/*
# Create directory for scripts
RUN mkdir -p /docker-entrypoint-initdb.d
# Copy initialization script
COPY init.sh /docker-entrypoint-initdb.d/
RUN chmod +x /docker-entrypoint-initdb.d/init.sh
# Environment variables
ENV SOURCE_DB_URL=""
ENV TARGET_DB_NAME="shadow_db"
# Expose PostgreSQL port
EXPOSE 5432
+25
View File
@@ -0,0 +1,25 @@
#!/bin/bash
set -e
# Wait for PostgreSQL to be ready
until pg_isready; do
echo "Waiting for PostgreSQL to be ready..."
sleep 2
done
# Create the target database
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
CREATE DATABASE $TARGET_DB_NAME;
EOSQL
# Copy the database if SOURCE_DB_URL is provided
if [ ! -z "$SOURCE_DB_URL" ]; then
echo "Copying database from $SOURCE_DB_URL to $TARGET_DB_NAME..."
# Dump the source database
pg_dump "$SOURCE_DB_URL" | psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$TARGET_DB_NAME"
echo "Database copy completed successfully"
else
echo "No SOURCE_DB_URL provided, skipping database copy"
fi