Files
panel-pelican-dev/Dockerfile

110 lines
3.6 KiB
Docker
Raw Permalink Normal View History

# syntax=docker.io/docker/dockerfile:1.13-labs
2024-06-02 21:57:23 -04:00
# Pelican Production Dockerfile
##
# If you want to build this locally you want to run `docker build -f Dockerfile.dev`
##
# ================================
# Stage 1-1: Composer Install
# ================================
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
# Copy bare minimum to install Composer dependencies
COPY composer.json composer.lock ./
2025-01-16 08:24:58 +01:00
RUN composer install --no-dev --no-interaction --no-autoloader --no-scripts
2025-01-16 08:24:58 +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
# 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 \
&& yarn install --frozen-lockfile
2024-06-02 21:57:23 -04:00
2025-01-16 08:24:58 +01:00
# ================================
# Stage 2-1: Composer Optimize
2025-01-16 08:24:58 +01:00
# ================================
FROM --platform=$TARGETOS/$TARGETARCH composer AS composerbuild
2024-06-02 21:57:23 -04:00
# Copy full code to optimize autoload
COPY --exclude=Caddyfile --exclude=docker/ . ./
2024-06-02 21:57:23 -04:00
RUN composer dump-autoload --optimize
2025-01-16 08:24:58 +01:00
# ================================
# Stage 2-2: Build Frontend Assets
# ================================
FROM --platform=$TARGETOS/$TARGETARCH yarn AS yarnbuild
WORKDIR /build
2024-06-02 21:57:23 -04:00
# Copy full code
COPY --exclude=Caddyfile --exclude=docker/ . ./
COPY --from=composer /build .
2024-06-02 21:57:23 -04:00
RUN yarn run build
2024-06-02 21:57:23 -04:00
# ================================
# Stage 5: Build Final Application Image
# ================================
FROM --platform=$TARGETOS/$TARGETARCH localhost:5000/base-php:$TARGETARCH AS final
2024-06-02 21:57:23 -04:00
WORKDIR /var/www/html
# Install additional required libraries
2025-08-10 14:30:58 -05:00
RUN 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 {} \; \
# Create necessary directories
&& mkdir -p /pelican-data/storage /var/www/html/storage/app/public /var/run/supervisord /etc/supercronic \
# Symlinks for env, database, and avatars
&& ln -s /pelican-data/.env ./.env \
&& ln -s /pelican-data/database/database.sqlite ./database/database.sqlite \
2025-04-21 11:25:36 +02:00
&& ln -sf /var/www/html/storage/app/public /var/www/html/public/storage \
&& ln -s /pelican-data/storage/avatars /var/www/html/storage/app/public/avatars \
&& ln -s /pelican-data/storage/fonts /var/www/html/storage/app/public/fonts \
# Allow www-data write permissions where necessary
2025-04-21 11:25:36 +02:00
&& chown -R www-data:www-data /pelican-data ./storage ./bootstrap/cache /var/run/supervisord /var/www/html/public/storage \
&& 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
COPY docker/supervisord.conf /etc/supervisord.conf
COPY docker/Caddyfile /etc/caddy/Caddyfile
# Add Laravel scheduler to crontab
COPY docker/crontab /etc/supercronic/crontab
2025-08-10 14:30:58 -05:00
COPY docker/entrypoint.sh /entrypoint.sh
COPY docker/healthcheck.sh /healthcheck.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 \
2025-08-10 14:30:58 -05:00
CMD /bin/ash /healthcheck.sh
2024-06-11 19:17:48 -04:00
2024-10-14 22:13:01 +02:00
EXPOSE 80 443
2024-06-11 19:17:48 -04:00
VOLUME /pelican-data
USER www-data
2025-08-10 14:30:58 -05:00
ENTRYPOINT [ "/bin/ash", "/entrypoint.sh" ]
CMD [ "supervisord", "-n", "-c", "/etc/supervisord.conf" ]