From 004a6b34d4eada8238c577662eab2b78783edd2a Mon Sep 17 00:00:00 2001 From: Henry Whitaker Date: Mon, 3 Aug 2020 10:42:38 +0100 Subject: [PATCH 1/3] Added home prefixes to helpers --- .gitignore | 1 + README.md | 2 +- app/Console/Commands/AcceptEULACommand.php | 43 ++++++++++++++++++++++ app/Helpers/SpeedtestHelper.php | 7 +++- changelog.json | 6 +++ config/speedtest.php | 2 +- 6 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 app/Console/Commands/AcceptEULACommand.php diff --git a/.gitignore b/.gitignore index e1e16b37..cd67c07b 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ yarn-error.log _ide_helper.php .idea +.config diff --git a/README.md b/README.md index cf9ce0d1..0f666c98 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Speedtest Tracker -[![Docker pulls](https://img.shields.io/docker/pulls/henrywhitaker3/speedtest-tracker?style=flat-square)](https://hub.docker.com/r/henrywhitaker3/speedtest-tracker) [![last_commit](https://img.shields.io/github/last-commit/henrywhitaker3/Speedtest-Tracker?style=flat-square)](https://github.com/henrywhitaker3/Speedtest-Tracker/commits) [![issues](https://img.shields.io/github/issues/henrywhitaker3/Speedtest-Tracker?style=flat-square)](https://github.com/henrywhitaker3/Speedtest-Tracker/issues) [![commit_freq](https://img.shields.io/github/commit-activity/m/henrywhitaker3/Speedtest-Tracker?style=flat-square)](https://github.com/henrywhitaker3/Speedtest-Tracker/commits) ![version](https://img.shields.io/badge/version-v1.7.14-success?style=flat-square) [![license](https://img.shields.io/github/license/henrywhitaker3/Speedtest-Tracker?style=flat-square)](https://github.com/henrywhitaker3/Speedtest-Tracker/blob/master/LICENSE) +[![Docker pulls](https://img.shields.io/docker/pulls/henrywhitaker3/speedtest-tracker?style=flat-square)](https://hub.docker.com/r/henrywhitaker3/speedtest-tracker) [![last_commit](https://img.shields.io/github/last-commit/henrywhitaker3/Speedtest-Tracker?style=flat-square)](https://github.com/henrywhitaker3/Speedtest-Tracker/commits) [![issues](https://img.shields.io/github/issues/henrywhitaker3/Speedtest-Tracker?style=flat-square)](https://github.com/henrywhitaker3/Speedtest-Tracker/issues) [![commit_freq](https://img.shields.io/github/commit-activity/m/henrywhitaker3/Speedtest-Tracker?style=flat-square)](https://github.com/henrywhitaker3/Speedtest-Tracker/commits) ![version](https://img.shields.io/badge/version-v1.7.15-success?style=flat-square) [![license](https://img.shields.io/github/license/henrywhitaker3/Speedtest-Tracker?style=flat-square)](https://github.com/henrywhitaker3/Speedtest-Tracker/blob/master/LICENSE) This program runs a speedtest check every hour and graphs the results. The back-end is written in [Laravel](https://laravel.com/) and the front-end uses [React](https://reactjs.org/). It uses the [Ookla's speedtest cli](https://www.speedtest.net/apps/cli) package to get the data and uses [Chart.js](https://www.chartjs.org/) to plot the results. diff --git a/app/Console/Commands/AcceptEULACommand.php b/app/Console/Commands/AcceptEULACommand.php new file mode 100644 index 00000000..6cfd459d --- /dev/null +++ b/app/Console/Commands/AcceptEULACommand.php @@ -0,0 +1,43 @@ + '1.7.14', + 'version' => '1.7.15', /* |-------------------------------------------------------------------------- From 538305470d5e2ea55311f7758590f1471da73e64 Mon Sep 17 00:00:00 2001 From: Henry Whitaker Date: Mon, 3 Aug 2020 11:14:22 +0100 Subject: [PATCH 2/3] Updated README.md --- README.md | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 0f666c98..05b9872b 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,8 @@ docker create \ ### Using Docker Compose ```yml +version: '3.3' +services: speedtest: container_name: speedtest image: henrywhitaker3/speedtest-tracker:dev @@ -53,10 +55,10 @@ docker create \ - BASE_PATH=/speedtest - OOKLA_EULA_GDPR=true logging: - driver: json-file + driver: "json-file" options: - max-file: 10 - max-size: 200k + max-file: "10" + max-size: "200k" restart: unless-stopped ``` @@ -83,8 +85,7 @@ This program has some dependencies, to install them you need to run the followin ```bash sudo apt update -sudo apt update -sudo apt install php-common php7.2 php7.2-cli php7.2-common php7.2-json php7.2-opcache php7.2-readline php-xml php-sqlite3 php-zip php-mbstring composer python3 python3-pip git +sudo apt install php-common php7.3 php7.3-cli php7.3-common php7.3-json php7.3-opcache php7.3-readline php-xml php-sqlite3 php-zip php-mbstring composer python3 python3-pip git ``` ```bash sudo apt install curl @@ -92,16 +93,20 @@ curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash - sudo apt install nodejs ``` -```bash -sudo pip3 install speedtest-cli -``` - Then, download the code by running: ```bash git clone https://github.com/henrywhitaker3/Speedtest-Tracker.git ``` +Now you need to download Ookla's speedtest binary for your system from [here](https://www.speedtest.net/apps/cli). For a x86_64 system: + +```bash +wget https://bintray.com/ookla/download/download_file?file_path=ookla-speedtest-1.0.0-x86_64-linux.tgz -O speedtest.tgz +tar zxvf speedtest.tgz +mv speedtest Speedtest-Tracker/app/Bin/ +``` + Install the composer and npm dependencies: ```bash @@ -126,6 +131,12 @@ php artisan key:generate php artisan migrate ``` +Now you need to accept Ookla's EULA by running: + +```bash +php artisan speedtest:eula +``` + Now run the following to make sure everything has been setup properly (it should output a speedtest result): ```bash @@ -159,7 +170,7 @@ command=php /path/to/project/artisan queue:work autostart=true autorestart=true user= -numprocs=8 +numprocs=1 redirect_stderr=true ``` From be5d1fa2ef113f67c511f944f7b88a1468eb138a Mon Sep 17 00:00:00 2001 From: Henry Whitaker Date: Mon, 3 Aug 2020 11:46:03 +0100 Subject: [PATCH 3/3] Updated HOME prefix --- README.md | 119 ++------------------- app/Console/Commands/AcceptEULACommand.php | 2 +- app/Helpers/SpeedtestHelper.php | 2 +- config/speedtest.php | 16 +++ 4 files changed, 29 insertions(+), 110 deletions(-) diff --git a/README.md b/README.md index 05b9872b..0fe40b02 100644 --- a/README.md +++ b/README.md @@ -27,9 +27,6 @@ docker create \ --name=speedtest \ -p 8765:80 \ -v /path/to/data:/config \ - -e SLACK_WEBHOOK=webhook `#optional` \ - -e PUID=uid `#optional` \ - -e PGID=gid `#optional` \ -e OOKLA_EULA_GDPR=true \ --restart unless-stopped \ henrywhitaker3/speedtest-tracker @@ -42,7 +39,7 @@ version: '3.3' services: speedtest: container_name: speedtest - image: henrywhitaker3/speedtest-tracker:dev + image: henrywhitaker3/speedtest-tracker ports: - 8765:80 volumes: @@ -51,8 +48,6 @@ services: - TZ= - PGID= - PUID= - - SLACK_WEBHOOK= - - BASE_PATH=/speedtest - OOKLA_EULA_GDPR=true logging: driver: "json-file" @@ -62,6 +57,15 @@ services: restart: unless-stopped ``` +#### Images + +There are 2 different docker images: + +| Tag | Description | +| :----: | --- | +| latest | This is the stable release of the app | +| dev | This release has more features, although could have some bugs | + #### Parameters Container images are configured using parameters passed at runtime (such as those above). These parameters are separated by a colon and indicate `:` respectively. For example, `-p 8080:80` would expose port `80` from inside the container to be accessible from the host's IP on port `8080` outside the container. @@ -79,105 +83,4 @@ Container images are configured using parameters passed at runtime (such as thos ### Manual Install -#### Installing Dependencies - -This program has some dependencies, to install them you need to run the following: - -```bash -sudo apt update -sudo apt install php-common php7.3 php7.3-cli php7.3-common php7.3-json php7.3-opcache php7.3-readline php-xml php-sqlite3 php-zip php-mbstring composer python3 python3-pip git -``` -```bash -sudo apt install curl -curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash - -sudo apt install nodejs -``` - -Then, download the code by running: - -```bash -git clone https://github.com/henrywhitaker3/Speedtest-Tracker.git -``` - -Now you need to download Ookla's speedtest binary for your system from [here](https://www.speedtest.net/apps/cli). For a x86_64 system: - -```bash -wget https://bintray.com/ookla/download/download_file?file_path=ookla-speedtest-1.0.0-x86_64-linux.tgz -O speedtest.tgz -tar zxvf speedtest.tgz -mv speedtest Speedtest-Tracker/app/Bin/ -``` - -Install the composer and npm dependencies: - -```bash -composer install -npm install && npm run production -``` - -#### Setting up the database - -Run the following to set your database variables: - -```bash -cp .env.example .env -``` - -Then update the `DB_DATABASE` value with the absolute path of your install, followed by `/database/speed.db`. - -Finally, run the following to setup the tables in the database: - -```bash -php artisan key:generate -php artisan migrate -``` - -Now you need to accept Ookla's EULA by running: - -```bash -php artisan speedtest:eula -``` - -Now run the following to make sure everything has been setup properly (it should output a speedtest result): - -```bash -php artisan speedtest:run -``` - -#### Scheduling Setup - -To get speed test results every hour, you need to add a cronjob, run `sudo crontab -e` and add an entry with the following (with the path you your install): - -```bash -* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1 -``` - -#### Queue Setup - -```bash -sudo apt install supervisor -``` - -```bash -sudo vim /etc/supervisor/conf.d/laravel-worker.conf -``` - -Add the following, updating the `command` and user `values`: - -```bash -[program:laravel-worker] -process_name=%(program_name)s_%(process_num)02d -command=php /path/to/project/artisan queue:work -autostart=true -autorestart=true -user= -numprocs=1 -redirect_stderr=true -``` - -Then run: - -```bash -sudo supervisorctl reread -sudo supervisorctl update -sudo supervisorctl restart all -``` +For manual installtions, please follow the instrucitons [here](https://github.com/henrywhitaker3/Speedtest-Tracker/wiki/Manual-Installation). diff --git a/app/Console/Commands/AcceptEULACommand.php b/app/Console/Commands/AcceptEULACommand.php index 6cfd459d..76d0fb6d 100644 --- a/app/Console/Commands/AcceptEULACommand.php +++ b/app/Console/Commands/AcceptEULACommand.php @@ -38,6 +38,6 @@ class AcceptEULACommand extends Command */ public function handle() { - shell_exec('HOME=' . base_path() . '/ && ' . app_path() . '/Bin/speedtest --accept-license --accept-gdpr'); + shell_exec(config('speedtest.home') . ' && ' . app_path() . '/Bin/speedtest --accept-license --accept-gdpr'); } } diff --git a/app/Helpers/SpeedtestHelper.php b/app/Helpers/SpeedtestHelper.php index 01b999c0..4793b990 100644 --- a/app/Helpers/SpeedtestHelper.php +++ b/app/Helpers/SpeedtestHelper.php @@ -80,7 +80,7 @@ class SpeedtestHelper { $server = SettingsHelper::get('server')['value']; $binPath = app_path() . DIRECTORY_SEPARATOR . 'Bin' . DIRECTORY_SEPARATOR . 'speedtest'; - $homePrefix = 'HOME=' . base_path() . '/ && '; + $homePrefix = config('speedtest.home') . ' && '; if($server != '' && $server != false) { $server = explode(',', $server); diff --git a/config/speedtest.php b/config/speedtest.php index 944b772b..0c698097 100644 --- a/config/speedtest.php +++ b/config/speedtest.php @@ -9,6 +9,22 @@ return [ 'version' => '1.7.15', + /* + |-------------------------------------------------------------------------- + | Installation type + |-------------------------------------------------------------------------- + */ + + 'install' => 'manual', + + /* + |-------------------------------------------------------------------------- + | Path for HOME variable + |-------------------------------------------------------------------------- + */ + + 'home' => 'HOME=' . base_path() . DIRECTORY_SEPARATOR, + /* |-------------------------------------------------------------------------- | GitHub Repo Variables