GithubHelp home page GithubHelp logo

codedge / laravel-selfupdater Goto Github PK

View Code? Open in Web Editor NEW
389.0 8.0 79.0 721 KB

This package provides some basic methods to implement a self updating functionality for your Laravel application. Already bundled are some methods to provide a self-update mechanism via Github or some private repository via http.

License: MIT License

PHP 99.94% Blade 0.06%
laravel updater self-updater php laravel-selfupdater laravel-package

laravel-selfupdater's Introduction

Laravel Application Self-Updater

Latest Stable Version Total Downloads StyleCI Codacy Badge codecov

This package provides some basic methods to implement a self updating functionality for your Laravel application.

Supported update provider:

  • GitHub
  • Gitlab
  • Gitea
  • Http-based archives

Usually you need this when distributing a self-hosted Laravel application that needs some updating mechanism without Composer.

Install

To install the latest version from the master using Composer:

$ composer require codedge/laravel-selfupdater

Configuration

After installing the package you need to publish the configuration file via

$ php artisan vendor:publish --provider="Codedge\Updater\UpdaterServiceProvider"

Note: Please enter correct value for vendor and repository name in your config/self-updater.php if you want to use Github as source for your updates.

Setting the currently installed version

Before starting an update, make sure to set the version installed correctly. You're responsible to set the current version installed, either in the config file or better via the env variable SELF_UPDATER_VERSION_INSTALLED.

tag-based updates

Set the installed version to one of the tags set for a release.

branch-based updates

Set the installed version to a datetime of one of the latest commits.
A valid version would be: 2020-04-19T22:35:48Z

Running artisan commands

Artisan commands can be run before or after the update process and can be configured in config/self-updater.php:

Example:

'artisan_commands' => [
    'pre_update' => [
        'updater:prepare' => [
            'class' => \App\Console\Commands\PreUpdateTasks::class,
            'params' => []
        ],
    ],
    'post_update' => [
        'postupdate:cleanup' => [
            'class' => \App\Console\Commands\PostUpdateCleanup::class,
            'params' => [
                'log' => 1,
                'reset' => false,
                // etc.
            ]
        ]
    ]
]

Configure the download path

Sometimes your web host does not allow saving files into the /tmp folder of the server. You can change the folder the application is downloaded to by setting the env var SELF_UPDATER_DOWNLOAD_PATH to something different. Just keep in mind, that the folder is not inside the folder your application lives in as it might be overwritten during the update.

Notifications via email

You need to specify a recipient email address and a recipient name to receive update available notifications. You can specify these values by adding SELF_UPDATER_MAILTO_NAME and SELF_UPDATER_MAILTO_ADDRESS to your .env file.

Config name Description
SELF_UPDATER_MAILTO_NAME Name of email recipient
SELF_UPDATER_MAILTO_ADDRESS Address of email recipient
SELF_UPDATER_MAILTO_UPDATE_AVAILABLE_SUBJECT Subject of update available email
SELF_UPDATER_MAILTO_UPDATE_SUCCEEDED_SUBJECT Subject of update succeeded email

Private repositories

Private repositories can be accessed via (Bearer) tokens. Each repository inside the config file should have a private_access_token field, where you can set the token.

ℹ Do not prefix the token with Bearer . This is done automatically.

Usage

To start an update process, i. e. in a controller, just use:

Route::get('/', function (\Codedge\Updater\UpdaterManager $updater) {

    // Check if new version is available
    if($updater->source()->isNewVersionAvailable()) {

        // 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);

    } else {
        echo "No new version available.";
    }

});

Currently, the fetching of the source is a synchronous process. It is not run in background.

Using GitHub

The package comes with a GitHub source repository type to fetch releases from GitHub - basically use GitHub to pull the latest version of your software.

Just make sure you set the proper repository in your config/self-updater.php file.

Tag-based updates

This is the default. Updates will be fetched by using a tagged commit, aka release.

Branch-based updates

Select the branch that should be used via the use_branch setting inside the configuration.

// ...
'repository_types' => [
    'github' => [
        'type' => 'github',
        'repository_vendor' => env('SELF_UPDATER_REPO_VENDOR', ''),
        'repository_name' => env('SELF_UPDATER_REPO_NAME', ''),
        // ...
        'use_branch' => 'v2',
   ],
   // ...
];

Using Gitlab

Configure Gitlab either via the config/self-updater.php or use the appropriate environment variables.

