Developed with love by KnpLabs Hire us for your project!
13

MopaRemoteUpdateBundle

by phiamo

Remote update Bundle

MopaRemoteUpdateBundle

This Bundle provides commands to update remote installations directly from your command line.

app/console mopa:update:remote yourremote

Installation

Installation is quite easy

Step 1: Installation using your composer.json:

{
    "require": {
        "mopa/remote-update-bundle": "dev-master",
    }
}

Step 2: Include the following bundles in your AppKernel.php:

Make sure you do not include bundles twice if you already use them.

// application/ApplicationKernel
public function registerBundles()
{
    return array(
        // ...
        new Mopa\Bundle\RemoteUpdateBundle\MopaRemoteUpdateBundle(),
        new Mopa\Bundle\WSSEAuthenticationBundle\MopaWSSEAuthenticationBundle(),
        new Sensio\Bundle\BuzzBundle\SensioBuzzBundle(),
        new FOS\RestBundle\FOSRestBundle(),
        new JMS\SerializerBundle\JMSSerializerBundle($this)
        // ...
    );
}

Step 2: Add the necessary routing information to your routing.yml

mopa_remote_update_bundle:
    type:     rest
    resource: "@MopaRemoteUpdateBundle/Resources/config/routing.yml"

Step 3: Add the necessary firewall configurations to your security.yml

To protect the api from public we need a firewall and a user provider:

security:
    firewalls:
        wsse_secured:
            pattern:   ^/mopa/update/api/.*
            wsse:
                nonce_dir: null
                lifetime: 300
                provider: in_memory # the user provider providing you user with the role ROLE_REMOTE_UPDATER

if you do not have any user providers or no chance to add the ROLE_REMOTE_UPDATER to your user add this too:

security:
    providers:
        in_memory:
            memory:
                users:
                    '%mopa_remote_update_user%':  { password: '%mopa_remote_update_password%', roles: 'ROLE_REMOTE_UPDATER' }

And in your parameters.yml:

parameters:
    mopa_remote_update_url: http://yourhost
    mopa_remote_update_user: changethis
    mopa_remote_update_password: changethat

Step 4: Add the necessary configuration to your config.yml

Import the necessary configuration in your config.yml:

imports:
    - { resource: @MopaRemoteUpdateBundle/Resources/config/config.yml }

If you do not have a dbal connection in your project also include the sqlite config:

imports:
    - { resource: @MopaRemoteUpdateBundle/Resources/config/config.yml }
    - { resource: @MopaRemoteUpdateBundle/Resources/config/database.yml }

If you do not want to have this feature in your productive environment, just include all this in your config_dev.yml just make sure dependencies are set correct, same for AppKernel and Bundles.

Setup your remotes in your config.yml:

mopa_remote_update:
    remotes:
        my_remote: # the alias to use on console, you can define as many remotes as you like
            url: %mopa_remote_update_url% # the url to your side might also be https
            username: %mopa_remote_update_user% # your username
            password: %mopa_remote_update_password% # your password
            preUpdate: git pull # optional: a command to run before composer updates the vendors, e.g. update your main application
            postUpdate: bin/post-composer.sh -w # optional: a command to run after composer updates
            updater: live # either live or cron see further down howto deal with cron
    composer: /usr/sbin/composer.phar # optional: sets the path to the composer binary if it cant be found

there is a usefule postUpdate packaged which has several features:

bin/post-composer.sh -h

To get a description

The bin/envvars.default has to be copied to bin/envvars and editied, to make app/cache and app/logs wirtable for webserver.

Step 5: update/create the schema:

app/console doctrine:schema:update  --force

Step 6(Optional): configure cron updater:

If you can not use the live updater, e.g. because your webserver does not have permissions to update the vendors, you can create a cronjob on the remote machine to execute the updates:

*/5   *   *   *  *    /path/to/your/app/console mopa:update:check # checks every 5 minutes if there is a new update job in queue

To log the output e.g. for debugging you could use:

*/5   *   *   *  *    /path/to/your/app/console mopa:update:check -v >> /path/to/your/app/logs/mopa_remote_update.log

Step 7: commit your changes to your favorite vcs and setup your remote.

Now its time to push the same to your server and make sure everything is working as expected.
You should also check the postUpdate command an composer are found.

To test the update you can use

app/console mopa:update:local my_remote

Step 8(Optional): ignore MopaRemoteUpdateBundle bin files

Optionally add this to your vcs ignore file (e.g. .gitignore):

# ignore MopaRemoteUpdateBundle bin files
bin/post-composer.sh
bin/envvars.default
app/Resources/remote_update.sqlite
Copyright (c) 2011 Mohrenweiser & Partner, Philipp A. Mohrenweiser
- http://www.mohrenweiserpartner.de

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
mopa_remote_update:
remotes:

# Prototype
name:
preUpdate: false
postUpdate: false
url: ~
username: ~
password: ~
environments:

# Default:
- dev
updater: live
timeout: 300
composer: composer.phar
  • Updated settings
    By phiamo, 4 years ago
  • Corrected exception text
    By phiamo, 4 years ago
  • Moved path of db
    By phiamo, 4 years ago
  • Corrected status message
    By phiamo, 4 years ago
  • Corrected order
    By phiamo, 4 years ago
  • Merge branch 'master' of git://github.com/phiamo/MopaRemoteUpdateBundle
    By phiamo, 4 years ago
  • Started SyfonyCS cleanup
    By phiamo, 4 years ago
  • Updated schema update to be configured
    By phiamo, 4 years ago
  • Envvars override settings for better default management
    By phiamo, 4 years ago
  • Added schema recreation
    By phiamo, 4 years ago
  • Nicened Exception handling and make use od jms serializer
    By phiamo, 4 years ago
  • Updated due to changes in wsse bundle
    By phiamo, 4 years ago
  • Updated namespace
    By phiamo, 4 years ago
  • Updated parameters
    By phiamo, 4 years ago
  • added error handling
    By phiamo, 4 years ago
  • added exception controller
    By phiamo, 4 years ago
  • Updated readme
    By phiamo, 4 years ago
  • corrected finished
    By phiamo, 4 years ago
  • changed check behaviour
    By phiamo, 4 years ago
  • Merge branch 'master' of git://github.com/phiamo/MopaRemoteUpdateBundle
    By phiamo, 4 years ago
  • Updated Readme
    By phiamo, 4 years ago
  • Merge branch 'order'
    By phiamo, 4 years ago
  • updated more
    By phiamo, 4 years ago
  • Corrected order
    By phiamo, 4 years ago
  • Updated Readme for ignore files
    By phiamo, 4 years ago
  • Updated to have runmaks configurable too
    By phiamo, 4 years ago
  • Updated bin paths
    By phiamo, 4 years ago
  • Updated Readme and added post-update script
    By phiamo, 4 years ago
  • Updated check command
    By phiamo, 4 years ago
  • Added check feature
    By phiamo, 4 years ago