2025-02-15 23:32:15 +01:00
# syntax=docker.io/docker/dockerfile:1.13-labs
2024-06-02 21:57:23 -04:00
# Pelican Production Dockerfile
2025-01-23 01:01:14 -08:00
2025-02-15 23:32:15 +01:00
# For those who want to build this Dockerfile themselves, uncomment lines 6-12 and replace "localhost:5000/base-php:$TARGETARCH" on lines 17 and 67 with "base".
# FROM --platform=$TARGETOS/$TARGETARCH php:8.3-fpm-alpine as base
# ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
2025-01-23 01:01:14 -08:00
2025-02-15 23:32:15 +01:00
# RUN install-php-extensions bcmath gd intl zip opcache pcntl posix pdo_mysql
2025-01-23 01:01:14 -08:00
2025-02-15 23:32:15 +01:00
# RUN rm /usr/local/bin/install-php-extensions
2025-01-23 01:01:14 -08:00
# ================================
2025-02-15 23:32:15 +01:00
# Stage 1-1: Composer Install
2025-01-23 01:01:14 -08:00
# ================================
2025-02-15 23:32:15 +01:00
FROM --platform=$TARGETOS/$TARGETARCH localhost:5000/base-php:$TARGETARCH AS composer
2024-06-02 21:57:23 -04:00
2024-06-11 19:17:48 -04:00
WORKDIR /build
2025-01-16 08:24:58 +01:00
COPY --from= composer:latest /usr/bin/composer /usr/local/bin/composer
2025-01-23 01:01:14 -08:00
# Copy bare minimum to install Composer dependencies
COPY composer.json composer.lock ./
2025-01-16 08:24:58 +01:00
2025-01-23 01:01:14 -08:00
RUN composer install --no-dev --no-interaction --no-autoloader --no-scripts
2025-01-16 08:24:58 +01:00
# ================================
2025-02-15 23:32:15 +01:00
# Stage 1-2: Yarn Install
2025-01-16 08:24:58 +01:00
# ================================
FROM --platform=$TARGETOS/$TARGETARCH node:20-alpine AS yarn
WORKDIR /build
2025-01-23 01:01:14 -08:00
# Copy bare minimum to install Yarn dependencies
COPY package.json yarn.lock ./
2024-06-02 21:57:23 -04:00
2024-10-14 22:13:01 +02:00
RUN yarn config set network-timeout 300000 \
2025-01-23 01:01:14 -08:00
&& yarn install --frozen-lockfile
2024-06-02 21:57:23 -04:00
2025-01-16 08:24:58 +01:00
# ================================
2025-02-15 23:32:15 +01:00
# Stage 2-1: Composer Optimize
2025-01-16 08:24:58 +01:00
# ================================
2025-01-23 01:01:14 -08:00
FROM --platform=$TARGETOS/$TARGETARCH composer AS composerbuild
2024-06-02 21:57:23 -04:00
2025-01-23 01:01:14 -08:00
# Copy full code to optimize autoload
COPY --exclude= Caddyfile --exclude= docker/ . ./
2024-06-02 21:57:23 -04:00
2025-01-23 01:01:14 -08:00
RUN composer dump-autoload --optimize
2025-01-16 08:24:58 +01:00
2025-01-23 01:01:14 -08:00
# ================================
2025-02-15 23:32:15 +01:00
# Stage 2-2: Build Frontend Assets
2025-01-23 01:01:14 -08:00
# ================================
FROM --platform=$TARGETOS/$TARGETARCH yarn AS yarnbuild
2025-01-16 09:20:54 +01:00
2025-01-23 01:01:14 -08:00
WORKDIR /build
2024-06-02 21:57:23 -04:00
2025-01-23 01:01:14 -08:00
# Copy full code
COPY --exclude= Caddyfile --exclude= docker/ . ./
COPY --from= composer /build .
2024-06-02 21:57:23 -04:00
2025-01-23 01:01:14 -08:00
RUN yarn run build
2024-06-02 21:57:23 -04:00
2025-01-23 01:01:14 -08:00
# ================================
2025-02-15 23:32:15 +01:00
# Stage 5: Build Final Application Image
2025-01-23 01:01:14 -08:00
# ================================
2025-02-15 23:32:15 +01:00
FROM --platform=$TARGETOS/$TARGETARCH localhost:5000/base-php:$TARGETARCH AS final
2024-06-02 21:57:23 -04:00
2025-01-23 01:01:14 -08:00
WORKDIR /var/www/html
# Install additional required libraries
RUN apk update && apk add --no-cache \
caddy ca-certificates supervisor supercronic
COPY --chown= root:www-data --chmod= 640 --from= composerbuild /build .
COPY --chown= root:www-data --chmod= 640 --from= yarnbuild /build/public ./public
# Set permissions
# First ensure all files are owned by root and restrict www-data to read access
RUN chown root:www-data ./ \
&& chmod 750 ./ \
# Files should not have execute set, but directories need it
&& find ./ -type d -exec chmod 750 { } \; \
# Symlink to env/database path, as www-data won't be able to write to webroot
&& ln -s /pelican-data/.env ./.env \
&& ln -s /pelican-data/database/database.sqlite ./database/database.sqlite \
# Create necessary directories
&& mkdir -p /pelican-data /var/run/supervisord /etc/supercronic \
# Finally allow www-data write permissions where necessary
&& chown -R www-data:www-data /pelican-data ./storage ./bootstrap/cache /var/run/supervisord \
&& chmod -R u+rwX,g+rwX,o-rwx /pelican-data ./storage ./bootstrap/cache /var/run/supervisord
2024-09-27 16:50:34 -04:00
2025-01-16 08:24:58 +01:00
# Configure Supervisor
2025-01-23 01:01:14 -08:00
COPY docker/supervisord.conf /etc/supervisord.conf
COPY docker/Caddyfile /etc/caddy/Caddyfile
# Add Laravel scheduler to crontab
COPY docker/crontab /etc/supercronic/crontab
COPY docker/entrypoint.sh ./docker/entrypoint.sh
2024-06-02 21:57:23 -04:00
2024-06-11 19:17:48 -04:00
HEALTHCHECK --interval=5m --timeout=10s --start-period= 5s --retries= 3 \
CMD curl -f http://localhost/up || exit 1
2024-10-14 22:13:01 +02:00
EXPOSE 80 443
2024-06-27 14:56:49 -04:00
2024-06-11 19:17:48 -04:00
VOLUME /pelican-data
2025-01-23 01:01:14 -08:00
USER www-data
ENTRYPOINT [ "/bin/ash" , "docker/entrypoint.sh" ]
2024-09-27 17:36:45 -04:00
CMD [ "supervisord" , "-n" , "-c" , "/etc/supervisord.conf" ]