Skip to content

Commit d45ada3

Browse files
committed
Add cron docker image
1 parent 6310f51 commit d45ada3

File tree

4 files changed

+65
-6
lines changed

4 files changed

+65
-6
lines changed

.github/workflows/docker-publish.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ jobs:
7272
name: fpm
7373
artifact: php
7474

75+
- image: ghcr.io/kduma-oss/webprint-server/cron
76+
name: cron
77+
artifact: php
78+
7579
- image: ghcr.io/kduma-oss/webprint-server/nginx
7680
name: nginx
7781
artifact: nginx

Dockerfile

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ WORKDIR /var/www/html
1010

1111

1212

13+
FROM php:8.1-fpm-alpine AS php_base
14+
WORKDIR /var/www/html
15+
16+
RUN docker-php-ext-install pdo pdo_mysql
17+
RUN docker-php-ext-install opcache
18+
19+
COPY docker/php/opcache.ini /usr/local/etc/php/conf.d/opcache.ini
20+
21+
22+
1323

1424

1525

@@ -24,20 +34,36 @@ COPY build/nginx/ /var/www/html/
2434

2535

2636

27-
FROM php:8.1-fpm-alpine AS fpm
37+
FROM php_base AS fpm
2838
WORKDIR /var/www/html
2939

40+
COPY docker/php/entrypoint.sh /var/www/entrypoint.sh
41+
RUN chmod +x /var/www/entrypoint.sh
3042

31-
RUN docker-php-ext-install pdo pdo_mysql
32-
RUN docker-php-ext-install opcache
43+
COPY build/php/ /var/www/html/
44+
45+
RUN chown -R www-data:www-data /var/www/html/storage
46+
RUN chown -R www-data:www-data /var/www/html/bootstrap/cache
47+
48+
ENV APP_ENV=production
49+
ENV APP_DEBUG=false
50+
51+
VOLUME /var/www/html/storage/app/jobs
52+
53+
CMD ["/var/www/entrypoint.sh"]
54+
55+
56+
57+
FROM php_base AS cron
58+
WORKDIR /var/www/html
3359

34-
COPY docker/php/opcache.ini /usr/local/etc/php/conf.d/opcache.ini
3560
COPY docker/php/entrypoint.sh /var/www/entrypoint.sh
3661
RUN chmod +x /var/www/entrypoint.sh
3762

38-
3963
COPY build/php/ /var/www/html/
4064

65+
COPY docker/php/crontab /etc/crontabs/root
66+
4167
RUN chown -R www-data:www-data /var/www/html/storage
4268
RUN chown -R www-data:www-data /var/www/html/bootstrap/cache
4369

@@ -46,4 +72,4 @@ ENV APP_DEBUG=false
4672

4773
VOLUME /var/www/html/storage/app/jobs
4874

49-
CMD ["/var/www/entrypoint.sh"]
75+
CMD ["crond", "-f"]

docker-compose-prod.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,33 @@ services:
2929
- db
3030
volumes:
3131
- jobs_data:/var/www/html/storage/app/jobs
32+
- cache_data:/var/www/html/storage/framework/cache/data
33+
environment:
34+
- DB_CONNECTION=mysql
35+
- DB_HOST=db
36+
- DB_PORT=3306
37+
- DB_DATABASE=webprint_server
38+
- DB_USERNAME=webprint_server
39+
- DB_PASSWORD=${DB_PASSWORD}
40+
41+
- APP_DEBUG=true
42+
- LOG_LEVEL=errorlog
43+
- APP_KEY=${APP_KEY}
44+
45+
cron:
46+
build:
47+
context: .
48+
dockerfile: Dockerfile
49+
target: cron
50+
image: ghcr.io/kduma-oss/webprint-server/cron
51+
restart: always
52+
networks:
53+
- internal
54+
depends_on:
55+
- db
56+
volumes:
57+
- jobs_data:/var/www/html/storage/app/jobs
58+
- cache_data:/var/www/html/storage/framework/cache/data
3259
environment:
3360
- DB_CONNECTION=mysql
3461
- DB_HOST=db
@@ -61,3 +88,4 @@ networks:
6188
volumes:
6289
db_data: {}
6390
jobs_data: {}
91+
cache_data: {}

docker/php/crontab

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* * * * * cd /var/www/html && php artisan schedule:run >> /dev/stdout 2>&1

0 commit comments

Comments
 (0)