From 17a36fd14b079301212d1b79d8c101ed0a99718d Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 9 Apr 2021 08:37:03 +1000 Subject: [PATCH 1/3] minor fixes --- app/Http/Controllers/SelfUpdateController.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/SelfUpdateController.php b/app/Http/Controllers/SelfUpdateController.php index 1d27e5d5d7..0f48d86bad 100644 --- a/app/Http/Controllers/SelfUpdateController.php +++ b/app/Http/Controllers/SelfUpdateController.php @@ -16,7 +16,6 @@ use Cz\Git\GitException; use Cz\Git\GitRepository; use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Support\Facades\Artisan; -use Illuminate\Support\Facades\Artisan; class SelfUpdateController extends BaseController { @@ -83,8 +82,8 @@ class SelfUpdateController extends BaseController Artisan::call('view:clear'); Artisan::call('config:clear'); - $output = $repo->execute('stash'); - $output = $repo->execute('reset hard origin/v5-stable'); + // $output = $repo->execute('stash'); + // $output = $repo->execute('reset --hard origin/v5-stable'); $output = $repo->execute('pull origin'); } catch (GitException $e) { From 469bf52467ab5d58c53bd36a0d3eca99cb558e29 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 9 Apr 2021 09:00:58 +1000 Subject: [PATCH 2/3] self updater --- composer.json | 5 +- composer.lock | 84 ++++++++++++++++++++++- config/ninja.php | 1 + config/self-update.php | 147 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 234 insertions(+), 3 deletions(-) create mode 100644 config/self-update.php diff --git a/composer.json b/composer.json index 85a2820370..07e68ad2ac 100644 --- a/composer.json +++ b/composer.json @@ -36,12 +36,12 @@ "checkout/checkout-sdk-php": "^1.0", "cleverit/ubl_invoice": "^1.3", "coconutcraig/laravel-postmark": "^2.10", + "codedge/laravel-selfupdater": "^3.2", "composer/composer": "^2", "czproject/git-php": "^3.17", - "turbo124/laravel-gmail": "^5", "doctrine/dbal": "^2.10", - "fideloper/proxy": "^4.2", "fakerphp/faker": "^1.14", + "fideloper/proxy": "^4.2", "google/apiclient": "^2.7", "guzzlehttp/guzzle": "^7.0.1", "hashids/hashids": "^4.0", @@ -67,6 +67,7 @@ "stripe/stripe-php": "^7.50", "symfony/http-client": "^5.2", "turbo124/beacon": "^1.0", + "turbo124/laravel-gmail": "^5", "webpatser/laravel-countries": "dev-master#75992ad", "wildbit/swiftmailer-postmark": "^3.3" }, diff --git a/composer.lock b/composer.lock index a665a1d18c..5b49aaf3fc 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": "64a35682f0e808b80b4784d812271f0b", + "content-hash": "c7966839cf1cb74e25348aff4acadb1c", "packages": [ { "name": "authorizenet/authorizenet", @@ -563,6 +563,88 @@ ], "time": "2021-02-24T13:45:30+00:00" }, + { + "name": "codedge/laravel-selfupdater", + "version": "3.2.2", + "source": { + "type": "git", + "url": "https://github.com/codedge/laravel-selfupdater.git", + "reference": "ade06363a1a8175adcf070f392f1fd25eef5c214" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/codedge/laravel-selfupdater/zipball/ade06363a1a8175adcf070f392f1fd25eef5c214", + "reference": "ade06363a1a8175adcf070f392f1fd25eef5c214", + "shasum": "" + }, + "require": { + "ext-json": "*", + "ext-zip": "*", + "guzzlehttp/guzzle": "6.* || 7.*", + "laravel/framework": "^8.33.1", + "php": "^7.3 || ^7.4 || ^8.0" + }, + "require-dev": { + "dg/bypass-finals": "^1.3", + "mikey179/vfsstream": "^1.6", + "mockery/mockery": "^1.4", + "orchestra/testbench": "^6.14.0", + "phpunit/phpunit": "^9.5.3" + }, + "type": "library", + "extra": { + "laravel": { + "aliases": { + "Updater": "Codedge\\Updater\\UpdaterFacade" + }, + "providers": [ + "Codedge\\Updater\\UpdaterServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Codedge\\Updater\\": "src/" + }, + "files": [ + "src/helpers.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Holger Lösken", + "email": "holger.loesken@codedge.de", + "homepage": "http://codedge.de", + "role": "Developer" + } + ], + "description": "Providing an auto-updating functionality for your self-hosted Laravel application.", + "keywords": [ + "auto update", + "auto-update", + "laravel", + "laravel application", + "self update", + "self-hosted laravel application", + "self-update", + "update" + ], + "support": { + "issues": "https://github.com/codedge/laravel-selfupdater/issues", + "source": "https://github.com/codedge/laravel-selfupdater" + }, + "funding": [ + { + "url": "https://github.com/codedge", + "type": "github" + } + ], + "time": "2021-03-20T09:31:26+00:00" + }, { "name": "composer/ca-bundle", "version": "1.2.9", diff --git a/config/ninja.php b/config/ninja.php index 35197d2027..c5c54a5a6b 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -15,6 +15,7 @@ return [ 'app_url' => rtrim(env('APP_URL', ''), '/'), 'app_domain' => env('APP_DOMAIN', ''), 'app_version' => '5.1.42', + 'app_tag' => 'v5.1.42', 'minimum_client_version' => '5.0.16', 'terms_version' => '1.0.1', 'api_secret' => env('API_SECRET', false), diff --git a/config/self-update.php b/config/self-update.php new file mode 100644 index 0000000000..3762d7babe --- /dev/null +++ b/config/self-update.php @@ -0,0 +1,147 @@ + env('SELF_UPDATER_SOURCE', 'github'), + + /* + |-------------------------------------------------------------------------- + | Version installed + |-------------------------------------------------------------------------- + | + | Set this to the version of your software installed on your system. + | + */ + + 'version_installed' => env('SELF_UPDATER_VERSION_INSTALLED', config('ninja.app_tag')), + + /* + |-------------------------------------------------------------------------- + | Repository types + |-------------------------------------------------------------------------- + | + | A repository can be of different types, which can be specified here. + | Current options: + | - github + | - http + | + */ + + 'repository_types' => [ + 'github' => [ + 'type' => 'github', + 'repository_vendor' => env('SELF_UPDATER_REPO_VENDOR', 'invoiceninja'), + 'repository_name' => env('SELF_UPDATER_REPO_NAME', 'invoiceninja'), + 'repository_url' => 'https://github.com/', + 'download_path' => env('SELF_UPDATER_DOWNLOAD_PATH', '/tmp'), + 'private_access_token' => env('SELF_UPDATER_GITHUB_PRIVATE_ACCESS_TOKEN', ''), + 'use_branch' => env('SELF_UPDATER_USE_BRANCH', 'v5-stable'), + ], + 'http' => [ + 'type' => 'http', + 'repository_url' => env('SELF_UPDATER_REPO_URL', ''), + 'pkg_filename_format' => env('SELF_UPDATER_PKG_FILENAME_FORMAT', 'v_VERSION_'), + 'download_path' => env('SELF_UPDATER_DOWNLOAD_PATH', '/tmp'), + 'private_access_token' => env('SELF_UPDATER_HTTP_PRIVATE_ACCESS_TOKEN', ''), + ], + ], + + /* + |-------------------------------------------------------------------------- + | Exclude folders from update + |-------------------------------------------------------------------------- + | + | Specific folders which should not be updated and will be skipped during the + | update process. + | + | Here's already a list of good examples to skip. You may want to keep those. + | + */ + + 'exclude_folders' => [ + '__MACOSX', + 'node_modules', + 'bootstrap/cache', + 'bower', + 'storage/app', + 'storage/framework', + 'storage/logs', + 'storage/self-update', + 'public/storage', + 'vendor', + ], + + /* + |-------------------------------------------------------------------------- + | Event Logging + |-------------------------------------------------------------------------- + | + | Configure if fired events should be logged + | + */ + + 'log_events' => env('SELF_UPDATER_LOG_EVENTS', false), + + /* + |-------------------------------------------------------------------------- + | Notifications + |-------------------------------------------------------------------------- + | + | Specify for which events you want to get notifications. Out of the box you can use 'mail'. + | + */ + + 'notifications' => [ + 'notifications' => [ + \Codedge\Updater\Notifications\Notifications\UpdateSucceeded::class => ['mail'], + \Codedge\Updater\Notifications\Notifications\UpdateFailed::class => ['mail'], + \Codedge\Updater\Notifications\Notifications\UpdateAvailable::class => ['mail'], + ], + + /* + * Here you can specify the notifiable to which the notifications should be sent. The default + * notifiable will use the variables specified in this config file. + */ + 'notifiable' => \Codedge\Updater\Notifications\Notifiable::class, + + 'mail' => [ + 'to' => [ + 'address' => env('SELF_UPDATER_MAILTO_ADDRESS', 'notifications@example.com'), + 'name' => env('SELF_UPDATER_MAILTO_NAME', ''), + ], + + 'from' => [ + 'address' => env('SELF_UPDATER_MAIL_FROM_ADDRESS', 'updater@example.com'), + 'name' => env('SELF_UPDATER_MAIL_FROM_NAME', 'Update'), + ], + ], + ], + + /* + |--------------------------------------------------------------------------- + | Register custom artisan commands + |--------------------------------------------------------------------------- + */ + + 'artisan_commands' => [ + 'pre_update' => [ + //'command:signature' => [ + // 'class' => Command class + // 'params' => [] + //] + ], + 'post_update' => [ + + ], + ], + +]; From a6e12ee95b76ee97d3c951bc478d37482731c9a6 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 9 Apr 2021 10:33:54 +1000 Subject: [PATCH 3/3] Working on new self updater --- app/Http/Controllers/SelfUpdateController.php | 65 ++++++++++++------- config/self-update.php | 2 +- 2 files changed, 43 insertions(+), 24 deletions(-) diff --git a/app/Http/Controllers/SelfUpdateController.php b/app/Http/Controllers/SelfUpdateController.php index 0f48d86bad..0acedf0791 100644 --- a/app/Http/Controllers/SelfUpdateController.php +++ b/app/Http/Controllers/SelfUpdateController.php @@ -68,34 +68,53 @@ class SelfUpdateController extends BaseController nlog('Are there changes to pull? '.$repo->hasChanges()); $output = ''; - try { - - $cacheCompiled = base_path('bootstrap/cache/compiled.php'); - if (file_exists($cacheCompiled)) { unlink ($cacheCompiled); } - $cacheServices = base_path('bootstrap/cache/services.php'); - if (file_exists($cacheServices)) { unlink ($cacheServices); } - Artisan::call('clear-compiled'); - Artisan::call('cache:clear'); - Artisan::call('debugbar:clear'); - Artisan::call('route:clear'); - Artisan::call('view:clear'); - Artisan::call('config:clear'); + $updater = new \Codedge\Updater\UpdaterManager() - // $output = $repo->execute('stash'); - // $output = $repo->execute('reset --hard origin/v5-stable'); - $output = $repo->execute('pull origin'); + // Check if new version is available + if($updater->source()->isNewVersionAvailable()) { - } catch (GitException $e) { - - nlog($output); - nlog($e->getMessage()); - return response()->json(['message'=>$e->getMessage()], 500); + // Get the current installed version + echo $updater->source()->getVersionInstalled(); + + // Get the new version available + $versionAvailable = $updater->source()->getVersionAvailable(); + + // Create a release + $release = $updater->source()->fetch($versionAvailable); + + // Run the update process + $updater->source()->update($release); } - dispatch(function () { - Artisan::call('ninja:post-update'); - }); + // try { + + // $cacheCompiled = base_path('bootstrap/cache/compiled.php'); + // if (file_exists($cacheCompiled)) { unlink ($cacheCompiled); } + // $cacheServices = base_path('bootstrap/cache/services.php'); + // if (file_exists($cacheServices)) { unlink ($cacheServices); } + + // Artisan::call('clear-compiled'); + // Artisan::call('cache:clear'); + // Artisan::call('debugbar:clear'); + // Artisan::call('route:clear'); + // Artisan::call('view:clear'); + // Artisan::call('config:clear'); + + // // $output = $repo->execute('stash'); + // // $output = $repo->execute('reset --hard origin/v5-stable'); + // $output = $repo->execute('pull origin'); + + // } catch (GitException $e) { + + // nlog($output); + // nlog($e->getMessage()); + // return response()->json(['message'=>$e->getMessage()], 500); + // } + + // dispatch(function () { + // Artisan::call('ninja:post-update'); + // }); return response()->json(['message' => $output], 200); } diff --git a/config/self-update.php b/config/self-update.php index 3762d7babe..844282b6f5 100644 --- a/config/self-update.php +++ b/config/self-update.php @@ -140,7 +140,7 @@ return [ //] ], 'post_update' => [ - + 'class' => \App\Console\Commands\PostUpdate::class ], ],