diff --git a/.dockerignore b/.dockerignore index 554ebe677..9bb4e8d66 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,17 +1,22 @@ +/.idea +/.vscode +/docker/8.1 /node_modules /public/build /public/hot /public/storage /storage/*.key +/storage/logs /vendor -config.yml +_ide_helper.php .env .env.backup +.phpstorm.meta.php .phpunit.result.cache +config.yml +auth.json +docker-compose.yml Homestead.json Homestead.yaml -auth.json npm-debug.log yarn-error.log -/.idea -/.vscode diff --git a/.env.example b/.env.example index 706601af4..b60a7b300 100644 --- a/.env.example +++ b/.env.example @@ -18,7 +18,7 @@ DB_PASSWORD= BROADCAST_DRIVER=log CACHE_DRIVER=file FILESYSTEM_DISK=local -QUEUE_CONNECTION=sync +QUEUE_CONNECTION=database SESSION_DRIVER=file SESSION_LIFETIME=120 diff --git a/README.md b/README.md index 9253d21e5..b5f304bed 100644 --- a/README.md +++ b/README.md @@ -4,82 +4,8 @@ Welcome to Speedtest Tracker! Speedtest Tracker runs a speedtest check against O This project replaces https://github.com/henrywhitaker3/Speedtest-Tracker as it looks like this project has been abandoned https://github.com/henrywhitaker3/Speedtest-Tracker/issues/1013. +### Docs +The docs can be found here https://docs.speedtest-tracker.dev to help you get started. + ### Roadmap To suggest features please use the roadmap. You can also follow development progress there as well: https://speedtest-tracker-roadmap.alexjustesen.dev/ - - -### Deployment - -#### Docker w/ sqlite -```bash -docker run -itd --name speedtest-tracker \ - -p 8080:80 \ - -e "PHP_POOL_NAME=speedtest-tracker_php" \ - -e "DB_CONNECTION=sqlite" \ - -e "DB_DATABASE=/app/database.sqlite" \ - -v speedtest-tracker_app:/app \ - speedtest-tracker -``` - -#### Docker w/ MariaDB or MySQL -```bash -docker run -itd --name speedtest-tracker \ - -p 8080:80 \ - -e "PHP_POOL_NAME=speedtest-tracker_php" \ - -e "DB_CONNECTION=mysql" \ - -e "DB_HOST=mysql" \ - -e "DB_PORT=3306" \ - -e "DB_DATABASE=speedtest_tracker" \ - -e "DB_USERNAME=" \ - -e "DB_PASSWORD=" \ - speedtest-tracker -``` - -#### Docker Compose -```bash -# tbd... -``` - - -### Build Docker Image -Want to build the image locally? Cool, just clone the repo and go right ahead... - -```bash -docker build . -t speedtest-tracker -``` - -#### Runing the docker image -```bash -docker run -it -p 8080:80 \ - speedtest-tracker -``` - -### Development - -Since this project uses Laravel as our framework of choice we can take advantage of [Laravel Sail](https://laravel.com/docs/9.x/sail) for a development environment. - -#### Clone the repo - -```bash -gh repo clone alexjustesen/speedtest-tracker \ - && cd speedtest-tracker \ - && cp .env.example .env -``` - -#### Install composer dependencies -```bash -docker run --rm \ - -u "$(id -u):$(id -g)" \ - -v $(pwd):/var/www/html \ - -w /var/www/html \ - laravelsail/php81-composer:latest \ - composer install --ignore-platform-reqs -``` - -#### Start sail -```bash -./vendor/bin/sail up -d - -# or, if you have the sail bash alias -sail up -d -``` diff --git a/app/Console/Commands/AppStartupCommand.php b/app/Console/Commands/AppStartupCommand.php deleted file mode 100644 index 62948961e..000000000 --- a/app/Console/Commands/AppStartupCommand.php +++ /dev/null @@ -1,107 +0,0 @@ -info('🐇 Starting up Speedtest Tracker...'); - $this->newLine(); - - $this->clearAppCache(); - - // $this->checkAppKey(); - - // $this->checkAppDatabase(); - - // $this->migrateDatabase(); - - $this->line('🚀 Speedtest Tracker is ready to roll!'); - - return 0; - } - - private function checkAppDatabase() - { - if (! Storage::exists('database.sqlite')) { - $this->line('🙄 Database not found, creating a new one...'); - - $process = new Process(['touch', 'storage/app/database.sqlite']); - $process->run(); - - if (! Storage::exists('database.sqlite')) { - $this->error('❌ There was an issue creating the database, check the logs'); - } - - $this->line('✅ done'); - $this->newLine(); - } - } - - private function checkAppKey() - { - if (blank(config('app.key'))) { - $this->line('🔑 Generating a key...'); - - Artisan::call('key:generate'); - - $this->line('✅ done'); - $this->newLine(); - } - } - - private function clearAppCache() - { - $this->line('💵 Clearing the cache...'); - - Artisan::call('optimize'); - - $this->line('✅ done'); - $this->newLine(); - } - - private function migrateDatabase() - { - $this->line('⏳ Migrating the database...'); - - try { - Artisan::call('migrate', [ - '--database' => 'sqlite', - '--force' => true, - ]); - } catch (\Throwable $th) { - $this->error('❌ There was an issue migrating the database, check the logs'); - - Log::info($th); - } - - $this->line('✅ done'); - $this->newLine(); - } -} diff --git a/app/Console/Commands/InstallCommand.php b/app/Console/Commands/InstallCommand.php new file mode 100644 index 000000000..69e53edda --- /dev/null +++ b/app/Console/Commands/InstallCommand.php @@ -0,0 +1,89 @@ +option('force')) { + $this->newLine(2); + + $this->info("Running the install will reset all of the application's data."); + $this->warn('!!! ALL OF THE DATA WILL BE DELETED !!!'); + + if (! $this->confirm('Do you wish to continue?')) { + $this->info('Install cancelled.'); + + return 0; + } + } + + $this->info('Starting to install the application...'); + + $this->newLine(); + + $this->checkAppKey(); + + $this->line('⏳ Optimizing the cache'); + + Artisan::call('optimize:clear'); + + $this->line('✅ Optimized cache'); + + $this->newLine(); + + $this->line('⏳ Migrating the database'); + + try { + Artisan::call('migrate:fresh', [ + '--force' => true, + ]); + } catch (\Throwable $th) { + $this->error('❌ There was an issue migrating the database, check the logs.'); + + return 0; + } + + $this->line('✅ Database migrated'); + + $this->newLine(); + + $this->line('🚀 Finished installing the application!'); + + return 0; + } + + public function checkAppKey() + { + if (empty(config('app.key'))) { + $this->line('🔑 Creating an application key'); + + Artisan::call('key:generate'); + + $this->line('✅ Application key created'); + } + } +} diff --git a/app/Console/Commands/TestInfluxDB.php b/app/Console/Commands/TestInfluxDB.php index 4539472b5..f89bbd06f 100644 --- a/app/Console/Commands/TestInfluxDB.php +++ b/app/Console/Commands/TestInfluxDB.php @@ -5,8 +5,6 @@ use App\Models\Result; use Illuminate\Console\Command; use Illuminate\Support\Facades\File; -use Illuminate\Support\Facades\Log; -use InfluxDB2\Client; use Symfony\Component\Yaml\Yaml; class TestInfluxDB extends Command diff --git a/app/Jobs/ExecSpeedtest.php b/app/Jobs/ExecSpeedtest.php index 43e1b10a6..42517f135 100644 --- a/app/Jobs/ExecSpeedtest.php +++ b/app/Jobs/ExecSpeedtest.php @@ -3,7 +3,6 @@ namespace App\Jobs; use App\Models\Result; -use App\Models\Speedtest; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldBeUnique; use Illuminate\Contracts\Queue\ShouldQueue; @@ -14,7 +13,7 @@ use Symfony\Component\Process\Exception\ProcessFailedException; use Symfony\Component\Process\Process; -class ExecSpeedtest implements ShouldQueue +class ExecSpeedtest implements ShouldQueue, ShouldBeUnique { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; @@ -26,7 +25,8 @@ class ExecSpeedtest implements ShouldQueue public function __construct( public array|null $speedtest = null, public bool $scheduled = false - ) {} + ) { + } /** * Execute the job. @@ -66,7 +66,7 @@ public function handle() 'upload' => $results['upload']['bandwidth'], 'server_id' => $results['server']['id'], 'server_name' => $results['server']['name'], - 'server_host' => $results['server']['host'] . ':' . $results['server']['port'], + 'server_host' => $results['server']['host'].':'.$results['server']['port'], 'url' => $results['result']['url'], 'scheduled' => $this->scheduled, 'data' => $output, diff --git a/app/Jobs/SearchForSpeedtests.php b/app/Jobs/SearchForSpeedtests.php index 07b42b67e..1a99da0b9 100644 --- a/app/Jobs/SearchForSpeedtests.php +++ b/app/Jobs/SearchForSpeedtests.php @@ -4,7 +4,6 @@ use Cron\CronExpression; use Illuminate\Bus\Queueable; -use Illuminate\Contracts\Queue\ShouldBeUnique; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; diff --git a/app/Observers/ResultObserver.php b/app/Observers/ResultObserver.php index 4425cf90e..0089a3182 100644 --- a/app/Observers/ResultObserver.php +++ b/app/Observers/ResultObserver.php @@ -43,7 +43,7 @@ public function created(Result $result) 'token' => $influxdb['token'], 'bucket' => $influxdb['bucket'], 'org' => $influxdb['org'], - 'precision' => \InfluxDB2\Model\WritePrecision::S + 'precision' => \InfluxDB2\Model\WritePrecision::S, ]); $writeApi = $client->createWriteApi(); diff --git a/composer.json b/composer.json index 8e102f6b1..faa3173ca 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "require-dev": { "barryvdh/laravel-ide-helper": "^2.12", "fakerphp/faker": "^1.9.1", - "laravel/pint": "^1.0", + "laravel/pint": "^1.2", "laravel/sail": "^1.0.1", "mockery/mockery": "^1.4.4", "nunomaduro/collision": "^6.1", diff --git a/composer.lock b/composer.lock index 57e15107a..7c0f31ee6 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": "d798083a208f71973c614fc10123d8e3", + "content-hash": "f550c556e10dbbdf735af2ed87ea772e", "packages": [ { "name": "brick/math", @@ -6137,16 +6137,16 @@ }, { "name": "laravel/pint", - "version": "v1.1.3", + "version": "v1.2.0", "source": { "type": "git", "url": "https://github.com/laravel/pint.git", - "reference": "9fb8e93074de3c04a0975beb90dcb38562afbdaa" + "reference": "1d276e4c803397a26cc337df908f55c2a4e90d86" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/pint/zipball/9fb8e93074de3c04a0975beb90dcb38562afbdaa", - "reference": "9fb8e93074de3c04a0975beb90dcb38562afbdaa", + "url": "https://api.github.com/repos/laravel/pint/zipball/1d276e4c803397a26cc337df908f55c2a4e90d86", + "reference": "1d276e4c803397a26cc337df908f55c2a4e90d86", "shasum": "" }, "require": { @@ -6199,7 +6199,7 @@ "issues": "https://github.com/laravel/pint/issues", "source": "https://github.com/laravel/pint" }, - "time": "2022-09-06T16:01:44+00:00" + "time": "2022-09-13T15:07:15+00:00" }, { "name": "laravel/sail", diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml deleted file mode 100644 index 8dfcd4821..000000000 --- a/docker-compose.prod.yml +++ /dev/null @@ -1,33 +0,0 @@ -version: '3' -services: - php: - image: speedtest-tracker:latest - environment: - PHP_POOL_NAME: "speedtest-tracker_php" - ports: - - '8080:80' - restart: unless-stopped - volumes: - - 'speedtest-tracker-app:/data' - - # task: - # image: speedtest-tracker:latest - # command: [ "su", "webuser", "-c", "php artisan schedule:work" ] - # environment: - # PHP_POOL_NAME: "speedtest-tracker_task" - # restart: unless-stopped - # depends_on: - # - php - - # queue: - # image: speedtest-tracker:latest - # command: ["su", "webuser", "-c", "php artisan queue:work --tries=3"] - # environment: - # PHP_POOL_NAME: "speedtest-tracker_queue" - # restart: unless-stopped - # depends_on: - # - php - -# volumes: - speedtest-tracker-app: - driver: local diff --git a/docker-compose.yml b/docker-compose.yml index a05885993..9e371769e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -22,31 +22,37 @@ services: - '.:/var/www/html' networks: - sail - # depends_on: - # - mysql - # 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 + depends_on: + - pgsql + - mailhog + pgsql: + image: 'postgres:14' + ports: + - '${FORWARD_DB_PORT:-5432}:5432' + environment: + PGPASSWORD: '${DB_PASSWORD:-secret}' + POSTGRES_DB: '${DB_DATABASE}' + POSTGRES_USER: '${DB_USERNAME}' + POSTGRES_PASSWORD: '${DB_PASSWORD:-secret}' + volumes: + - 'sail-pgsql:/var/lib/postgresql/data' + - './vendor/laravel/sail/database/pgsql/create-testing-database.sql:/docker-entrypoint-initdb.d/10-create-testing-database.sql' + networks: + - sail + healthcheck: + test: ["CMD", "pg_isready", "-q", "-d", "${DB_DATABASE}", "-U", "${DB_USERNAME}"] + retries: 3 + timeout: 5s + mailhog: + image: 'mailhog/mailhog:latest' + ports: + - '${FORWARD_MAILHOG_PORT:-1025}:1025' + - '${FORWARD_MAILHOG_DASHBOARD_PORT:-8025}:8025' + networks: + - sail networks: sail: driver: bridge -# volumes: -# sail-mysql: -# driver: local +volumes: + sail-pgsql: + driver: local