2017 © Pedro Pelรกez
 

robo-tasks robo-digipolis-helpers

Helper to create a basic deploy flow.

image

digipolisgent/robo-digipolis-helpers

Helper to create a basic deploy flow.

  • Thursday, July 5, 2018
  • by Jelle-S
  • Repository
  • 9 Watchers
  • 0 Stars
  • 8,474 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 0 Forks
  • 6 Open issues
  • 53 Versions
  • 16 % Grown

The README.md

Robo Digipolis Helpers

Latest Stable Version Latest Unstable Version Total Downloads License, (*1)

Build Status Maintainability Test Coverage PHP 7 ready, (*2)

Used by digipolis, abstract robo file to help with the deploy flow., (*3)

By default, we assume a capistrano-like directory structure:, (*4)

โ”œโ”€โ”€ current -> releases/20150120114500/
โ”œโ”€โ”€ releases
โ”‚   โ”œโ”€โ”€ 20150080072500
โ”‚   โ”œโ”€โ”€ 20150090083000
โ”‚   โ”œโ”€โ”€ 20150100093500
โ”‚   โ”œโ”€โ”€ 20150110104000
โ”‚   โ””โ”€โ”€ 20150120114500

Example implementation

RoboFile.php

<?php

use DigipolisGent\Robo\Helpers\AbstractRoboFile;
use DigipolisGent\Robo\Task\Deploy\Ssh\Auth\AbstractAuth;

class RoboFile extends AbstractRoboFile
{
    public function digipolisValidateCode()
    {
        $collection = $this->collectionBuilder();
        $collection->addTask($this->taskExec('phpcs --standard=PSR2 ./src'));
        return $collection;
    }

    /**
     * Detects whether this site is installed or not. This method is used to
     * determine whether we should run `updateTask` (if this returns `true`) or
     * `installTask` (if this returns `false`).
     */
    protected function isSiteInstalled($worker, AbstractAuth $auth, $remote)
    {
        $currentProjectRoot = $this->getCurrentProjectRoot($worker, $auth, $remote);
        $migrateStatus = '';
        return $this->taskSsh($worker, $auth)
            ->remoteDirectory($currentProjectRoot, true)
            ->exec('ls -al | grep index.php')
            ->run()
            ->wasSuccessful();
    }

    protected function updateTask($worker, AbstractAuth $auth, $remote)
    {
        $currentProjectRoot = $remote['rootdir'];
        return $this->taskSsh($server, $auth)
            ->remoteDirectory($currentProjectRoot, true)
            ->exec('./update.sh');
    }

    protected function installTask(
        $worker,
        AbstractAuth $auth,
        $remote,
        $extra = [],
        $force = false
    ) {
        $currentProjectRoot = $remote['rootdir'];
        return $this->taskSsh($server, $auth)
            ->remoteDirectory($currentProjectRoot, true)
            ->exec('./install.sh');
    }

    /**
     * Build a my site and push it to the server(s).
     *
     * @param array $arguments
     *   Variable amount of arguments. The last argument is the path to the
     *   the private key file (ssh), the penultimate is the ssh user. All
     *   arguments before that are server IP's to deploy to.
     * @param array $opts
     *   The options for this command.
     *
     * @option option1 Description of the first option.
     * @option option2 Description of the second option.
     *
     * @usage --option1=first --option2=2 192.168.1.2 sshuser /home/myuser/.ssh/id_rsa
     */
    public function myDeployCommand(
        array $arguments,
        $opts = ['option1' => 'one', 'option2' => 'two']
    ) {
        return $this->deployTask($arguments, $opts);
    }
}

If you place this in RoboFile.php in your project root, you'll be able to run vendor/bin/robo my:deploy-command --option1=1 --option2=2 192.168.1.2 sshuser /home/myuser/.ssh/id_rsa to release your website. The script will automatically detect whether it should update your site or do a fresh install, based on your implementation of isSiteInstalled. Note that this command can only run after the composer install command completed successfully (without any errors)., (*5)

properties.yml

