Skip to content

Commit a3316ca

Browse files
committed
Merge branch 'release/0.12.0'
2 parents 935c7ec + 6ef4fd4 commit a3316ca

File tree

14 files changed

+183
-72
lines changed

14 files changed

+183
-72
lines changed

Dockerfile

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
FROM php:7.3.8-fpm-alpine3.10
1+
FROM php:7.4.10-fpm-alpine3.11
22

33
ENV PHP_OPCACHE_VALIDATE_TIMESTAMPS="0" \
44
PHP_OPCACHE_MAX_ACCELERATED_FILES="10000" \
55
PHP_OPCACHE_MEMORY_CONSUMPTION="192" \
66
PHP_OPCACHE_MAX_WASTED_PERCENTAGE="10" \
7-
PHP_MEMORY_LIMIT="512M"
7+
PHP_MEMORY_LIMIT="512M" \
8+
PHP_MAX_EXECUTION_TIME="60" \
9+
PHP_FPM_MAX_CHILDREN="100" \
10+
PHP_FPM_MAX_REQUESTS="1000" \
11+
PHP_FPM_PM="ondemand" \
12+
PHP_FPM_PROCESS_IDLE_TIMEOUT="10s"
813

914
RUN apk info \
1015
&& echo @edge http://nl.alpinelinux.org/alpine/edge/community >> /etc/apk/repositories \
1116
&& echo @edge http://nl.alpinelinux.org/alpine/edge/main >> /etc/apk/repositories \
12-
&& echo @3.9 http://dl-cdn.alpinelinux.org/alpine/v3.9/main >> /etc/apk/repositories \
1317
&& apk update \
1418
&& apk upgrade \
1519
&& apk add --no-cache --virtual .build-deps \
@@ -36,10 +40,7 @@ RUN apk info \
3640
php7-dom \
3741
mysql-client \
3842
yarn@edge \
39-
xvfb \
40-
chromium@3.9 \
41-
chromium-chromedriver@3.9 \
42-
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-png-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
43+
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
4344
&& docker-php-ext-install -j$(nproc) \
4445
gd \
4546
pdo_mysql \
@@ -49,7 +50,6 @@ RUN apk info \
4950
intl \
5051
opcache \
5152
pcntl \
52-
mbstring \
5353
iconv \
5454
&& pecl install \
5555
redis \
@@ -66,11 +66,6 @@ ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so php
6666
# change default shell
6767
SHELL ["/bin/bash", "-c"]
6868

69-
# create app user
70-
RUN addgroup -S app && \
71-
adduser -S app -G app && \
72-
echo "app ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
73-
7469
# create working dir
7570
RUN mkdir /opt/app
7671
WORKDIR /opt/app
@@ -90,6 +85,9 @@ COPY ./etc/nginx/ /etc/nginx/
9085
COPY ./usr/local/etc/php/ /usr/local/etc/php/
9186
COPY ./usr/local/etc/php-fpm.d/ /usr/local/etc/php-fpm.d/
9287

88+
# copy bin files
89+
COPY ./usr/local/bin/startup-commands.php /usr/local/bin/
90+
9391
# configure composer
9492
ENV COMPOSER_ALLOW_SUPERUSER=1 \
9593
COMPOSER_MEMORY_LIMIT=-1
@@ -100,11 +98,11 @@ RUN composer global require hirak/prestissimo
10098
RUN yarn config set strict-ssl false && \
10199
yarn global add cross-env
102100

103-
# copy home folder and make run scripts executable
104-
COPY ./home/app/ /home/app/
105-
COPY ./root/.bashrc /root/
106-
RUN find /home/app -name "run-*.sh" -exec chmod -v +x {} \;
101+
# copy root folder and make run scripts executable
102+
COPY ./root/ /root/
103+
RUN find /root -name "*.sh" -exec chmod -v +x {} \;
107104