// ...
'repository_types' => [
    'gitlab' => [
            'base_url'             => '',
            'type'                 => 'gitlab',
            'repository_id'        => env('SELF_UPDATER_REPO_URL', ''),
            'download_path'        => env('SELF_UPDATER_DOWNLOAD_PATH', '/tmp'),
            'private_access_token' => env('SELF_UPDATER_GITLAB_PRIVATE_ACCESS_TOKEN', ''),
   ],
   // ...
];

ℹ Although the environment variable is named SELF_UPDATER_REPO_URL, only specify your repository id.

For self-hosted Gitlab instances you can set the base_url variable to a domain where the instance is hosted at, f. ex. http://gitlab.acme.local.

Using HTTP archives

The package comes with an HTTP source repository type to fetch releases from an HTTP directory listing containing zip archives.

To run with HTTP archives, use following settings in your .env file:

Config name Value / Description
SELF_UPDATER_SOURCE http
SELF_UPDATER_REPO_URL Archive URL, e.g. http://archive.webapp/
SELF_UPDATER_PKG_FILENAME_FORMAT Zip package filename format
SELF_UPDATER_DOWNLOAD_PATH Download path on the webapp host server

The archive URL should contain nothing more than a simple directory listing with corresponding zip-Archives.

SELF_UPDATER_PKG_FILENAME_FORMAT contains the filename format for all webapp update packages. I.e. when the update packages listed on the archive URL contain names like webapp-v1.2.0.zip, webapp-v1.3.5.zip, ... then the format should be webapp-v_VERSION_. The _VERSION_ part is used as semantic versionioning variable for MAJOR.MINOR.PATCH versioning. The zip-extension is automatically added.

The target archive files must be zip archives and should contain all files on root level, not within an additional folder named like the archive itself.

Using Gitea

With Gitea you can use your own Gitea-Instance with tag-releases.

To use it, use the following settings in your .env file:

Config name Value / Description
SELF_UPDATER_SOURCE gitea
SELF_UPDATER_GITEA_URL URL of Gitea Server
SELF_UPDATER_REPO_VENDOR Repo Vendor Name
SELF_UPDATER_REPO_NAME Repo Name
SELF_UPDATER_GITEA_PRIVATE_ACCESS_TOKEN Access Token from Gitea
SELF_UPDATER_DOWNLOAD_PATH Download path on the webapp host server

Contributing

Please see the contributing guide.

Licence

The MIT License (MIT). Please see Licence file for more information.

laravel-selfupdater's People

Contributors

codedge avatar dependabot[bot] avatar hsyir avatar jbalatero avatar julianprieber avatar laravel-shift avatar paumove avatar phillopp avatar ruaq avatar turbo124 avatar vortechron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-selfupdater's Issues

Updater evaluating bool instead of string.

We've been using the self-updater for quite a while and things are working perfectly. Recently we've seen the following error

