From ee5172fb5cfa97e3d5881faa507ff6ab6760ee89 Mon Sep 17 00:00:00 2001 From: Jovert Lota Palonpon Date: Sun, 7 Apr 2019 00:03:48 +0800 Subject: [PATCH] Created micro-services: queues & jobs, resolve #24 --- .docker/{php => php-fpm}/Dockerfile | 8 ++++++ .docker/{php => php-fpm}/php.ini | 0 .docker/scripts/queuer.sh | 3 +++ .docker/scripts/scheduler.sh | 7 +++++ .docker/webserver/nginx.conf.example | 2 +- docker-compose.yml | 39 ++++++++++++++++++++++------ 6 files changed, 50 insertions(+), 9 deletions(-) rename .docker/{php => php-fpm}/Dockerfile (82%) rename .docker/{php => php-fpm}/php.ini (100%) create mode 100644 .docker/scripts/queuer.sh create mode 100644 .docker/scripts/scheduler.sh diff --git a/.docker/php/Dockerfile b/.docker/php-fpm/Dockerfile similarity index 82% rename from .docker/php/Dockerfile rename to .docker/php-fpm/Dockerfile index 44b8fe3..96421ea 100644 --- a/.docker/php/Dockerfile +++ b/.docker/php-fpm/Dockerfile @@ -46,5 +46,13 @@ RUN composer install --no-interaction --no-plugins --no-scripts # Copy app COPY . ${MASTER_DIR} +# Copy scripts +COPY ./.docker/scripts/queuer.sh /usr/local/bin/laravel-queuer +COPY ./.docker/scripts/scheduler.sh /usr/local/bin/laravel-scheduler + +# Give the scripts executable permissions +RUN chmod u+x /usr/local/bin/laravel-queuer +RUN chmod u+x /usr/local/bin/laravel-scheduler + EXPOSE 9000 CMD ["php-fpm"] \ No newline at end of file diff --git a/.docker/php/php.ini b/.docker/php-fpm/php.ini similarity index 100% rename from .docker/php/php.ini rename to .docker/php-fpm/php.ini diff --git a/.docker/scripts/queuer.sh b/.docker/scripts/queuer.sh new file mode 100644 index 0000000..7c0c39a --- /dev/null +++ b/.docker/scripts/queuer.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +php /var/www/html/artisan queue:work --verbose --tries=3 --timeout=90 \ No newline at end of file diff --git a/.docker/scripts/scheduler.sh b/.docker/scripts/scheduler.sh new file mode 100644 index 0000000..36209b7 --- /dev/null +++ b/.docker/scripts/scheduler.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +while [ true ] +do + php /var/www/html/artisan schedule:run --verbose --no-interaction & + sleep 60 +done \ No newline at end of file diff --git a/.docker/webserver/nginx.conf.example b/.docker/webserver/nginx.conf.example index 9215def..4a4920b 100644 --- a/.docker/webserver/nginx.conf.example +++ b/.docker/webserver/nginx.conf.example @@ -10,7 +10,7 @@ server { location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; - fastcgi_pass laravel-react-admin-php:9000; + fastcgi_pass laravel-react-admin-php-fpm:9000; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; diff --git a/docker-compose.yml b/docker-compose.yml index f02ed71..f13ddb6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,19 +1,42 @@ version: '3' services: - laravel-react-admin-php: + php-fpm: build: context: . - dockerfile: ./.docker/php/Dockerfile - container_name: laravel-react-admin-php + dockerfile: ./.docker/php-fpm/Dockerfile + image: laravel-react-admin-php-fpm + container_name: laravel-react-admin-php-fpm restart: unless-stopped working_dir: /var/www/html volumes: - ./:/var/www/html - - ./.docker/php/php.ini:/usr/local/etc/php/conf.d/local.ini:ro + - ./.docker/php-fpm/php.ini:/usr/local/etc/php/conf.d/local.ini:ro env_file: - .env - laravel-react-admin-webserver: + scheduler: + image: laravel-react-admin-php-fpm + container_name: laravel-react-admin-scheduler + volumes: + - ./:/var/www/html + depends_on: + - php-fpm + command: laravel-scheduler + env_file: + - .env + + queuer: + image: laravel-react-admin-php-fpm + container_name: laravel-react-admin-queuer + volumes: + - ./:/var/www/html + depends_on: + - php-fpm + command: laravel-queuer + env_file: + - .env + + webserver: image: nginx:alpine container_name: laravel-react-admin-webserver restart: unless-stopped @@ -24,9 +47,9 @@ services: - ./:/var/www/html - ./.docker/webserver/nginx.conf:/etc/nginx/conf.d/nginx.conf depends_on: - - laravel-react-admin-php + - php-fpm - laravel-react-admin-db: + db: image: mysql:5.7 container_name: laravel-react-admin-db restart: unless-stopped @@ -38,4 +61,4 @@ services: volumes: - ~/.laravel-react-admin-data:/var/lib/mysql depends_on: - - laravel-react-admin-php + - php-fpm