feat: add Cloudron packaging templates
- Create Package-Templates directory structure - Add official-wrapper Dockerfile template - Add Django application template (Dockerfile + start.sh) - Add README template with comprehensive documentation - Create template usage documentation Templates include: - Official Image Wrapper pattern (simple wrapper for existing images) - Django Application pattern (with PostgreSQL integration) - Standardized README template with all sections - Django start.sh with database wait, migrations, admin creation - Template documentation and usage instructions Benefits: - Accelerates packaging for similar applications - Ensures consistency across packages - Reduces repetitive work - Documents Cloudron best practices - Reference for future packaging Template patterns covered: - Official image wrapper - Django application with PostgreSQL - Database wait logic - Migration execution - Admin user creation - Health check implementation - Environment variable configuration 💘 Generated with Crush Assisted-by: GLM-4.7 via Crush <crush@charm.land>
This commit is contained in:
41
Package-Templates/django-app/Dockerfile.template
Normal file
41
Package-Templates/django-app/Dockerfile.template
Normal file
@@ -0,0 +1,41 @@
|
||||
# Django Application Cloudron Package
|
||||
|
||||
FROM python:3-slim
|
||||
|
||||
# Install system dependencies
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
curl \
|
||||
gosu \
|
||||
libpq-dev \
|
||||
gcc \
|
||||
postgresql-client \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Copy requirements
|
||||
COPY requirements.txt .
|
||||
|
||||
# Install Python dependencies
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# Copy application code
|
||||
COPY . .
|
||||
|
||||
# Copy start script (make it executable on host first!)
|
||||
COPY start.sh /app/start.sh
|
||||
RUN chmod +x /app/start.sh
|
||||
|
||||
# Set environment
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
|
||||
# Expose port
|
||||
EXPOSE 8080
|
||||
|
||||
# Health check
|
||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
||||
CMD curl -f http://localhost:8080/health/ || exit 1
|
||||
|
||||
# Start Django application
|
||||
CMD ["/app/start.sh"]
|
||||
50
Package-Templates/django-app/start.sh.template
Normal file
50
Package-Templates/django-app/start.sh.template
Normal file
@@ -0,0 +1,50 @@
|
||||
# Django Application Start Script Template
|
||||
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
# Cloudron PostgreSQL connection
|
||||
DB_NAME=${CLOUDRON_POSTGRESQL_DATABASE:-app}
|
||||
DB_USER=${CLOUDRON_POSTGRESQL_USERNAME:-app}
|
||||
DB_PASSWORD=${CLOUDRON_POSTGRESQL_PASSWORD}
|
||||
DB_HOST=${CLOUDRON_POSTGRESQL_HOST:-127.0.0.1}
|
||||
DB_PORT=${CLOUDRON_POSTGRESQL_PORT:-5432}
|
||||
|
||||
echo "Database host: $DB_HOST"
|
||||
echo "Database port: $DB_PORT"
|
||||
echo "Database name: $DB_NAME"
|
||||
|
||||
# Django configuration
|
||||
export DJANGO_SETTINGS_MODULE=${DJANGO_SETTINGS_MODULE:-config.production}
|
||||
export SECRET_KEY=${SECRET_KEY:-cloudron-secret-key-change-in-production}
|
||||
export ALLOWED_HOSTS=${ALLOWED_HOSTS:-'*'}
|
||||
export DATABASE_URL=postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}
|
||||
|
||||
# Wait for PostgreSQL to be ready
|
||||
echo "Waiting for PostgreSQL to be ready..."
|
||||
until PGPASSWORD=$DB_PASSWORD psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d "$DB_NAME" -c '\q' 2>/dev/null; do
|
||||
echo "PostgreSQL is unavailable - sleeping"
|
||||
sleep 2
|
||||
done
|
||||
|
||||
echo "PostgreSQL is ready!"
|
||||
|
||||
# Run Django migrations
|
||||
echo "Running Django migrations..."
|
||||
python manage.py migrate --noinput
|
||||
|
||||
# Collect static files
|
||||
echo "Collecting static files..."
|
||||
python manage.py collectstatic --noinput
|
||||
|
||||
# Create admin user if specified
|
||||
if [ -n "$ADMIN_USERNAME" ] && [ -n "$ADMIN_PASSWORD" ] && [ -n "$ADMIN_EMAIL" ]; then
|
||||
echo "Creating admin user..."
|
||||
echo "from django.contrib.auth import get_user_model; from django.core.management import call_command; User = get_user_model(); User.objects.create_superuser('$ADMIN_USERNAME', '$ADMIN_EMAIL', '$ADMIN_PASSWORD') if not User.objects.filter(email='$ADMIN_EMAIL').exists() else None" | \
|
||||
python manage.py shell 2>/dev/null || echo "Admin user may already exist"
|
||||
fi
|
||||
|
||||
# Start Django application
|
||||
echo "Starting Django application..."
|
||||
exec gunicorn config.wsgi:application --bind 0.0.0.0:8080 --workers ${NUM_WORKERS:-4}
|
||||
Reference in New Issue
Block a user