Skip to content

Commit d8c21f3

Browse files
author
Dmitriy
committed
added supervisord with cron job
1 parent 517548f commit d8c21f3

File tree

9 files changed

+73
-6
lines changed

9 files changed

+73
-6
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ env-prod:
3434
ssh:
3535
@docker-compose $(project) exec laravel bash
3636

37+
ssh-supervisord:
38+
@docker-compose $(project) exec supervisord bash
39+
3740
exec:
3841
@docker-compose $(project) exec laravel $$cmd
3942

docker-compose-ci.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,21 @@ services:
1616
- "443:443"
1717
depends_on:
1818
- mysql
19+
links:
20+
- mysql
21+
22+
supervisord:
23+
image: laravel:latest
24+
build:
25+
context: .
26+
dockerfile: ./docker/development/Dockerfile
27+
container_name: supervisord
28+
user: root
29+
depends_on:
30+
- mysql
31+
links:
32+
- mysql
33+
command: ["/usr/bin/supervisord"]
1934

2035
mysql:
2136
image: mysql:8.0
@@ -24,8 +39,6 @@ services:
2439
environment:
2540
- MYSQL_ROOT_PASSWORD=secret
2641
- MYSQL_DATABASE=laravel
27-
expose:
28-
- "33061"
2942
ports:
3043
- "33061:3306"
3144
volumes:

docker-compose-prod.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,21 @@ services:
1616
- "443:443"
1717
depends_on:
1818
- mysql
19+
links:
20+
- mysql
21+
22+
supervisord:
23+
image: laravel:latest
24+
build:
25+
context: .
26+
dockerfile: ./docker/development/Dockerfile
27+
container_name: supervisord
28+
user: root
29+
depends_on:
30+
- mysql
31+
links:
32+
- mysql
33+
command: ["/usr/bin/supervisord"]
1934

2035
mysql:
2136
image: mysql:8.0
@@ -24,8 +39,6 @@ services:
2439
environment:
2540
- MYSQL_ROOT_PASSWORD=secret
2641
- MYSQL_DATABASE=laravel
27-
expose:
28-
- "33061"
2942
ports:
3043
- "33061:3306"
3144
volumes:

docker-compose.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@ services:
1818
- .:/var/www/laravel
1919
depends_on:
2020
- mysql
21+
links:
22+
- mysql
23+
24+
supervisord:
25+
image: laravel:latest
26+
build:
27+
context: .
28+
dockerfile: ./docker/development/Dockerfile
29+
container_name: supervisord
30+
user: root
31+
depends_on:
32+
- mysql
33+
links:
34+
- mysql
35+
command: ["/usr/bin/supervisord"]
2136

2237
mysql:
2338
image: mysql:8.0
@@ -26,8 +41,6 @@ services:
2641
environment:
2742
- MYSQL_ROOT_PASSWORD=secret
2843
- MYSQL_DATABASE=laravel
29-
expose:
30-
- "33061"
3144
ports:
3245
- "33061:3306"
3346
volumes:

docker/development/Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ RUN apt-get update && apt-get upgrade -y && apt-get install -y \
1010
libxml2 \
1111
libxml2-dev \
1212
libreadline-dev \
13+
supervisor \
14+
cron \
1315
&& rm -r /var/lib/apt/lists/* \
1416
&& docker-php-ext-configure pdo_mysql --with-pdo-mysql=mysqlnd \
1517
&& docker-php-ext-install \
@@ -40,6 +42,12 @@ COPY ./docker/hosts/laravel-ssl.conf /etc/apache2/sites-available/laravel-ssl.co
4042
RUN a2dissite 000-default.conf && a2ensite laravel.conf && a2ensite laravel-ssl
4143
COPY ./docker/development/php.ini /usr/local/etc/php/php.ini
4244

45+
# add supervisor
46+
RUN mkdir -p /var/log/supervisor
47+
COPY --chown=root:root ./docker/other/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
48+
COPY --chown=root:root ./docker/other/cron /var/spool/cron/crontabs/root
49+
RUN chmod 0600 /var/spool/cron/crontabs/root
50+
4351
# generate certificates
4452
RUN openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/ssl-cert-snakeoil.key -out /etc/ssl/certs/ssl-cert-snakeoil.pem -subj "/C=AT/ST=Vienna/L=Vienna/O=Security/OU=Development/CN=example.com"
4553

docker/other/cron

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* * * * * cd /var/www/laravel && /usr/local/bin/php artisan schedule:run > /proc/1/fd/1 2>/proc/1/fd/2

docker/other/supervisord.conf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[supervisord]
2+
nodaemon=true
3+
4+
[program:cron]
5+
command=/usr/sbin/cron -l 2 -f
6+
autostart=true
7+
autorestart=true

docker/production/Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ RUN apt-get update && apt-get upgrade -y && apt-get install -y \
1010
libxml2 \
1111
libxml2-dev \
1212
libreadline-dev \
13+
supervisor \
14+
cron \
1315
&& rm -r /var/lib/apt/lists/* \
1416
&& docker-php-ext-configure pdo_mysql --with-pdo-mysql=mysqlnd \
1517
&& docker-php-ext-install \
@@ -36,6 +38,12 @@ COPY ./docker/hosts/laravel-ssl.conf /etc/apache2/sites-available/laravel-ssl.co
3638
RUN a2dissite 000-default.conf && a2ensite laravel.conf && a2ensite laravel-ssl
3739
COPY ./docker/production/php.ini /usr/local/etc/php/php.ini
3840

41+
# add supervisor
42+
RUN mkdir -p /var/log/supervisor
43+
COPY --chown=root:root ./docker/other/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
44+
COPY --chown=root:root ./docker/other/cron /var/spool/cron/crontabs/root
45+
RUN chmod 0600 /var/spool/cron/crontabs/root
46+
3947
# generate certificates. TODO: change it
4048
RUN openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/ssl-cert-snakeoil.key -out /etc/ssl/certs/ssl-cert-snakeoil.pem -subj "/C=AT/ST=Vienna/L=Vienna/O=Security/OU=Development/CN=example.com"
4149

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ Note: OS recommendation - Linux Ubuntu based.
6262
make stop
6363
make restart
6464
make ssh
65+
make ssh-supervisord
6566
make composer-install
6667
make composer-update
6768
make info

0 commit comments

Comments
 (0)