techblog/Dockerfile

88 lines
2.3 KiB
Docker
Raw Permalink Normal View History

2026-03-31 04:06:02 +00:00
# syntax=docker/dockerfile:1
# Stage 1: Install PHP dependencies
2026-03-31 02:54:47 +00:00
FROM composer:2 AS composer-builder
WORKDIR /app
COPY composer.json composer.lock ./
2026-03-31 04:06:02 +00:00
# Mount auth.json as a secret so it never gets baked into the image
2026-03-31 04:16:01 +00:00
RUN --mount=type=secret,id=composer_auth \
test -s /run/secrets/composer_auth || (echo "ERROR: composer_auth secret is missing or empty" && exit 1) && \
COMPOSER_AUTH=$(cat /run/secrets/composer_auth) \
2026-03-31 04:06:02 +00:00
composer install \
2026-03-31 02:54:47 +00:00
--no-dev \
--no-interaction \
--no-plugins \
--no-scripts \
--prefer-dist \
--optimize-autoloader
COPY . .
# Run post-install scripts now that source is present
RUN composer run-script post-autoload-dump 2>/dev/null || true
# Stage 2: Build frontend assets (needs vendor for flux CSS)
FROM node:20-alpine AS node-builder
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
COPY . .
COPY --from=composer-builder /app/vendor ./vendor
RUN npm run build
2026-03-31 02:54:47 +00:00
# Stage 3: Production image
2026-04-01 04:04:47 +00:00
FROM php:8.4-fpm-alpine
2026-03-31 02:54:47 +00:00
# Install system dependencies and PHP extensions
RUN apk add --no-cache \
nginx \
supervisor \
curl \
libpng-dev \
libjpeg-turbo-dev \
libwebp-dev \
freetype-dev \
libzip-dev \
icu-dev \
oniguruma-dev \
&& docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp \
&& docker-php-ext-install -j$(nproc) \
pdo_mysql \
mbstring \
exif \
pcntl \
bcmath \
gd \
zip \
intl \
opcache
WORKDIR /var/www/html
# Copy application files
COPY --from=composer-builder /app /var/www/html
COPY --from=node-builder /app/public/build /var/www/html/public/build
# Copy Docker config files
COPY docker/nginx.conf /etc/nginx/nginx.conf
COPY docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY docker/php.ini /usr/local/etc/php/conf.d/app.ini
COPY docker/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
2026-03-31 02:54:47 +00:00
# Set up storage and cache directories
RUN mkdir -p \
storage/framework/sessions \
storage/framework/views \
storage/framework/cache/data \
storage/logs \
bootstrap/cache \
&& chown -R www-data:www-data /var/www/html \
&& chmod -R 755 /var/www/html \
&& chmod -R 775 storage bootstrap/cache
# Remove any accidentally included .env files
RUN rm -f .env .env.* 2>/dev/null || true
EXPOSE 80
ENTRYPOINT ["/entrypoint.sh"]