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

0 commit comments

Comments
 (0)