From 7bfa9ef91dd48d2d321aa0b8744e2bde0413f53b Mon Sep 17 00:00:00 2001 From: Saeed Vaziry <61919774+saeedvaziry@users.noreply.github.com> Date: Sat, 21 Jun 2025 09:48:07 +0200 Subject: [PATCH] use redis for queues, sessions and cache (#618) --- .env.sail | 3 +++ config/cache.php | 2 +- config/queue.php | 12 ++++++++---- config/session.php | 2 +- ..._06_14_111059_add_name_to_workers_table.php | 2 +- docker-compose.yml | 18 +++++++++++++++++- docker/Dockerfile | 2 +- docker/docker-compose.yml | 1 + docker/start.sh | 1 + scripts/install.sh | 6 ++++++ 10 files changed, 40 insertions(+), 9 deletions(-) diff --git a/.env.sail b/.env.sail index 8768a869..272e44fc 100644 --- a/.env.sail +++ b/.env.sail @@ -15,3 +15,6 @@ MAIL_PASSWORD=null MAIL_ENCRYPTION=null MAIL_FROM_ADDRESS="noreply@${APP_NAME}" MAIL_FROM_NAME="${APP_NAME}" + +REDIS_HOST=redis +REDIS_PORT=6379 diff --git a/config/cache.php b/config/cache.php index c5aa96cd..48aae5c1 100644 --- a/config/cache.php +++ b/config/cache.php @@ -15,7 +15,7 @@ | */ - 'default' => env('CACHE_DRIVER', 'file'), + 'default' => env('CACHE_DRIVER', 'redis'), /* |-------------------------------------------------------------------------- diff --git a/config/queue.php b/config/queue.php index 410319bd..2ec44989 100755 --- a/config/queue.php +++ b/config/queue.php @@ -44,19 +44,23 @@ ], 'default' => [ - 'driver' => 'database', - 'table' => 'jobs', + 'driver' => 'redis', + 'connection' => 'default', 'queue' => 'default', 'timeout' => 90, 'retry_after' => 600, + 'block_for' => null, + 'after_commit' => false, ], 'ssh' => [ - 'driver' => 'database', - 'table' => 'jobs', + 'driver' => 'redis', + 'connection' => 'default', 'queue' => 'default', 'timeout' => 600, 'retry_after' => 600, + 'block_for' => null, + 'after_commit' => false, ], ], diff --git a/config/session.php b/config/session.php index 2db3bd29..11dd8f1c 100644 --- a/config/session.php +++ b/config/session.php @@ -18,7 +18,7 @@ | */ - 'driver' => env('SESSION_DRIVER', 'database'), + 'driver' => env('SESSION_DRIVER', 'redis'), /* |-------------------------------------------------------------------------- diff --git a/database/migrations/2025_06_14_111059_add_name_to_workers_table.php b/database/migrations/2025_06_14_111059_add_name_to_workers_table.php index 197e84f4..1c262bbf 100644 --- a/database/migrations/2025_06_14_111059_add_name_to_workers_table.php +++ b/database/migrations/2025_06_14_111059_add_name_to_workers_table.php @@ -16,7 +16,7 @@ public function up(): void public function down(): void { Schema::table('workers', function (Blueprint $table) { - $table->dropColumn('name'); + // $table->dropColumn('name'); }); } }; diff --git a/docker-compose.yml b/docker-compose.yml index a6132450..fff110c5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -21,7 +21,18 @@ services: - '.:/var/www/html' networks: - vito - depends_on: { } + depends_on: + - redis + redis: + image: 'redis:alpine' + volumes: + - 'vito-redis:/data' + networks: + - vito + healthcheck: + test: [ "CMD", "redis-cli", "ping" ] + retries: 3 + timeout: 5s worker: build: context: ./vendor/laravel/sail/runtimes/8.4 @@ -43,6 +54,11 @@ services: - vito depends_on: - app + - redis networks: vito: driver: bridge +volumes: + vito-redis: + driver: local + name: vito-redis diff --git a/docker/Dockerfile b/docker/Dockerfile index 724f8226..a2f0a3f4 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -8,7 +8,7 @@ ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update && apt-get upgrade -y && apt-get autoremove -y # requirements -RUN apt-get install -y software-properties-common curl zip unzip gcc nginx git \ +RUN apt-get install -y software-properties-common curl zip unzip gcc nginx redis-server git \ cron gnupg gosu curl ca-certificates zip unzip supervisor libcap2-bin libpng-dev \ dnsutils librsvg2-bin fswatch wget openssh-client \ && add-apt-repository ppa:ondrej/php -y \ diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 542b41da..1850635d 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -9,6 +9,7 @@ services: PASSWORD: "password" APP_KEY: "base64:UodiJrx3DkcMlizmoimNlDn+yd4q5f2VbkBay19rJwM=" APP_PORT: 8000 + APP_URL: "http://localhost:8000" extra_hosts: - 'host.docker.internal:host-gateway' ports: diff --git a/docker/start.sh b/docker/start.sh index ea716e46..b4bb2b53 100644 --- a/docker/start.sh +++ b/docker/start.sh @@ -58,6 +58,7 @@ chown -R www-data:www-data /var/www/html \ && chmod -R 755 /var/www/html/storage /var/www/html/bootstrap/cache service php8.4-fpm start +service redis-server start service nginx start php /var/www/html/artisan migrate --force diff --git a/scripts/install.sh b/scripts/install.sh index a440ac48..0a6c8aca 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -108,6 +108,12 @@ sed -i "s/post_max_size = .*/post_max_size = 1G/" /etc/php/${V_PHP_VERSION}/fpm/ curl -sS https://getcomposer.org/installer -o composer-setup.php php composer-setup.php --install-dir=/usr/local/bin --filename=composer +# redis +apt install redis-server -y +service redis enable +service redis start + + # setup website export COMPOSER_ALLOW_SUPERUSER=1 export V_REPO="https://github.com/vitodeploy/vito.git"