File size: 3,090 Bytes
10dc6f2
 
 
 
 
 
f274afb
 
 
 
 
 
 
 
10dc6f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5a3f516
 
 
 
10dc6f2
 
 
 
 
 
 
5a3f516
 
 
10dc6f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
FROM php:8.4-apache

# Enable Apache modules and ensure correct MPM for mod_php
RUN a2dismod mpm_event mpm_worker || true \
    && a2enmod mpm_prefork rewrite headers

# Install PostgreSQL official repo for latest libpq with SNI support (required for Neon.tech)
RUN apt-get update && apt-get install -y lsb-release gnupg2 \
    && echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list \
    && curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor -o /etc/apt/trusted.gpg.d/postgresql.gpg \
    && apt-get update

# Install system dependencies + PHP extensions (PostgreSQL with SNI support)
RUN apt-get install -y \
    git curl libpng-dev libonig-dev libxml2-dev libpq-dev libzip-dev \
    libfreetype6-dev libjpeg-dev libicu-dev zip unzip \
    && docker-php-ext-configure gd --with-freetype --with-jpeg \
    && docker-php-ext-install pdo pdo_pgsql pgsql mbstring exif pcntl bcmath gd zip intl \
    && apt-get clean && rm -rf /var/lib/apt/lists/*

# PHP production settings
RUN cp /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini \
    && sed -i 's/memory_limit = .*/memory_limit = 256M/' /usr/local/etc/php/php.ini \
    && sed -i 's/upload_max_filesize = .*/upload_max_filesize = 10M/' /usr/local/etc/php/php.ini \
    && sed -i 's/post_max_size = .*/post_max_size = 12M/' /usr/local/etc/php/php.ini \
    && sed -i 's/max_execution_time = .*/max_execution_time = 60/' /usr/local/etc/php/php.ini

# Install Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

# Set Apache document root to Laravel's public directory
RUN sed -ri -e 's!/var/www/html!/var/www/public!g' /etc/apache2/sites-available/*.conf \
    && sed -ri -e 's!/var/www/!/var/www/public/!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf

# Allow .htaccess overrides (required for Laravel routing)
RUN sed -i '/<Directory \/var\/www\/public\/>/,/<\/Directory>/ s/AllowOverride None/AllowOverride All/' /etc/apache2/apache2.conf \
    || echo "<Directory /var/www/public/>\n    AllowOverride All\n    Require all granted\n</Directory>" >> /etc/apache2/apache2.conf

WORKDIR /var/www

# Install Node.js & NPM
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
    && apt-get install -y nodejs

# Install PHP dependencies (production only)
COPY composer.json composer.lock* ./
RUN composer install --no-dev --no-scripts --no-autoloader --prefer-dist

# Copy application
COPY . /var/www

# Install Node modules and build Vite assets
RUN npm ci && npm run build

# Dump optimized autoloader
RUN composer dump-autoload --optimize

# HF Spaces runs as non-root (uid 1000), so open permissions
RUN mkdir -p storage/logs storage/framework/cache storage/framework/sessions storage/framework/views bootstrap/cache storage/app/public \
    && chmod -R 777 storage bootstrap/cache \
    && chmod -R 755 public

# Make start script executable
RUN chmod +x /var/www/docker/start-hfspace.sh

# HF Spaces expects port 7860
EXPOSE 7860

CMD ["bash", "/var/www/docker/start-hfspace.sh"]