Skip to content

Commit

Permalink
Auto-update functionality #449 (#544)
Browse files Browse the repository at this point in the history
* Convert tar to zip file for updater

* Add update section to maintenance
  • Loading branch information
nabeelio authored Feb 10, 2020
1 parent 90e1b33 commit 6b79ad7
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 15 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ install:
- php --version
- mysql --version
- composer install --dev --no-interaction --verbose
- npm i tar-to-zip -g
- cp .travis/env.travis.php env.php
- cp .travis/phpunit.travis.xml phpunit.xml

Expand Down
12 changes: 2 additions & 10 deletions .travis/deploy_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,21 +109,13 @@ if [ "$TRAVIS" = "true" ]; then
cd /tmp
tar -czf $TAR_NAME -C $TRAVIS_BUILD_DIR/../ phpvms
sha256sum $TAR_NAME >"$TAR_NAME.sha256"

# Create zip https://stackoverflow.com/a/6301947
for f in *.tar.gz;\
do rm -rf ${f%.tar.gz} ;\
mkdir ${f%.tar.gz} ;\
tar -C ${f%.tar.gz} zxvf $f ;\
zip -r ${f%.tar.gz} $f.zip ;\
rm -rf ${f%.tar.gz} ;\
done
tar2zip $TAR_NAME

echo "Uploading to S3"
mkdir -p $TRAVIS_BUILD_DIR/build
cd $TRAVIS_BUILD_DIR/build

mv "/tmp/$TAR_NAME" "/tmp/$TAR_NAME.sha256" .
mv "/tmp/$TAR_NAME" "/tmp/$ZIP_NAME" "/tmp/$TAR_NAME.sha256" .
artifacts upload --target-paths "/" $TAR_NAME $TRAVIS_BUILD_DIR/VERSION $TAR_NAME.sha256

# Upload the version for a tagged release. Move to a version file in different
Expand Down
42 changes: 39 additions & 3 deletions app/Http/Controllers/Admin/MaintenanceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,37 @@
namespace App\Http\Controllers\Admin;

use App\Contracts\Controller;
use App\Repositories\KvpRepository;
use App\Services\CronService;
use Codedge\Updater\UpdaterManager;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Log;
use Laracasts\Flash\Flash;

class MaintenanceController extends Controller
{
private $cronSvc;
private $kvpRepo;
private $updateManager;

public function __construct(CronService $cronSvc)
{
public function __construct(
CronService $cronSvc,
KvpRepository $kvpRepo,
UpdaterManager $updateManager
) {
$this->cronSvc = $cronSvc;
$this->kvpRepo = $kvpRepo;
$this->updateManager = $updateManager;
}

public function index()
{
return view('admin.maintenance.index', [
'cron_path' => $this->cronSvc->getCronExecString(),
'cron_problem_exists' => $this->cronSvc->cronProblemExists(),
'new_version' => $this->kvpRepo->get('new_version_available', false),
'new_version_tag' => $this->kvpRepo->get('latest_version_tag'),
]);
}

Expand All @@ -30,7 +42,7 @@ public function index()
*
* @param \Illuminate\Http\Request $request
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
* @return mixed
*/
public function cache(Request $request)
{
Expand All @@ -57,4 +69,28 @@ public function cache(Request $request)
Flash::success('Cache cleared!');
return redirect(route('admin.maintenance.index'));
}

/**
* Update the phpVMS install
*
* @param \Illuminate\Http\Request $request
*
* @return mixed
*/
public function update(Request $request)
{
$new_version_avail = $this->kvpRepo->get('new_version_available', false);
if (!$new_version_avail) {
Flash::error('A newer version is not available!');
return redirect(route('admin.maintenance.index'));
}

$new_version_tag = $this->kvpRepo->get('latest_version_tag');
Log::info('Attempting to update to '.$new_version_tag);

$this->updateManager->source()->update($new_version_tag);

Flash::success('phpVMS was updated!');
return redirect(route('/update'));
}
}
6 changes: 5 additions & 1 deletion app/Http/Routes/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,14 @@ static function () {
->name('maintenance.index')
->middleware('ability:admin,maintenance');

Route::match(['post'], 'maintenance', 'MaintenanceController@cache')
Route::match(['post'], 'maintenance/cache', 'MaintenanceController@cache')
->name('maintenance.cache')
->middleware('ability:admin,maintenance');

Route::match(['post'], 'maintenance/update', 'MaintenanceController@update')
->name('maintenance.update')
->middleware('ability:admin,maintenance');

// subfleet
Route::get('subfleets/export', 'SubfleetController@export')
->name('subfleets.export')
Expand Down
2 changes: 1 addition & 1 deletion config/self-update.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
'http' => [
'type' => 'http',
'repository_url' => 'http://downloads.phpvms.net',
'pkg_filename_format' => 'phpvms-v_VERSION_.zip',
'pkg_filename_format' => 'phpvms-_VERSION_.zip',
'download_path' => env('SELF_UPDATER_DOWNLOAD_PATH', '/tmp'),
'private_access_token' => env('SELF_UPDATER_HTTP_PRIVATE_ACCESS_TOKEN', ''),
],
Expand Down
6 changes: 6 additions & 0 deletions resources/views/admin/maintenance/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
@section('content')
@include('flash::message')

<div class="card border-blue-bottom">
<div class="content">
@include('admin.maintenance.update')
</div>
</div>

<div class="card border-blue-bottom">
<div class="content">
@include('admin.maintenance.cron')
Expand Down
22 changes: 22 additions & 0 deletions resources/views/admin/maintenance/update.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<div class="row">
<div class="col-sm-12">
<div class="form-container">
<h6><i class="fas fa-clock"></i>
&nbsp;Update
</h6>
<div class="row" style="padding-top: 5px">
<div class="col-sm-12">

@if ($new_version)
<p>An update to version {{ $new_version_tag }} is available.</p>
{{ Form::open(['route' => 'admin.maintenance.update']) }}
{{ Form::button('Update', ['type' => 'submit', 'class' => 'btn btn-success']) }}
{{ Form::close() }}
@else
<p>There is no new version available</p>
@endif
</div>
</div>
</div>
</div>
</div>

0 comments on commit 6b79ad7

Please sign in to comment.