Files
Fleetbase-Mirror-Repo/docker/Dockerfile-php8
2023-04-11 20:02:52 +08:00

125 lines
4.4 KiB
Plaintext

# Build stage
FROM php:8.2.4-fpm-alpine3.17 as build
# download and install geos php bindings
# need to run docker-php-ext-configure to create /usr/src/php/ext dir
RUN mkdir -p /usr/src/php/ext && curl -L https://git.osgeo.org/gitea/geos/php-geos/archive/1.0.0.tar.gz > /tmp/php-geos.tar.gz && tar -C /usr/src/php/ext -xzvf /tmp/php-geos.tar.gz
# Update package repositories
RUN apk update
# Install dependencies
RUN apk add --no-cache autoconf g++ gcc make build-base linux-headers git unzip geos-dev libzip-dev libgd gd-dev libpng-dev imagemagick imagemagick-libs imagemagick-dev libmemcached-dev libmemcached-libs gmp-dev icu-dev icu icu-libs tmux
# Install PHP extensions
RUN docker-php-ext-install -j$(nproc) gmp gd zip pdo_mysql sockets intl
RUN pecl install imagick redis-5.3.7 memcached-3.2.0
RUN docker-php-ext-enable imagick redis memcached opcache
RUN docker-php-ext-configure gd --enable-gd --with-external-gd
RUN docker-php-ext-configure php-geos
# Configure PHP ini settings
RUN sed -e 's/^expose_php.*/expose_php = Off/' "$PHP_INI_DIR/php.ini-production" > "$PHP_INI_DIR/php.ini"
RUN sed -i -e 's/^upload_max_filesize.*/upload_max_filesize = 600M/' -e 's/^post_max_size.*/post_max_size = 0/' -e 's/^memory_limit.*/memory_limit = 600M/' "$PHP_INI_DIR/php.ini"
# set recommended PHP.ini settings
# see https://secure.php.net/manual/en/opcache.installation.php
RUN { \
echo 'opcache.memory_consumption=128'; \
echo 'opcache.interned_strings_buffer=8'; \
echo 'opcache.max_accelerated_files=4000'; \
echo 'opcache.revalidate_freq=2'; \
echo 'opcache.fast_shutdown=1'; \
echo 'opcache.enable_cli=1'; \
} > /usr/local/etc/php/conf.d/opcache-recommended.ini
# Get springload ssm-parent
RUN curl -L https://github.com/springload/ssm-parent/releases/download/v1.4.3/ssm-parent_1.4.3_linux_amd64.tar.gz > /tmp/ssm-parent.tar.gz && tar -C /sbin -xvf /tmp/ssm-parent.tar.gz ssm-parent && rm /tmp/ssm-parent.tar.gz
# Install composer
WORKDIR /var/www
COPY docker/composer-install.sh ./
RUN chmod +x ./composer-install.sh && ./composer-install.sh
# Copy application files
WORKDIR /var/www/html
USER www-data
COPY . .
# Install dependencies
RUN composer install --no-dev --no-scripts --no-autoloader --working-dir=/var/www/html/api
COPY --chown=www-data:nogroup . ./
RUN composer dumpautoload /var/www/html/api
# Use root user
USER root
# Set environment variables
ARG ENVIRONMENT=production
ENV APP_ENV=$ENVIRONMENT
# Final stage
FROM php:8.2.4-fpm-alpine as final
# Install dependencies
RUN apk add --no-cache autoconf g++ gcc make build-base linux-headers git unzip geos-dev libzip-dev libgd gd-dev libpng-dev imagemagick imagemagick-libs imagemagick-dev libmemcached-dev libmemcached-libs gmp-dev icu-dev icu icu-libs tmux
# Copy application files
WORKDIR /var/www/html
COPY --from=build /var/www/html .
# Set ownership and permissions
RUN chown -R www-data:www-data /var/www/html \
&& chmod -R 775 /var/www/html/storage /var/www/html/bootstrap/cache
# Set entrypoint and command
ENTRYPOINT ["/sbin/ssm-parent", "-c", ".ssm-parent.yaml", "run", "--", "docker-php-entrypoint"]
CMD ["php-fpm"]
# Scheduler stages
FROM alpine:3.14 as scheduler
RUN apk add --no-cache curl
# Install go-crond
RUN curl -L https://github.com/webdevops/go-crond/releases/download/0.6.1/go-crond-64-linux-dynamic > /usr/local/bin/go-crond \
&& chmod +x /usr/local/bin/go-crond
# Copy application files
WORKDIR /var/www/html
COPY --chown=www-data:nogroup . ./
# Copy crontab file and set permissions
COPY --chown=www-data:nogroup docker/crontab ./crontab
RUN chmod 0600 ./crontab
# Set ownership and permissions
RUN chown -R www-data:www-data /var/www/html
# Set entrypoint and command
ENTRYPOINT []
CMD ["go-crond", "--verbose", "--no-auto", "root:./crontab"]
# Application stages
FROM final as app-dev
# Set entrypoint and command
ENTRYPOINT ["docker-php-entrypoint"]
CMD ["php-fpm"]
# Application stage
FROM final as app
ENTRYPOINT ["/sbin/ssm-parent", "-c", ".ssm-parent.yaml", "run", "--", "docker-php-entrypoint"]
CMD ["php-fpm"]
FROM final as events
# Set entrypoint and command
ENTRYPOINT ["/sbin/ssm-parent", "-c", ".ssm-parent.yaml", "run", "--", "docker-php-entrypoint"]
CMD ["php", "api/artisan", "queue:work", "events"]
FROM final as jobs
# Set entrypoint and command
ENTRYPOINT ["/sbin/ssm-parent", "-c", ".ssm-parent.yaml", "run", "--", "docker-php-entrypoint"]
CMD ["php", "api/artisan", "queue:work", "sqs"]