Skip to content

Commit 511e0d8

Browse files
committed
feat: added redis as cache
1 parent 78596b5 commit 511e0d8

File tree

6 files changed

+41
-28
lines changed

6 files changed

+41
-28
lines changed

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ LOG_DEPRECATIONS_CHANNEL=errorlog
1212

1313
DB_CONNECTION=sqlite
1414

15+
SESSION_DRIVER=redis
16+
CACHE_STORE=redis
17+
1518
FILESYSTEM_DISK=local
1619
AWS_ACCESS_KEY_ID=
1720
AWS_SECRET_ACCESS_KEY=

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"ext-pcntl": "*",
2424
"ext-pcre": "*",
2525
"ext-pdo": "*",
26+
"ext-redis": "*",
2627
"ext-session": "*",
2728
"ext-tokenizer": "*",
2829
"ext-xml": "*",

composer.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

containers/php/Dockerfile

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ARG PHP_EXTENSIONS="pcntl"
1+
ARG PHP_EXTENSIONS="pcntl redis"
22
ARG ADDITIONAL_PACKAGES="bash rclone sqlite"
33

44
FROM php:8.4.11-fpm-alpine AS base
@@ -10,14 +10,13 @@ ADD --chmod=777 \
1010
--checksum=sha256:206a8f9b2177703fc5aa924d85ad6c72e82413e2d09635b4c9c82a1b65b5b3d5 \
1111
https://github.com/eficode/wait-for/releases/download/v2.2.4/wait-for /usr/local/bin/wait-for
1212
# configure entrypoints and image
13-
RUN echo "* * * * * cd /var/www/html && php artisan schedule:run" > /etc/crontabs/www-data
14-
COPY --chmod=777 containers/php/entrypoint.sh /usr/local/sbin/entrypoint
15-
ENTRYPOINT ["entrypoint"]
16-
CMD ["php-fpm"]
1713
ARG PHP_EXTENSIONS
1814
ARG ADDITIONAL_PACKAGES
1915
RUN apk add --no-cache ${ADDITIONAL_PACKAGES} \
2016
&& install-php-extensions ${PHP_EXTENSIONS}
17+
COPY --chmod=777 containers/php/entrypoint.sh /usr/local/sbin/entrypoint
18+
ENTRYPOINT ["entrypoint"]
19+
CMD ["php-fpm"]
2120

2221

2322
FROM base AS development

containers/php/entrypoint.sh

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,38 @@
22

33
set -e
44

5-
if [ -f '.env' ]; then
6-
. .env
7-
fi
5+
wait_for_services() {
6+
wait-for "${PHP_HOST:?Missing PHP_HOST}:${PHP_PORT:?Missing PHP_PORT}" -t 60
7+
}
88

9-
if [ "$1" = "php-fpm" ]; then
9+
optimize() {
1010
if [ "$APP_ENV" != "local" ]; then
1111
php artisan optimize
12-
else
12+
fi
13+
}
14+
15+
if [ "$1" = "php-fpm" ]; then
16+
optimize
17+
if [ "$APP_ENV" = "local" ]; then
1318
composer install
1419
fi
1520
php artisan migrate --force
1621
if [ "$(id -u)" = '0' ]; then
1722
chown -R www-data:www-data storage
1823
fi
24+
exec "$@"
1925
elif [ "$1" = "scheduler" ]; then
20-
wait-for "${PHP_HOST:?Missing PHP_HOST}:${PHP_PORT:?Missing PHP_PORT}" -t 60
21-
if [ "$APP_ENV" != "local" ]; then
22-
php artisan optimize
23-
fi
24-
set -- crond -f -d 8
26+
wait_for_services
27+
optimize
28+
exec su -s /bin/sh -c "php artisan schedule:work --quiet" www-data
2529
elif [ "$1" = "worker" ]; then
26-
wait-for "${PHP_HOST:?Missing PHP_HOST}:${PHP_PORT:?Missing PHP_PORT}" -t 60
27-
if [ "$APP_ENV" != "local" ]; then
28-
php artisan optimize
29-
fi
30-
set -- su -s /bin/sh -c "php artisan queue:work --tries=3 --timeout=1800" www-data
30+
wait_for_services
31+
optimize
32+
exec su -s /bin/sh -c "php artisan queue:work --tries=3 --timeout=1800" www-data
3133
elif [ "$1" = "nightwatch" ]; then
32-
wait-for "${PHP_HOST:?Missing PHP_HOST}:${PHP_PORT:?Missing PHP_PORT}" -t 60
33-
if [ "$APP_ENV" != "local" ]; then
34-
php artisan optimize
35-
fi
36-
set -- su -s /bin/sh -c "php artisan nightwatch:agent --listen-on 0.0.0.0:2407" www-data
34+
wait_for_services
35+
optimize
36+
exec su -s /bin/sh -c "php artisan nightwatch:agent --listen-on 0.0.0.0:2407" www-data
37+
else
38+
exec "$@"
3739
fi
38-
39-
exec "$@"

docker-compose.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ x-app: &app
1212
volumes:
1313
- /etc/localtime:/etc/localtime:ro
1414
- .:/var/www/html
15+
env_file:
16+
- .env
1517

1618
services:
1719
nginx:
@@ -32,6 +34,7 @@ services:
3234
<<: *app
3335
user: root
3436
command: scheduler
37+
stop_signal: SIGKILL
3538
environment:
3639
PHP_HOST: php
3740
PHP_PORT: 9000
@@ -46,6 +49,7 @@ services:
4649
<<: *app
4750
user: root
4851
command: nightwatch
52+
stop_signal: SIGKILL
4953
environment:
5054
PHP_HOST: php
5155
PHP_PORT: 9000
@@ -55,3 +59,8 @@ services:
5559
timeout: 5s
5660
retries: 3
5761
start_period: 5s
62+
redis:
63+
image: redis:8.2.1-alpine
64+
restart: unless-stopped
65+
ports:
66+
- "6379:6379"

0 commit comments

Comments
 (0)