# Generate AUTH_SECRET if not provided if [ -z "$AUTH_SECRET" ]; then if [ -f "/data/.auth_secret" ]; then export AUTH_SECRET=$(cat /data/.auth_secret) else export AUTH_SECRET=$(openssl rand -base64 32) echo"$AUTH_SECRET" > /data/.auth_secret echo"⚠ AUTH_SECRET generated and saved" fi fi
# Initialize PostgreSQL if needed if [ ! -f "$PGDATA/PG_VERSION" ]; then echo"▶ Initializing PostgreSQL..." su postgres -c "$PGBIN/initdb -D $PGDATA" cat >> "$PGDATA/postgresql.conf" << EOF listen_addresses = 'localhost' port = 5432 max_connections = 100 shared_buffers = 128MB EOF cat > "$PGDATA/pg_hba.conf" << EOF local all all trust host all all 127.0.0.1/32 trust host all all ::1/128 trust EOF su postgres -c "$PGBIN/pg_ctl -D $PGDATA -l /tmp/pg.log start" sleep 3 su postgres -c "$PGBIN/createuser -s prompts 2>/dev/null" || true su postgres -c "$PGBIN/createdb -O prompts prompts 2>/dev/null" || true su postgres -c "$PGBIN/pg_ctl -D $PGDATA stop" sleep 2 echo"✓ PostgreSQL initialized" fi
# Clone and build on first run if [ ! -f "$BUILD_MARKER" ]; then echo"" echo"▶ First run detected - building prompts.chat..." echo"" # Clone repository (with retry and network optimization) if [ ! -d "$APP_DIR/.git" ]; then echo"▶ Cloning repository..." rm -rf "$APP_DIR" git config --global http.version HTTP/1.1 git config --global http.postBuffer 524288000 REPO="https://gh-proxy.com/https://github.com/f/prompts.chat.git" [ -n "$REPO_URL" ] && REPO="$REPO_URL" git clone --depth 1 --single-branch --filter=blob:none "$REPO""$APP_DIR" || \ git clone --depth 1 --single-branch "$REPO""$APP_DIR" echo"✓ Repository cloned" fi cd"$APP_DIR" # Clean up unnecessary files rm -rf .github .claude packages .git # Install dependencies (optimized) echo"▶ Installing dependencies..." npm config set registry https://registry.npmmirror.com npm config set fetch-timeout 300000 npm config set fetch-retries 5 npm config set fetch-retry-mintimeout 20000 npm config set fetch-retry-maxtimeout 120000 npm cache clean --force PRISMA_SKIP_POSTINSTALL_GENERATE=1 NODE_ENV=development npm ci --no-audit --no-fund --progress=false echo"✓ Dependencies installed" # Run docker-setup.js to generate config with branding echo"▶ Generating configuration..." node scripts/docker-setup.js echo"✓ Configuration generated" # Generate Prisma client echo"▶ Generating Prisma client..." npx prisma generate echo"✓ Prisma client generated" # Build Next.js (DISABLE TURBOPACK - use webpack) echo"▶ Building Next.js application (this may take a few minutes)..." npx next build --webpack echo"✓ Build complete" # Copy static files for standalone mode echo"▶ Copying static assets..." cp -r .next/static .next/standalone/.next/ cp -r public .next/standalone/ echo"✓ Static assets copied" # Mark as built touch"$BUILD_MARKER" echo"" echo"✅ Build complete! Starting application..." echo"" else echo"✓ Using existing build" cd"$APP_DIR" fi
# Wait for PostgreSQL echo"▶ Waiting for PostgreSQL..." for i in $(seq 1 30); do if$PGBIN/pg_isready -h localhost -p 5432 >/dev/null 2>&1; then echo"✓ PostgreSQL is ready" break fi if [ $i -eq 30 ]; then echo"✗ PostgreSQL failed to start" exit 1 fi sleep 1 done
# Seed on first run only SEED_MARKER="/data/.seeded" if [ ! -f "$SEED_MARKER" ]; then echo"▶ Seeding database..." if npx tsx prisma/seed.ts 2>/dev/null; then touch"$SEED_MARKER" echo"✓ Database seeded" else echo"⚠ Seeding skipped" fi fi
# Wait for supervisord to be ready echo"▶ Waiting for supervisord..." for i in $(seq 1 30); do ifkill -0 $SUPERVISOR_PID 2>/dev/null && [ -S /var/run/supervisor.sock ]; then echo"✓ Supervisord is ready" break fi if ! kill -0 $SUPERVISOR_PID 2>/dev/null; then echo"✗ Supervisord process died" exit 1 fi if [ $i -eq 30 ]; then echo"✗ Supervisord socket not available after 30s" exit 1 fi sleep 1 done
f/prompts.chat: f.k.a. Awesome ChatGPT Prompts. Share, discover, and collect prompts from the community. Free and open source — self-host for your organization with complete privacy. 地址:https://github.com/f/prompts.chat
prompts.chat - AI Prompts Community 地址:https://prompts.chat/