Skip to content

Commit da3d30f

Browse files
committed
docker: add Laravel scheduler and queue worker services with S6 integration
1 parent fcd5295 commit da3d30f

File tree

10 files changed

+31
-29
lines changed

10 files changed

+31
-29
lines changed

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ RUN set -e; \
111111
RUN install-php-extensions intl \
112112
&& rm -rf /tmp/*
113113

114+
# Copy s6 service definitions for Laravel scheduler and queue worker
115+
COPY --chmod=755 root /
116+
114117
# Drop back to our unprivileged user
115118
USER www-data
116119

README.md

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,9 @@
22

33
> [!INFO]
44
> **Work in Progress** - This is a custom Docker image build based on [ServerSideUp's Docker PHP](https://serversideup.net/open-source/docker-php/).
5-
>
6-
> This image separates the application into multiple services:
7-
> - **Main App** (PHP/Web server)
8-
> - **Task Scheduler** (Cron jobs)
9-
> - **Queue Worker** (Background jobs)
105
116
### Using
127

13-
This image is designed to work as a service and separates the app from the task scheduler and queue worker into separate service containers.
14-
158
```yaml
169
# compose.yml
1710
services:
@@ -33,28 +26,6 @@ services:
3326
- DB_PASSWORD=
3427
depends_on:
3528
- db
36-
- task
37-
- queue
38-
39-
task:
40-
image: speedtest-tracker-docker:latest
41-
command: ["php", "/var/www/html/artisan", "schedule:work"]
42-
stop_signal: SIGTERM # Set this for graceful shutdown if you're using fpm-apache or fpm-nginx
43-
healthcheck:
44-
test: ["CMD", "healthcheck-schedule"]
45-
start_period: 10s
46-
networks:
47-
- speedtest
48-
49-
queue:
50-
image: speedtest-tracker-docker:latest
51-
command: ["php", "/var/www/html/artisan", "queue:work", "--tries=3"]
52-
stop_signal: SIGTERM # Set this for graceful shutdown if you're using fpm-apache or fpm-nginx
53-
healthcheck:
54-
test: ["CMD", "healthcheck-queue"]
55-
start_period: 10s
56-
networks:
57-
- speedtest
5829

5930
db:
6031
image: 'postgres:18-alpine'

root/etc/s6-overlay/s6-rc.d/laravel-queue/dependencies.d/svc-php-fpm

Whitespace-only changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/command/with-contenv bash
2+
3+
# Change to the application directory
4+
cd /var/www/html
5+
6+
# Run the Laravel queue worker
7+
exec s6-setuidgid www-data php artisan queue:work --verbose --sleep=5 --tries=3
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
longrun

root/etc/s6-overlay/s6-rc.d/laravel-scheduler/dependencies.d/svc-php-fpm

Whitespace-only changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/command/with-contenv bash
2+
3+
# Change to the application directory
4+
cd /var/www/html
5+
6+
# Handle shutdown gracefully
7+
shutdown() {
8+
echo "Received shutdown signal, exiting..."
9+
exit 0
10+
}
11+
12+
trap shutdown SIGTERM SIGINT
13+
14+
# Run the Laravel scheduler every minute
15+
while true; do
16+
s6-setuidgid www-data php artisan schedule:run --verbose --no-interaction
17+
sleep 60 &
18+
wait $!
19+
done
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
longrun

root/etc/s6-overlay/s6-rc.d/user/contents.d/laravel-queue

Whitespace-only changes.

root/etc/s6-overlay/s6-rc.d/user/contents.d/laravel-scheduler

Whitespace-only changes.

0 commit comments

Comments
 (0)