diff --git a/README.md b/README.md index ccd792d..7d3ee63 100644 --- a/README.md +++ b/README.md @@ -9,5 +9,6 @@ It's meant to be used with image geekstuffreal/php-fpm-alpine and the To fully see how it's used, head over to https://github.com/geekstuff-it/docker-php-fpm-alpine ## TODO -- add laravel specifics -- add other installers (silex?) +- fix issue where new project got latest tag for php-fpm +- add env var in base nginx box to let us control the timeouts differently in dev and prod. + (in dev, we will put a long timeout to avoid nginx getting in the way with xdebug) diff --git a/src/Command/Common.php b/src/Command/Common.php index a32d67e..34d6d3a 100644 --- a/src/Command/Common.php +++ b/src/Command/Common.php @@ -10,6 +10,7 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Finder\Finder; use Symfony\Component\Finder\SplFileInfo; use Symfony\Component\HttpClient\HttpClient; @@ -167,10 +168,14 @@ protected function isRoot(): bool protected function detectFramework(): string { - if (file_exists($this->config->appDir.'/symfony.lock')) { - return $this->data::FRAMEWORK_SYMFONY; - } else { - return $this->data::FRAMEWORK_NONE; + $fs = new Filesystem(); + switch (true) { + case $fs->exists($this->config->appDir.'/symfony.lock'): + return $this->data::FRAMEWORK_SYMFONY; + case $fs->exists($this->config->appDir.'/artisan'): + return $this->data::FRAMEWORK_LARAVEL; + default: + return $this->data::FRAMEWORK_NONE; } } diff --git a/src/Command/Dockerize.php b/src/Command/Dockerize.php index 88ed5ef..65b4639 100644 --- a/src/Command/Dockerize.php +++ b/src/Command/Dockerize.php @@ -137,6 +137,13 @@ protected function writeFiles(InputInterface $input, OutputInterface $output): b $frameworkVersion = sprintf('framework/%s/%s', $framework, $templateFile->getFilename()); if ($fs->exists($this->config->rootDir . '/templates/dockerizer/' . $frameworkVersion)) { $template = $frameworkVersion; + $output->writeln(sprintf( + '- with %s specifics, [%s]', + ucfirst($framework), + $templateFile->getFilenameWithoutExtension() + )); + } else { + $output->writeln(sprintf('- [%s]', $templateFile->getFilenameWithoutExtension())); } } @@ -163,7 +170,6 @@ protected function doneMessage(OutputInterface $output): bool $message = $this->getTwig($this->getOtherTemplateDir())->render( 'dockerize-done.twig', [ - 'FILE_LIST' => $this->getDockerizeTemplateFiles(), 'NOTES_FILENAME' => $notesFileBasename ] ); diff --git a/templates/dockerizer/Dockerfile.twig b/templates/dockerizer/Dockerfile.twig index 4e24ee2..d8a0a1b 100644 --- a/templates/dockerizer/Dockerfile.twig +++ b/templates/dockerizer/Dockerfile.twig @@ -8,6 +8,11 @@ ARG NGINX_VERSION={{ NGINX_VERSION }} FROM {{ FPM_FROM }}:${PHP_GEEKSTUFF_VERSION} AS base {% block base %} +RUN docker-php-ext-install \ + mysqli \ + pdo_mysql \ + && docker-php-source delete + {% block base_extras %}{% endblock %} {% endblock %} @@ -94,8 +99,10 @@ RUN create-php-user ${PHP_USER_ID} \ ## Copy code COPY --chown=${PHP_USER_NAME}:${PHP_USER_NAME} . /app -## Init & Optimise app +## Switch to user USER ${PHP_USER_NAME} + +## Build and optimise app {% block build_framework %} RUN composer install --no-dev {% endblock %} diff --git a/templates/dockerizer/framework/laravel/Dockerfile.twig b/templates/dockerizer/framework/laravel/Dockerfile.twig new file mode 100644 index 0000000..a119f06 --- /dev/null +++ b/templates/dockerizer/framework/laravel/Dockerfile.twig @@ -0,0 +1,24 @@ +{% extends "Dockerfile.twig" %} + +{% block buildtools_extras %} +# npm +RUN apk add --update --no-cache \ + nodejs \ + npm \ + yarn +{% endblock %} + +{% block build_framework %} +RUN composer install --no-dev --optimize-autoloader \ + && php artisan config:cache \ + && php artisan view:cache \ + && php artisan event:cache \ + && php artisan storage:link + +RUN yarn + +# RUN npm run prod +# && php artisan route:cache \ +# && composer dump-env prod \ +# && composer dump-autoload --no-dev --classmap-authoritative +{% endblock %} diff --git a/templates/dockerizer/framework/symfony/Dockerfile.twig b/templates/dockerizer/framework/symfony/Dockerfile.twig index bf89a9b..626f2d3 100644 --- a/templates/dockerizer/framework/symfony/Dockerfile.twig +++ b/templates/dockerizer/framework/symfony/Dockerfile.twig @@ -1,8 +1,9 @@ {% extends "Dockerfile.twig" %} {% block build_framework %} -RUN composer install --no-dev \ +RUN composer install --no-dev --optimize-autoloader \ && bin/console cache:clear --env=prod \ + && bin/console cache:warmup --env=prod \ && bin/console assets:install public \ && composer dump-env prod \ && composer dump-autoload --no-dev --classmap-authoritative diff --git a/templates/message/dockerize-done.twig b/templates/message/dockerize-done.twig index 88c3372..5129723 100644 --- a/templates/message/dockerize-done.twig +++ b/templates/message/dockerize-done.twig @@ -2,13 +2,6 @@ #### Dockerize complete! You now have a multi-stage, multi-purpose Dockerfile, kept as lean as possible in every end stages, and 2 docker-compose configs. -## Details -These are the files that dockerize added: -{% for file in FILE_LIST %} - {{ file.getFilenameWithoutExtension }} -{% endfor %} - {{ NOTES_FILENAME }} (a copy of this "Dockerize complete" output) - ## Easy DEV `docker-compose up --build` and `docker-compose run php bash` should let you continue to build and run anything. @@ -25,3 +18,4 @@ Because we have 2 separate image that don't need to share a volume in between th ## What's next? Now you might still be in the init phase. Simply exit and start using docker-compose on your project! +(and these notes above have been written to {{ NOTES_FILENAME }})