[2021-08-02 21:17:29] production.ERROR: strlen() expects parameter 1 to be string, bool given {“userId”:1,“exception”:"[object] (TypeError(code: 0): strlen() expects parameter 1 to be string, bool given at /invoice/vendor/codedge/laravel-selfupdater/src/Models/UpdateExecutor.php:101)
[stacktrace]

        $sorted->each(function (SplFileInfo $directory) {
            if (! dirsIntersect(File::directories($directory->getRealPath()), config('self-update.exclude_folders'))) {
                File::copyDirectory(
                    $directory->getRealPath(),
                    Str::finish($this->basePath, DIRECTORY_SEPARATOR).Str::finish($directory->getRelativePath(), DIRECTORY_SEPARATOR).$directory->getBasename()
                );
            }

Any ideas of what could possibly be the cause?

Add auto-discovery

Since Laravel 5.5 auto discovery can be used.
Make this package using being auto-discovered by Laravel.

Downloading updates from http source doesnt work

when trying to download a release i get this error
cURL error 3: (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for http:update-server.localhostv1.0.1.zip
this is my env

SELF_UPDATER_VERSION_INSTALLED=1.0
SELF_UPDATER_SOURCE=http
SELF_UPDATER_PKG_FILENAME_FORMAT=v_VERSION_
SELF_UPDATER_REPO_URL=http://update-server.localhost/
SELF_UPDATER_DOWNLOAD_PATH=/tmp

it looks like your regular expression is deforming the repo url

Wrong AccessToken Implementation HTTP Private Repository

The package isn´t able to insert any private access token in an http repository due to a wrong reference.

In HttpRepositoryType in line 220 the following lines were written:
if ($this->hasAccessToken()) { $headers = [ 'Authorization' => $this->getAccessToken(), ]; }
But i think the accesstoken isn´t stored in the current repository but in the releases. So the following code works:

if ($this->release->hasAccessToken()) { $headers = [ 'Authorization' => $this->release->getAccessToken(), ]; }
Is that right or am i´m doing something wrong?

Greets

Adding Slack notification

Currently notification are sent only via mail. Adding Slack as notification channel would be nice.

checkPermissions($this->basePath) is false so can't update

Hi,

I would like to purpose an update button to my admin dashboard for my laravel project.
But, when a new version is available, I click on the update button and nothing.
So I analyzed and found that the problem is in the "UpdateExecutor" class :
this function "checkPermissions($this->basePath)" return false so i can't update.

What I missed ? I don't understand..

Math_syo.

Updating from wrong release folder

I found a major issue when new release folder is created. This line is actually not working as such release folder already exists:

$this->filesystem->moveDirectory(

As a result there are 2 folders created and app tries to update from wrong folder (0.0.1, but files are being stored in 0.0.12021-03-19):
image image

Adding $force = true parameter to moveDirectory method fixed issue for me:

$this->filesystem->moveDirectory(
    createFolderFromFile($this->getStoragePath()).now()->toDateString(),
    createFolderFromFile($this->getStoragePath()),
    true
);

How and where to set download path?

Unbenannt
In the picture above you can see the a folder called "netbounty-shop-52f688b". In there is my fresh downloaded repo. How the heck do I grab all the files and replace them with my original or is there any known bug? Or do I have to change my download path to replace them right?

Can’t fetch repo from github

If I’m trying to fetch a repo from github with

$versionAvailable = $updater->source()->getVersionAvailable();
$release = $updater->source()->fetch($versionAvailable);

I get a Illuminate \ Http \ Client \ ConnectionException with the message:

cURL error 6: Could not resolve host: repos (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for repos/courservio/courservio/zipball/aa49aacc7fa61de8d9135a65c9cc9c0980a6e387

My config in .env is

SELF_UPDATER_REPO_VENDOR=courservio
SELF_UPDATER_REPO_NAME=courservio
SELF_UPDATER_USE_BRANCH=self-update
SELF_UPDATER_VERSION_INSTALLED=2020-04-19T22:35:48Z

Using PHP 8.1.14, Laravel 9.48.0
The installedVersion is 2020-04-19T22:35:48Z and the versionAvailable is 2023-01-29T00:22:28Z.

self-update.php wasn't changed.

I figured out, that the download() function in Release.php is missing the host (api.github.com) but not why. Using tags works fine.

What am I missing?

Excluding vendor directory

Just getting setup, I noticed 'exclude_folders' => ['vendor']. Is it best practice would you say to not distribute /vendor and run composer update? Can this even be done with post_update? I thought that was for artisan commands only? Thanks.

No release found for version

When i hit my update button i get
No release found for version "0.5.0". Please check the repository you're pulling from.
My version_installed is set to v.0.6 and my latest tag is v.0.7
what am i doing wrong?

all my tags:
image

Config is not published

Laravel 5.5
Self-Updater 1.4.3
PHP 7.2.11

Config is not published when running command:

php artisan vendor:publish --provider="Codedge\Updater\UpdaterServiceProvider"

Other packages are successfully publishing their configs.

Is it Laravel 5.5 compatible?

Github private repo access

Is it possible to use this code with Github Private repository also?

I would like to check in user has valid subscription with us and if yes, give him access to upgrade to the latest release. Don't want to give permanent access to private repository but temporary to download the release.

Version check based on branch and commit

Currently you can only update to a specific version which is a tagged release. An improvement would be to specify a branch and optional a commit you can update to.

Problem with extend repository

Hi! I'm having a problem while extending and creating a Bitbucket repository. In the file UpdaterManager line 91 should the attribute not be customSourceCreators instead of customRepositoryTypes?

Support for incremental updates

Just figured out that i need incremental updates for http repos.

Example: if http repo contains multiple update archives like

  • myproject_v1.0.1.zip
  • myproject_v1.0.2.zip
  • myproject_v1.0.3.zip
  • ...

all zip files beginning from SELF_UPDATER_VERSION_INSTALLED should be installed one after another.

` if($updater->source()->isNewVersionAvailable()) {

    // Get all the newest versions available
    $updater->source()->getVersionsAvailable();

    // Run the update process for all zip files
    $updater->source()->updateIncrementing();

`

Would this be s.th. for you?

Not using bearer token for Github

I have configured everything to access a private repository using a token, but calling "getVersionAvailable" returns the following error: 404 Not Found.

As I see in the code, the token is not being used in the request. If I make the following change it works correctly:

Class GithubTagType
Method getRepositoryReleases
Lines from 122 to 126

//if ($this->hasAccessToken()) {
        $headers = [
            'Authorization' => "Bearer <token>", //$this->getAccessToken(),
        ];
//}

Thanks for your support.

Update version installed

good afternoon

After update, does not update SELF_UPDATER_VERSION_INSTALLED in the .env file?

Any place to put the current version that is updated automatically?

Update by tag 'tag_name' of non-object

Hi

I has this error on install

ErrorException
Trying to get property 'tag_name' of non-object

codedge\laravel-selfupdater\src\SourceRepositoryTypes\GithubRepositoryTypes\GithubTagType.php

 $releaseCollection = collect(json_decode($response->getBody()->getContents()));
 $version = $prepend.$releaseCollection->first()->tag_name.$append;

ENV CONFIG

SELF_UPDATER_VERSION_INSTALLED=0.0.1
SELF_UPDATER_REPO_VENDOR={owner}
SELF_UPDATER_REPO_NAME={repo}
SELF_UPDATER_GITHUB_PRIVATE_ACCESS_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
SELF_UPDATER_PKG_FILENAME_FORMAT=VERSION
SELF_UPDATER_DOWNLOAD_PATH=/tmp
SELF_UPDATER_USE_BRANCH={empty}

Router

Route::get('/update', function (\Codedge\Updater\UpdaterManager $updater) {
    // Check if new version is available
    if ($updater->source()->isNewVersionAvailable()) {
        echo $updater->source()->getVersionInstalled(); // Get the current installed version
        $versionAvailable = $updater->source()->getVersionAvailable(); // Get the new version available
        $release = $updater->source()->fetch($versionAvailable); // Create a release
        $updater->source()->update($release); // Run the update process
    } else {
        echo "No new version available.";
    }
});

What is this?

Call to undefined method Codedge\Updater\Events\UpdateSucceeded::getVersionAvailable()

Hello!

Could you help me in this error?

http://imgur.com/a/rRIfL

What u need to know:

The update is running properly, but i always get this message and ofc i can not recieve the email.

Thanks for your help!

p.s: This package isn't removing files if those aren't exist anymore in the new release, am i right? Or is there any way to do that?

p.s 2: Something is wrong with your contact form on your page: https://codedge.de/ (execution timeout, after sending a message). That's why i wrote my issue here :(

When checking new version got error "Attempt to read property "name" on null"

When I try to check new version I got following error

ErrorException
Attempt to read property "name" on null

My configurations are as

'default' => env('SELF_UPDATER_SOURCE', 'http'),
'version_installed' => env('SELF_UPDATER_VERSION_INSTALLED', 'v1.0'),
'repository_types' => [
        'github' => [
            'type' => 'github',
            'repository_vendor' => env('SELF_UPDATER_REPO_VENDOR', ''),
            'repository_name' => env('SELF_UPDATER_REPO_NAME', ''),
            'repository_url' => '',
            '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', ''),
        ],
        'http' => [
            'type' => 'http',
            'repository_url' => env('SELF_UPDATER_REPO_URL', 'http://65.108.219.166:7800/down/dCQgArdmHbAe'),
            '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', '1234'),
        ],
    ],

getVersionAvailable() throws exception if http repo is empty

In my usecase i have version 1.0 running and have no updates in repo yet.
My question is if throwing an exception ("Retrieved version list is empty.") in this case a good idea?
As user i would expect isNewVersionAvailable() to return "false".

Thanks for the great work on this project ..

Gitlab private repo

Please add a support for gitlab repository.
as of not the available is http and github only.

Thanks

Support Guzzle 7.x

Problem 1
- Root composer.json requires codedge/laravel-selfupdater ^3.1 -> satisfiable by codedge/laravel-selfupdater[3.1].
- codedge/laravel-selfupdater 3.1 requires guzzlehttp/guzzle 6.* -> found guzzlehttp/guzzle[6.0.0, ..., 6.5.x-dev] but it conflicts with your root composer.json require (^7.0.1).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.