redaction (#1)
Add the redacted source file for demo purposes Reviewed-on: https://source.michaeldileo.org/michael_dileo/Keybard-Vagabond-Demo/pulls/1 Co-authored-by: Michael DiLeo <michael_dileo@proton.me> Co-committed-by: Michael DiLeo <michael_dileo@proton.me>
This commit was merged in pull request #1.
This commit is contained in:
116
build/pixelfed/pixelfed-base/entrypoint-common.sh
Normal file
116
build/pixelfed/pixelfed-base/entrypoint-common.sh
Normal file
@@ -0,0 +1,116 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
# Common functions for Pixelfed containers
|
||||
|
||||
# Setup directories and create necessary structure
|
||||
setup_directories() {
|
||||
echo "Setting up directories..."
|
||||
mkdir -p /var/www/pixelfed/storage
|
||||
mkdir -p /var/www/pixelfed/bootstrap/cache
|
||||
|
||||
# CRITICAL FIX: Remove stale package discovery cache files
|
||||
echo "Removing stale package discovery cache files..."
|
||||
rm -f /var/www/pixelfed/bootstrap/cache/packages.php || true
|
||||
rm -f /var/www/pixelfed/bootstrap/cache/services.php || true
|
||||
}
|
||||
|
||||
# Wait for database to be ready
|
||||
wait_for_database() {
|
||||
echo "Waiting for database connection..."
|
||||
cd /var/www/pixelfed
|
||||
|
||||
# Try for up to 60 seconds
|
||||
for i in $(seq 1 12); do
|
||||
if su-exec pixelfed php artisan migrate:status >/dev/null 2>&1; then
|
||||
echo "Database is ready!"
|
||||
return 0
|
||||
fi
|
||||
echo "Database not ready yet, waiting... (attempt $i/12)"
|
||||
sleep 5
|
||||
done
|
||||
|
||||
echo "ERROR: Database connection failed after 60 seconds"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Run database migrations (only if needed)
|
||||
setup_database() {
|
||||
echo "Checking database migrations..."
|
||||
cd /var/www/pixelfed
|
||||
|
||||
# Only run migrations if they haven't been run
|
||||
if ! su-exec pixelfed php artisan migrate:status | grep -q "Y"; then
|
||||
echo "Running database migrations..."
|
||||
su-exec pixelfed php artisan migrate --force
|
||||
else
|
||||
echo "Database migrations are up to date"
|
||||
fi
|
||||
}
|
||||
|
||||
# Generate application key if not set
|
||||
setup_app_key() {
|
||||
if [ -z "$APP_KEY" ] || [ "$APP_KEY" = "base64:" ]; then
|
||||
echo "Generating application key..."
|
||||
cd /var/www/pixelfed
|
||||
su-exec pixelfed php artisan key:generate --force
|
||||
fi
|
||||
}
|
||||
|
||||
# Cache configuration (safe to run multiple times)
|
||||
cache_config() {
|
||||
echo "Clearing and caching configuration..."
|
||||
cd /var/www/pixelfed
|
||||
# Clear all caches first to avoid stale service provider registrations
|
||||
su-exec pixelfed php artisan config:clear || true
|
||||
su-exec pixelfed php artisan route:clear || true
|
||||
su-exec pixelfed php artisan view:clear || true
|
||||
su-exec pixelfed php artisan cache:clear || true
|
||||
|
||||
# Remove package discovery cache files and regenerate them
|
||||
rm -f bootstrap/cache/packages.php bootstrap/cache/services.php || true
|
||||
su-exec pixelfed php artisan package:discover --ansi || true
|
||||
|
||||
# Now rebuild caches with fresh configuration
|
||||
su-exec pixelfed php artisan config:cache
|
||||
su-exec pixelfed php artisan route:cache
|
||||
su-exec pixelfed php artisan view:cache
|
||||
}
|
||||
|
||||
# Link storage if not already linked
|
||||
setup_storage_link() {
|
||||
if [ ! -L "/var/www/pixelfed/public/storage" ]; then
|
||||
echo "Linking storage..."
|
||||
cd /var/www/pixelfed
|
||||
su-exec pixelfed php artisan storage:link
|
||||
fi
|
||||
}
|
||||
|
||||
# Import location data (only on first run)
|
||||
import_location_data() {
|
||||
if [ ! -f "/var/www/pixelfed/.location-imported" ]; then
|
||||
echo "Importing location data..."
|
||||
cd /var/www/pixelfed
|
||||
su-exec pixelfed php artisan import:cities || true
|
||||
touch /var/www/pixelfed/.location-imported
|
||||
fi
|
||||
}
|
||||
|
||||
# Main initialization function
|
||||
initialize_pixelfed() {
|
||||
echo "Initializing Pixelfed..."
|
||||
|
||||
setup_directories
|
||||
|
||||
# Only the first container should run these
|
||||
if [ "${PIXELFED_INIT_CONTAINER:-false}" = "true" ]; then
|
||||
setup_database
|
||||
setup_app_key
|
||||
import_location_data
|
||||
fi
|
||||
|
||||
cache_config
|
||||
setup_storage_link
|
||||
|
||||
echo "Pixelfed initialization complete!"
|
||||
}
|
||||
Reference in New Issue
Block a user