0

I'm building a small cms and i would like to make a self update feature to it. (something like WordPress has done, but to be honest, i don't know how that works)

So here is where i am now:

  • Every time the client logs in, a curl post request is going to my server, sending the current version of the cms, some authentication data, and for now that's all.
  • A response comes back, and it there is a new version i get the full description about it, show it in the front end to the client and if he wants to update, i download a zip file.

This is where i'm stuck. I don't know if this is the good way and even it it is, how should i proceed.

  • After download i would like to unpack it, overwrite the old files with the new one's, and make all the changes necessary, maybe do some migrations and so on.
  • Make some logs, backups, and when all its done somehow check to so if everything is ok. (Don't know if that's possible)

So could please someone give me some directions, ideas, any advice would be gratefully appreciated.

Mr. Sam
  • 790
  • 2
  • 9
  • 31
  • Do you have access to the creation of cron jobs (time based job scheduler) on your server? If you want it updated automatically on your local PC you can always schedule a cron job – Steve Bauman Mar 07 '14 at 17:51
  • @SteveBauman lets say for now that i dont, but i was thinking everytime the user logs in send an ajax request to the server to check for updates – Mr. Sam Mar 07 '14 at 17:57
  • 1
    As enticing as a self-updating application is, you should ask yourself if you really want that. At any point, your app could break, in which case you will be either trying to debug someone else's code, or waiting for the next update. In my opinion, you should only update if there are new features you really need or for fixing bugs that are negatively impacting your app. – user1669496 Mar 07 '14 at 18:39

1 Answers1

4

One way is to use this package I've created: https://github.com/antonioribeiro/deeployer. The idea behind it is to update your application every time you do a git push to github or bitbucket. Since it uses Taylor's Laravel Envoy Task Runner, updating your application is really easy:

Check this page on how to Install Laravel Envoy Task Runner: http://laravel.com/docs/ssh#envoy-task-runner

Install the Deeployer on your application:

composer require pragmarx/deeployer dev-master

Create a route to do your self-update:

Route::post('deploy', function() 
{
    return Deeployer::run();
});

Create a file Envoy.blade.php in the root of your application with your update commands:

@task('https://github.com/you/repo-name:master', ['on' => ['localhost']])
    git pull origin master
    composer dump-autoload --optimize
    php artisan migrate
@endtask

And then you just have to add a webhook to your application in:

https://github.com/yourname/yourapplication/settings/hooks

Pointing to your route:

http://yourdomain.com/deploy
Md Mazedul Islam Khan
  • 5,318
  • 4
  • 40
  • 66
Antonio Carlos Ribeiro
  • 86,191
  • 22
  • 213
  • 204