Skip to content

Commit

Permalink
build: moved around container init
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbaile committed May 3, 2024
1 parent a77dcd9 commit 4c61e8e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
23 changes: 11 additions & 12 deletions containers/php/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ RUN apk add --no-cache \
sqlite
COPY --from=docker.io/composer:2.7.2 /usr/bin/composer /usr/local/bin/composer
COPY --from=docker.io/mlocati/php-extension-installer:2.2.5 /usr/bin/install-php-extensions /usr/local/sbin/install-php-extensions
ADD --chmod=777 \
--checksum=sha256:206a8f9b2177703fc5aa924d85ad6c72e82413e2d09635b4c9c82a1b65b5b3d5 \
https://github.com/eficode/wait-for/releases/download/v2.2.4/wait-for /usr/local/bin/wait-for
# configure entrypoints and image
COPY --chmod=777 containers/php/entrypoint.sh /usr/local/sbin/entrypoint
RUN echo "* * * * * cd /var/www/html && php artisan schedule:run >> /dev/null 2>&1" > /etc/crontabs/www-data \
&& echo "access.log = /dev/null" >> /usr/local/etc/php-fpm.d/zz-docker.conf
ENTRYPOINT ["entrypoint"]
CMD ["php-fpm"]
COPY containers/php/config /usr/local/etc/php

FROM base as development
RUN apk add --no-cache \
Expand All @@ -30,7 +34,10 @@ ENV XDEBUG_CONFIG="client_host=host.docker.internal"
USER www-data

FROM base as production
RUN install-php-extensions opcache
RUN install-php-extensions opcache \
&& mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
COPY containers/php/config/conf.d/opcache.ini /usr/local/etc/php/conf.d/opcache.ini
ARG COMPOSER_ALLOW_SUPERUSER=1
COPY composer.json .
COPY composer.lock .
RUN composer install --no-dev --no-scripts --no-cache
Expand All @@ -41,17 +48,9 @@ COPY database ./database
COPY public ./public
COPY resources ./resources
COPY routes ./routes
COPY storage ./storage
COPY --chown=www-data:www-data storage ./storage
COPY artisan .
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" \
&& echo "* * * * * cd /var/www/html && php artisan schedule:run >> /dev/null 2>&1" > /etc/crontabs/www-data \
&& echo "access.log = /dev/null" >> /usr/local/etc/php-fpm.d/zz-docker.conf
ADD --chmod=777 \
--checksum=sha256:206a8f9b2177703fc5aa924d85ad6c72e82413e2d09635b4c9c82a1b65b5b3d5 \
https://github.com/eficode/wait-for/releases/download/v2.2.4/wait-for /usr/local/bin/wait-for
ARG COMPOSER_ALLOW_SUPERUSER=1
RUN chown -R www-data:www-data storage \
&& composer dump-autoload --optimize \
RUN composer dump-autoload --optimize \
&& echo -n "opcache.max_accelerated_files=" >> "$PHP_INI_DIR/conf.d/opcache.ini" \
&& echo $(find . -name "*.php" | wc -l | awk '{print (int($1/1000)+2)*1000}') >> "$PHP_INI_DIR/conf.d/opcache.ini" \
&& rm /usr/local/bin/composer \
Expand Down
4 changes: 2 additions & 2 deletions containers/php/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ if [ "$1" = 'php-fpm' ]; then
composer install
else
php artisan optimize
chown -R www-data:www-data storage
fi
php artisan migrate --force
elif [ "$1" = 'crond' ] || [ "$3" = 'queue:work' ]; then
chown -R www-data:www-data storage
elif [ "$1" = 'crond' ] || [ "$3" = 'queue:work' ] || [ "$3" = 'queue:listen' ]; then
wait-for "${PHP_HOST:?Missing PHP_HOST}:${PHP_PORT:?Missing PHP_PORT}" -t 60
fi

Expand Down
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ services:
extends:
service: php
stop_signal: SIGKILL
user: root
command: crond -f
environment:
PHP_HOST: php
Expand Down

0 comments on commit 4c61e8e

Please sign in to comment.