108105
# run the application
109-
CMD /home/app/run-dev.sh
106+
ENTRYPOINT ["/root/entrypoint.sh"]
107+
CMD ["runsvdir", "/etc/service"]
110108
EXPOSE 8080

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ services:
4949
environment:
5050
- PHP_OPCACHE_VALIDATE_TIMESTAMPS=1
5151
- PHP_MEMORY_LIMIT=1G
52+
- PHP_MAX_EXECUTION_TIME=30
53+
- STARTUP_COMMAND1=/root/modules/dev.sh
54+
- STARTUP_COMMAND2=php artisan migrate --force
55+
- STARTUP_COMMAND3=php artisan setup
5256
volumes:
5357
- ./:/opt/app:cached
5458
ports:
@@ -68,6 +72,39 @@ Make sure to adjust your `.env` accordingly and set `APP_URL` to `http://localho
6872

6973
Run `docker-compose up` to start the services.
7074

75+
### Startup Commands
76+
77+
Further commands can be defined via ENV variable `STARTUP_COMMANDXXX`, which are executed at container start before the actual command.
78+
79+
The commands must be numbered sequentially and start with 1 (e.g. `STARTUP_COMMAND1=command`, `STARTUP_COMMAND2=...`).
80+
81+
```yml
82+
version: '3.7'
83+
services:
84+
app:
85+
image: sourceboat/docker-laravel
86+
restart: unless-stopped
87+
environment:
88+
- PHP_OPCACHE_VALIDATE_TIMESTAMPS=1
89+
- PHP_MEMORY_LIMIT=1G
90+
- PHP_MAX_EXECUTION_TIME=30
91+
- STARTUP_COMMAND1=/root/modules/storage.sh
92+
- STARTUP_COMMAND2=/root/modules/cache.sh
93+
- STARTUP_COMMAND3=php artisan migrate --force
94+
- STARTUP_COMMAND4=php artisan horizon:restart
95+
volumes:
96+
- ./:/opt/app:cached
97+
ports:
98+
- "8080:8080"
99+
depends_on:
100+
- mysql
101+
mysql:
102+
image: mysql:8.0
103+
environment:
104+
- "MYSQL_ROOT_PASSWORD=secret"
105+
- "MYSQL_DATABASE=default"
106+
```
107+
71108
### Production
72109

73110
`WIP`
@@ -79,6 +116,7 @@ Check [releases](https://github.com/sourceboat/docker-laravel/releases) for all
79116
## Credits
80117

81118
- [Phil-Bastian Berndt](https://github.com/pehbehbeh)
119+
- [Philipp Kübler](https://github.com/PKuebler)
82120
- [All Contributors](https://github.com/sourceboat/docker-laravel/graphs/contributors)
83121

84122
## License

etc/nginx/conf.d/default.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@ server {
2929
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
3030
fastcgi_param PATH_INFO $fastcgi_path_info;
3131
fastcgi_param HTTPS $is_https;
32+
fastcgi_hide_header X-Powered-By;
3233
}
3334
}

etc/nginx/nginx.conf

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
user nginx;
22
worker_processes 4;
33

4-
error_log /var/log/nginx/error.log warn;
5-
pid /var/run/nginx.pid;
4+
error_log /dev/stdout warn;
5+
pid /var/run/nginx.pid;
66

77
events {
88
worker_connections 1024;
@@ -11,18 +11,20 @@ events {
1111
}
1212

1313
http {
14-
include /etc/nginx/mime.types;
15-
default_type application/octet-stream;
14+
include /etc/nginx/mime.types;
15+
default_type application/octet-stream;
16+
17+
server_tokens off;
1618

1719
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
1820
'$status $body_bytes_sent "$http_referer" '
1921
'"$http_user_agent" "$http_x_forwarded_for"';
2022

21-
access_log /var/log/nginx/access.log main;
23+
access_log /dev/null main;
2224

23-
sendfile on;
25+
sendfile on;
2426

25-
keepalive_timeout 65;
27+
keepalive_timeout 65;
2628

2729
include /etc/nginx/conf.d/*.conf;
2830
}

home/app/.bashrc

Lines changed: 0 additions & 17 deletions
This file was deleted.

home/app/run-dev.sh

Lines changed: 0 additions & 24 deletions
This file was deleted.

root/.bashrc

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,17 @@
1-
source /home/app/.bashrc
1+
# useful aliases
2+
alias ll='ls -la'
3+
alias artisan="php artisan"
4+
5+
# prompt colors and short user display
6+
force_color_prompt=yes
7+
PS1='\[\033[1;36m\]\u\[\033[1;31m\]\[\033[1;32m\]:\[\033[1;35m\]\w\[\033[1;31m\]\$\[\033[0m\] '
8+
9+
# artisan autocompletion
10+
_artisan()
11+
{
12+
COMP_WORDBREAKS=${COMP_WORDBREAKS//:}
13+
COMMANDS=`artisan --raw --no-ansi list | sed "s/[[:space:]].*//g"`
14+
COMPREPLY=(`compgen -W "$COMMANDS" -- "${COMP_WORDS[COMP_CWORD]}"`)
15+
return 0
16+
}
17+
complete -F _artisan artisan

root/entrypoint.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
echo "Running entrypoint script..."
3+
4+
set -e
5+
6+
# make sure Laravel can write its own files
7+
mkdir -p /opt/app/storage/logs/
8+
touch /opt/app/storage/logs/laravel.log
9+
touch /opt/app/storage/logs/worker.log
10+
chown www-data:www-data -R /opt/app/storage
11+
chown www-data:www-data -R /opt/app/bootstrap/cache
12+
13+
# startup commands
14+
echo "Running startup commands..."
15+
php /usr/local/bin/startup-commands.php | bash
16+
17+
if [[ -n "$DB_HOST" || -n "$DB_PORT" ]]; then
18+
wait-for-it.sh --host=$DB_HOST --port=$DB_PORT
19+
fi
20+
21+
exec "$@"

root/modules/cache.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
3+
cd /opt/app
4+
5+
# build caches
6+
echo "Build caches..."
7+
php artisan config:cache
8+
php artisan route:cache
9+
php artisan view:cache

root/modules/dev.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
cd /opt/app
3+
4+
echo "Build development..."
5+
composer install --prefer-dist --no-progress --no-interaction
6+
yarn

root/modules/storage.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
cd /opt/app
3+
4+
echo "Create storage symlink..."
5+
su www-data -s /bin/sh -c "php artisan storage:link -q"

usr/local/bin/startup-commands.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
/**
3+
* A very simple script in charge of generating the startup commands based on environment variables.
4+
* The script is run on each start of the container.
5+
*
6+
* MIT License
7+
*
8+
* Copyright (c) 2018 TheCodingMachine
9+
*
10+
* Permission is hereby granted, free of charge, to any person obtaining a copy
11+
* of this software and associated documentation files (the "Software"), to deal
12+
* in the Software without restriction, including without limitation the rights
13+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+
* copies of the Software, and to permit persons to whom the Software is
15+
* furnished to do so, subject to the following conditions:
16+
*
17+
* The above copyright notice and this permission notice shall be included in all
18+
* copies or substantial portions of the Software.
19+
*
20+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26+
* SOFTWARE.
27+
*/
28+
29+
$commands = array_filter($_SERVER, function(string $key) {
30+
return strpos($key, 'STARTUP_COMMAND') === 0;
31+
}, ARRAY_FILTER_USE_KEY);
32+
33+
ksort($commands);
34+
35+
echo "set -e\n";
36+
37+
38+
// Let's run the commands as user $UID if env variable UID is set.
39+
40+
foreach ($commands as $command) {
41+
$line = $command;
42+
if (isset($_SERVER['UID'])) {
43+
$line = 'sudo -E -u \\#'.$_SERVER['UID'].' bash -c '.escapeshellarg($line);
44+
}
45+
echo $line."\n";
46+
}

usr/local/etc/php-fpm.d/zz-fpm.conf

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[www]
22
; Ondemand process manager
3-
pm = ondemand
3+
pm = ${PHP_FPM_PM}
44

55
; The number of child processes to be created when pm is set to 'static' and the
66
; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'.
@@ -11,21 +11,24 @@ pm = ondemand
1111
; forget to tweak pm.* to fit your needs.
1212
; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand'
1313
; Note: This value is mandatory.
14-
pm.max_children = 100
14+
pm.max_children = ${PHP_FPM_MAX_CHILDREN}
1515

1616
; The number of seconds after which an idle process will be killed.
1717
; Note: Used only when pm is set to 'ondemand'
1818
; Default Value: 10s
19-
pm.process_idle_timeout = 10s;
19+
pm.process_idle_timeout = ${PHP_FPM_PROCESS_IDLE_TIMEOUT};
2020

2121
; The number of requests each child process should execute before respawning.
2222
; This can be useful to work around memory leaks in 3rd party libraries. For
2323
; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS.
2424
; Default Value: 0
25-
pm.max_requests = 1000
25+
pm.max_requests = ${PHP_FPM_MAX_REQUESTS}
2626

2727
; Make sure the FPM workers can reach the environment variables for configuration
2828
clear_env = no
2929

3030
; Catch output from PHP
3131
catch_workers_output = yes
32+
33+
; No Access Log
34+
access.log=/dev/null

usr/local/etc/php/php.ini

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
; Resource Limits ;
55
;;;;;;;;;;;;;;;;;;;
66

7-
max_execution_time = 60
7+
max_execution_time = ${PHP_MAX_EXECUTION_TIME}
88
max_input_time = 60
99
memory_limit = ${PHP_MEMORY_LIMIT}
1010

@@ -56,3 +56,10 @@ opcache.memory_consumption=${PHP_OPCACHE_MEMORY_CONSUMPTION}
5656
opcache.max_wasted_percentage=${PHP_OPCACHE_MAX_WASTED_PERCENTAGE}
5757
opcache.interned_strings_buffer=16
5858
opcache.fast_shutdown=1
59+
60+
;;;;;;;;;;;;;;;;;
61+
; Miscellaneous ;
62+
;;;;;;;;;;;;;;;;;
63+
64+
; http://www.php.net/manual/en/ini.core.php#ini.expose-php
65+
expose_php = Off

0 commit comments

Comments
 (0)