From 03f6305e7295a141c6a102f7a26494fd0313e8dc Mon Sep 17 00:00:00 2001 From: Refringe Date: Sun, 9 Jun 2024 20:18:25 -0400 Subject: [PATCH] Laravel Sail for Development --- .env.ci | 3 +- .env.example | 32 +++---- .github/workflows/tests.yml | 6 +- app/Console/Commands/ImportHub.php | 9 +- composer.json | 1 + composer.lock | 136 ++++++++++++++++++++++++++++- docker-compose.yml | 103 ++++++++++++++++++++++ phpunit.xml | 2 +- 8 files changed, 267 insertions(+), 25 deletions(-) create mode 100644 docker-compose.yml diff --git a/.env.ci b/.env.ci index 816800d..267e7e9 100644 --- a/.env.ci +++ b/.env.ci @@ -11,11 +11,10 @@ LOG_LEVEL=debug DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=33306 -DB_DATABASE=test +DB_DATABASE=testing DB_USERNAME=root DB_PASSWORD= -BROADCAST_DRIVER=log FILESYSTEM_DISK=local QUEUE_CONNECTION=sync CACHE_DRIVER=array diff --git a/.env.example b/.env.example index cdc4fa4..9030640 100644 --- a/.env.example +++ b/.env.example @@ -3,7 +3,7 @@ APP_ENV=local APP_KEY= APP_DEBUG=true APP_TIMEZONE=UTC -APP_URL=http://forge.test +APP_URL=http://localhost APP_LOCALE=en APP_FALLBACK_LOCALE=en APP_FAKER_LOCALE=en_US @@ -19,20 +19,20 @@ LOG_DEPRECATIONS_CHANNEL=null LOG_LEVEL=debug DB_CONNECTION=mysql -DB_HOST=localhost +DB_HOST=mysql DB_PORT=3306 DB_DATABASE=forge -DB_USERNAME=root -DB_PASSWORD= +DB_USERNAME=forge +DB_PASSWORD=password # This is only needed if you are running the app:import-hub command. # For normal development you should just seed the database with fake data: # `php artisan migrate:fresh --seed` DB_HUB_CONNECTION=mysql -DB_HUB_HOST=localhost -DB_HUB_PORT=3306 -DB_HUB_DATABASE=forge -DB_HUB_USERNAME=root +DB_HUB_HOST= +DB_HUB_PORT= +DB_HUB_DATABASE= +DB_HUB_USERNAME= DB_HUB_PASSWORD= SESSION_DRIVER=redis @@ -43,32 +43,32 @@ SESSION_ENCRYPT=false SESSION_PATH=/ SESSION_DOMAIN=null -BROADCAST_CONNECTION=log FILESYSTEM_DISK=local CACHE_STORE=redis QUEUE_CONNECTION=redis -REDIS_HOST=127.0.0.1 +REDIS_HOST=redis REDIS_PASSWORD=null REDIS_PORT=6379 REDIS_CACHE_CONNECTION=cache REDIS_QUEUE_CONNECTION=queue REDIS_QUEUE=queue -SCOUT_DRIVER=meilisearch SCOUT_QUEUE=true - -MEILISEARCH_HOST=http://127.0.0.1:7700 -MEILISEARCH_KEY=LARAVEL-HERD +SCOUT_DRIVER=meilisearch +MEILISEARCH_HOST=http://meilisearch:7700 +MEILISEARCH_KEY= MEILISEARCH_NO_ANALYTICS=true MAIL_MAILER=smtp -MAIL_HOST=127.0.0.1 -MAIL_PORT=2525 +MAIL_HOST=mailpit +MAIL_PORT=1025 MAIL_USERNAME=${APP_NAME} MAIL_ENCRYPTION=null MAIL_FROM_ADDRESS="no-reply@sp-tarkov.com" MAIL_FROM_NAME="${APP_NAME}" NOVA_LICENSE_KEY= + +SAIL_XDEBUG_MODE=develop,debug,coverage diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index cfdc3e8..e111964 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -16,7 +16,7 @@ jobs: image: mysql:8.3 env: MYSQL_ALLOW_EMPTY_PASSWORD: yes - MYSQL_DATABASE: test + MYSQL_DATABASE: testing ports: - 33306:3306 options: >- @@ -102,7 +102,7 @@ jobs: - name: Run Migrations env: DB_CONNECTION: mysql - DB_DATABASE: test + DB_DATABASE: testing DB_PORT: 33306 DB_USER: root run: php artisan migrate @@ -110,7 +110,7 @@ jobs: - name: Execute Unit & Feature Tests env: DB_CONNECTION: mysql - DB_DATABASE: test + DB_DATABASE: testing DB_PORT: 33306 DB_USER: root run: | diff --git a/app/Console/Commands/ImportHub.php b/app/Console/Commands/ImportHub.php index f07767b..de1f524 100644 --- a/app/Console/Commands/ImportHub.php +++ b/app/Console/Commands/ImportHub.php @@ -352,8 +352,13 @@ class ImportHub extends Command $hubUrl = "https://hub.sp-tarkov.com/files/images/file/$hashShort/$fileID.$thumbnailExtension"; $relativePath = "mods/$thumbnailHash.$thumbnailExtension"; + $disk = match (config('app.env')) { + 'production' => 'r2', + default => 'local', + }; + // Check to make sure the image doesn't already exist. - if (Storage::exists($relativePath)) { + if (Storage::disk($disk)->exists($relativePath)) { return $relativePath; } @@ -363,7 +368,7 @@ class ImportHub extends Command if ($image === false) { $command->error('Error: '.curl_error($curl)); } else { - Storage::put($relativePath, $image); + Storage::disk($disk)->put($relativePath, $image); $command->info('Done.'); } diff --git a/composer.json b/composer.json index 2f9dd51..29d58e9 100644 --- a/composer.json +++ b/composer.json @@ -29,6 +29,7 @@ "fakerphp/faker": "^1.23", "larastan/larastan": "^2.9", "laravel/pint": "^1.16", + "laravel/sail": "^1.29", "mockery/mockery": "^1.6", "nunomaduro/collision": "^8.0", "phpunit/phpunit": "^11.0.1", diff --git a/composer.lock b/composer.lock index 3aebb50..29a9767 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "8c770bdae88add57a8001a1354d48f72", + "content-hash": "74acc57f3d0a3786094ce1d23349788a", "packages": [ { "name": "aws/aws-crt-php", @@ -8741,6 +8741,69 @@ }, "time": "2024-05-21T18:08:25+00:00" }, + { + "name": "laravel/sail", + "version": "v1.29.2", + "source": { + "type": "git", + "url": "https://github.com/laravel/sail.git", + "reference": "a8e4e749735ba2f091856eafeb3f99db8cd6b621" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laravel/sail/zipball/a8e4e749735ba2f091856eafeb3f99db8cd6b621", + "reference": "a8e4e749735ba2f091856eafeb3f99db8cd6b621", + "shasum": "" + }, + "require": { + "illuminate/console": "^9.52.16|^10.0|^11.0", + "illuminate/contracts": "^9.52.16|^10.0|^11.0", + "illuminate/support": "^9.52.16|^10.0|^11.0", + "php": "^8.0", + "symfony/console": "^6.0|^7.0", + "symfony/yaml": "^6.0|^7.0" + }, + "require-dev": { + "orchestra/testbench": "^7.0|^8.0|^9.0", + "phpstan/phpstan": "^1.10" + }, + "bin": [ + "bin/sail" + ], + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Laravel\\Sail\\SailServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Laravel\\Sail\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "Docker files for running a basic Laravel application.", + "keywords": [ + "docker", + "laravel" + ], + "support": { + "issues": "https://github.com/laravel/sail/issues", + "source": "https://github.com/laravel/sail" + }, + "time": "2024-05-16T21:39:11+00:00" + }, { "name": "maximebf/debugbar", "version": "v1.22.3", @@ -10965,6 +11028,77 @@ ], "time": "2024-05-02T13:42:49+00:00" }, + { + "name": "symfony/yaml", + "version": "v7.1.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/yaml.git", + "reference": "fa34c77015aa6720469db7003567b9f772492bf2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/yaml/zipball/fa34c77015aa6720469db7003567b9f772492bf2", + "reference": "fa34c77015aa6720469db7003567b9f772492bf2", + "shasum": "" + }, + "require": { + "php": ">=8.2", + "symfony/polyfill-ctype": "^1.8" + }, + "conflict": { + "symfony/console": "<6.4" + }, + "require-dev": { + "symfony/console": "^6.4|^7.0" + }, + "bin": [ + "Resources/bin/yaml-lint" + ], + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Yaml\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Loads and dumps YAML files", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/yaml/tree/v7.1.1" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-05-31T14:57:53+00:00" + }, { "name": "theseer/tokenizer", "version": "1.2.3", diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..da5e05c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,103 @@ +services: + laravel.test: + build: + context: ./vendor/laravel/sail/runtimes/8.3 + dockerfile: Dockerfile + args: + WWWGROUP: '${WWWGROUP}' + image: sail-8.3/app + extra_hosts: + - 'host.docker.internal:host-gateway' + ports: + - '${APP_PORT:-80}:80' + - '${VITE_PORT:-5173}:${VITE_PORT:-5173}' + environment: + WWWUSER: '${WWWUSER}' + LARAVEL_SAIL: 1 + XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}' + XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}' + IGNITION_LOCAL_SITES_PATH: '${PWD}' + volumes: + - '.:/var/www/html' + networks: + - sail + depends_on: + - mysql + - redis + - meilisearch + - mailpit + mysql: + image: 'mysql/mysql-server:8.0' + ports: + - '${FORWARD_DB_PORT:-3306}:3306' + environment: + MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}' + MYSQL_ROOT_HOST: '%' + MYSQL_DATABASE: '${DB_DATABASE}' + MYSQL_USER: '${DB_USERNAME}' + MYSQL_PASSWORD: '${DB_PASSWORD}' + MYSQL_ALLOW_EMPTY_PASSWORD: 1 + volumes: + - 'sail-mysql:/var/lib/mysql' + - './vendor/laravel/sail/database/mysql/create-testing-database.sh:/docker-entrypoint-initdb.d/10-create-testing-database.sh' + networks: + - sail + healthcheck: + test: + - CMD + - mysqladmin + - ping + - '-p${DB_PASSWORD}' + retries: 3 + timeout: 5s + redis: + image: 'redis:alpine' + ports: + - '${FORWARD_REDIS_PORT:-6379}:6379' + volumes: + - 'sail-redis:/data' + networks: + - sail + healthcheck: + test: + - CMD + - redis-cli + - ping + retries: 3 + timeout: 5s + meilisearch: + image: 'getmeili/meilisearch:latest' + ports: + - '${FORWARD_MEILISEARCH_PORT:-7700}:7700' + environment: + MEILI_NO_ANALYTICS: '${MEILISEARCH_NO_ANALYTICS:-false}' + volumes: + - 'sail-meilisearch:/meili_data' + networks: + - sail + healthcheck: + test: + - CMD + - wget + - '--no-verbose' + - '--spider' + - 'http://localhost:7700/health' + retries: 3 + timeout: 5s + mailpit: + image: 'axllent/mailpit:latest' + ports: + - '${FORWARD_MAILPIT_PORT:-1025}:1025' + - '${FORWARD_MAILPIT_DASHBOARD_PORT:-8025}:8025' + networks: + - sail +networks: + sail: + driver: bridge +volumes: + sail-mysql: + driver: local + sail-redis: + driver: local + sail-meilisearch: + driver: local diff --git a/phpunit.xml b/phpunit.xml index 4ba8235..c09b5bc 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -22,7 +22,7 @@ - +