Skip to content

Commit 09f4d5e

Browse files
authored
Merge pull request #3 from geekstuff-it/base-and-laravel
Addition of laravel template blocks if artisan file detected, plus base tweaks.
2 parents 793c0ba + 6395fca commit 09f4d5e

File tree

7 files changed

+54
-16
lines changed

7 files changed

+54
-16
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ It's meant to be used with image geekstuffreal/php-fpm-alpine and the
99
To fully see how it's used, head over to https://github.com/geekstuff-it/docker-php-fpm-alpine
1010

1111
## TODO
12-
- add laravel specifics
13-
- add other installers (silex?)
12+
- fix issue where new project got latest tag for php-fpm
13+
- add env var in base nginx box to let us control the timeouts differently in dev and prod.
14+
(in dev, we will put a long timeout to avoid nginx getting in the way with xdebug)

src/Command/Common.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Symfony\Component\Console\Command\Command;
1111
use Symfony\Component\Console\Input\InputInterface;
1212
use Symfony\Component\Console\Output\OutputInterface;
13+
use Symfony\Component\Filesystem\Filesystem;
1314
use Symfony\Component\Finder\Finder;
1415
use Symfony\Component\Finder\SplFileInfo;
1516
use Symfony\Component\HttpClient\HttpClient;
@@ -167,10 +168,14 @@ protected function isRoot(): bool
167168

168169
protected function detectFramework(): string
169170
{
170-
if (file_exists($this->config->appDir.'/symfony.lock')) {
171-
return $this->data::FRAMEWORK_SYMFONY;
172-
} else {
173-
return $this->data::FRAMEWORK_NONE;
171+
$fs = new Filesystem();
172+
switch (true) {
173+
case $fs->exists($this->config->appDir.'/symfony.lock'):
174+
return $this->data::FRAMEWORK_SYMFONY;
175+
case $fs->exists($this->config->appDir.'/artisan'):
176+
return $this->data::FRAMEWORK_LARAVEL;
177+
default:
178+
return $this->data::FRAMEWORK_NONE;
174179
}
175180
}
176181

src/Command/Dockerize.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,13 @@ protected function writeFiles(InputInterface $input, OutputInterface $output): b
137137
$frameworkVersion = sprintf('framework/%s/%s', $framework, $templateFile->getFilename());
138138
if ($fs->exists($this->config->rootDir . '/templates/dockerizer/' . $frameworkVersion)) {
139139
$template = $frameworkVersion;
140+
$output->writeln(sprintf(
141+
'- with %s specifics, [%s]',
142+
ucfirst($framework),
143+
$templateFile->getFilenameWithoutExtension()
144+
));
145+
} else {
146+
$output->writeln(sprintf('- [%s]', $templateFile->getFilenameWithoutExtension()));
140147
}
141148
}
142149

@@ -163,7 +170,6 @@ protected function doneMessage(OutputInterface $output): bool
163170
$message = $this->getTwig($this->getOtherTemplateDir())->render(
164171
'dockerize-done.twig',
165172
[
166-
'FILE_LIST' => $this->getDockerizeTemplateFiles(),
167173
'NOTES_FILENAME' => $notesFileBasename
168174
]
169175
);

templates/dockerizer/Dockerfile.twig

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ ARG NGINX_VERSION={{ NGINX_VERSION }}
88
FROM {{ FPM_FROM }}:${PHP_GEEKSTUFF_VERSION} AS base
99

1010
{% block base %}
11+
RUN docker-php-ext-install \
12+
mysqli \
13+
pdo_mysql \
14+
&& docker-php-source delete
15+
1116
{% block base_extras %}{% endblock %}
1217
{% endblock %}
1318

@@ -94,8 +99,10 @@ RUN create-php-user ${PHP_USER_ID} \
9499
## Copy code
95100
COPY --chown=${PHP_USER_NAME}:${PHP_USER_NAME} . /app
96101

97-
## Init & Optimise app
102+
## Switch to user
98103
USER ${PHP_USER_NAME}
104+
105+
## Build and optimise app
99106
{% block build_framework %}
100107
RUN composer install --no-dev
101108
{% endblock %}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{% extends "Dockerfile.twig" %}
2+
3+
{% block buildtools_extras %}
4+
# npm
5+
RUN apk add --update --no-cache \
6+
nodejs \
7+
npm \
8+
yarn
9+
{% endblock %}
10+
11+
{% block build_framework %}
12+
RUN composer install --no-dev --optimize-autoloader \
13+
&& php artisan config:cache \
14+
&& php artisan view:cache \
15+
&& php artisan event:cache \
16+
&& php artisan storage:link
17+
18+
RUN yarn
19+
20+
# RUN npm run prod
21+
# && php artisan route:cache \
22+
# && composer dump-env prod \
23+
# && composer dump-autoload --no-dev --classmap-authoritative
24+
{% endblock %}

templates/dockerizer/framework/symfony/Dockerfile.twig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{% extends "Dockerfile.twig" %}
22

33
{% block build_framework %}
4-
RUN composer install --no-dev \
4+
RUN composer install --no-dev --optimize-autoloader \
55
&& bin/console cache:clear --env=prod \
6+
&& bin/console cache:warmup --env=prod \
67
&& bin/console assets:install public \
78
&& composer dump-env prod \
89
&& composer dump-autoload --no-dev --classmap-authoritative

templates/message/dockerize-done.twig

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@
22
#### Dockerize complete!
33
You now have a multi-stage, multi-purpose Dockerfile, kept as lean as possible in every end stages, and 2 docker-compose configs.
44

5-
## Details
6-
These are the files that dockerize added:
7-
{% for file in FILE_LIST %}
8-
{{ file.getFilenameWithoutExtension }}
9-
{% endfor %}
10-
{{ NOTES_FILENAME }} (a copy of this "Dockerize complete" output)
11-
125
## Easy DEV
136
`docker-compose up --build` and `docker-compose run php bash` should let you continue to build and run anything.
147

@@ -25,3 +18,4 @@ Because we have 2 separate image that don't need to share a volume in between th
2518

2619
## What's next?
2720
Now you might still be in the init phase. Simply exit and start using docker-compose on your project!
21+
(and these notes above have been written to {{ NOTES_FILENAME }})

0 commit comments

Comments
 (0)