Skip to content

Commit

Permalink
Some cleanup (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjustesen authored Sep 15, 2022
1 parent cc12e4c commit 86f2e84
Show file tree
Hide file tree
Showing 13 changed files with 145 additions and 262 deletions.
13 changes: 9 additions & 4 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
80 changes: 3 additions & 77 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
107 changes: 0 additions & 107 deletions app/Console/Commands/AppStartupCommand.php

This file was deleted.

89 changes: 89 additions & 0 deletions app/Console/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;

class InstallCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:install {--force}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'A fresh install of Speedtest Tracker.';

/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
if (! $this->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');
}
}
}
2 changes: 0 additions & 2 deletions app/Console/Commands/TestInfluxDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions app/Jobs/ExecSpeedtest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -26,7 +25,8 @@ class ExecSpeedtest implements ShouldQueue
public function __construct(
public array|null $speedtest = null,
public bool $scheduled = false
) {}
) {
}

/**
* Execute the job.
Expand Down Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion app/Jobs/SearchForSpeedtests.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion app/Observers/ResultObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading

0 comments on commit 86f2e84

Please sign in to comment.