You need to provide a properties.yml file in your project root as well, so the script knows what symlinks to create, where to put backups, ..., (*6)

Below is an example of some sensible defaults:, (*7)

remote:
  # The application directory where your capistrano folder structure resides.
  appdir: '/home/[user]'
  # The releases directory where to deploy new releases to.
  releasesdir: '${remote.appdir}/releases'
  # The root directory of a new release.
  rootdir: '${remote.releasesdir}/[time]'
  # The web directory of a new release (where e.g. your index.php file resides).
  webdir: '${remote.rootdir}/public'
  # The directory of your current release (your web root). Usually a symlink,
  # see `symlinks` below.
  currentdir: '${remote.appdir}/current'
  # The directory where your config files reside. This should get symlinked to
  # since your config files are normally not in your git repository, and shared
  # across releases. See `symlinks` below.
  configdir: '${remote.appdir}/config'
  # Your files directory that is used to store files uploaded by end-users. This
  # should get symlinked to since the uploaded files are shared across releases.
  # See `symlinks` below.
  filesdir: '${remote.appdir}/files'
  # The folder where to store backups that are created before running updates.
  backupsdir: '${remote.appdir}/backups'
  # The symlinks to create when deploying, in format target:link
  symlinks:
    # Symlink the webdir of the release we're creating to the current directory.
    - '${remote.webdir}:${remote.currentdir}'
    # Symlink the config file from within our config directory to the config of
    # our current release.
    - '${remote.configdir}/config.php:${remote.rootdir}/config/config.php'
  # After a successful release, older releases are removed from
  # ${remote.releasesdir}. This value determines how many past releases we
  # should keep.
  cleandir_limit: 5
# We use the phpseclib library to execute our ssh commands. Their default
# timeout is 10 seconds. Some tasks take longer than that, so we make the
# timeouts configurable. Below are the configurable timeouts. The values used in
# this example are the defaults, meaning that if you don't add them to your
# properties.yml, these are the values that will be used.
timeouts:
  # When we symlink a directory, but it already exists as a directory where we
  # are going to put the symlink, we mirror that directory to the target before
  # removing it and replacing it with the symlink. This is the timeout for the
  # mirroring of such a directory.
  presymlink_mirror_dir: 60
  # We provide a task for syncing database and files between
  # servers/environments. This is the timeout for the rsync command to sync the
  # files in ${remote.filesdir}.
  synctask_rsync: 1800
  # The timeout to create a backup of ${remote.filesdir}.
  backup_files: 300
  # The timeout to create a database backup.
  backup_database: 300
  # The timeout to remove a backup of both files and database (during sync, a
  # backup is created, restored on the destination and then removed from the
  # source).
  remove_backup: 300
  # The timeout to restore a files backup.
  restore_files_backup: 300
  # The timeout to restore a database backup.
  restore_db_backup: 60
  # Before a files backup is restored, the current files are removed. This is
  # the timeout for removing those files.
  pre_restore_remove_files: 300
  # See ${remote.cleandir_limit}. This is the timeout for that operation.
  clean_dir: 30

As you can see, you can reference values from within properties.yml by using following notation: ${path.to.property}. There are also other tokens available:, (*8)

[user]    The ssh user we used to connect to the server.
[time]    New releases are put in a folder with the current timestamp as folder
          name. This is that timestamp.

The Versions

05/07 2018

dev-master

9999999-dev

Helper to create a basic deploy flow.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dieter Blomme
by Jelle Sebreghts

05/07 2018
05/07 2018

dev-develop

dev-develop

Helper to create a basic deploy flow.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dieter Blomme
by Jelle Sebreghts

05/07 2018
19/06 2018
08/06 2018
04/05 2018
14/03 2018
14/03 2018
14/02 2018
06/02 2018
29/01 2018
22/01 2018

dev-feature/13-cleandirs

dev-feature/13-cleandirs

Helper to create a basic deploy flow.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dieter Blomme
by Jelle Sebreghts

29/11 2017
22/11 2017
06/11 2017