PHP code example of digipolisgent / robo-digipolis-deploy

1. Go to this page and download the library: Download digipolisgent/robo-digipolis-deploy library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

digipolisgent / robo-digipolis-deploy example snippets


$auth = new \DigipolisGent\Robo\Task\Deploy\Ssh\Auth\KeyFile('user', '/home/myuser/.ssh/id_dsa');
$result = $this->taskPushPackage('192.168.1.1', $auth)
    ->port(8022)
    ->timeout(15)
    ->destinationFolder('/folder/on/server')
    ->package('/path/to/local/package.tar.gz')
    ->run();

$auth = new \DigipolisGent\Robo\Task\Deploy\Ssh\Auth\KeyFile('user', '/home/myuser/.ssh/id_dsa');
$result = $this->taskSFTP('192.168.1.1', $auth)
    ->port(8022)
    ->timeout(15)
    // Download file from server.
    ->get('/path/to/remote/file.txt', '/path/to/local/file.txt')
    // Upload file to server.
    ->put('/path/to/remote/file.txt', '/path/to/local/file.txt')
    ->run();

$auth = new \DigipolisGent\Robo\Task\Deploy\Ssh\Auth\KeyFile('user', '/home/myuser/.ssh/id_dsa');
$result = $this->taskSsh('192.168.1.1', $auth)
    ->port(8022)
    ->timeout(15)
    // Set the remote directory to execute the commands in.
    ->remoteDirectory('/path/to/remote/dir')
    ->exec('composer install')
    ->run();

$result = $this
    ->taskSymlinkFolderFileContents('/path/to/source', '/path/to/destination')
    ->run();



class RoboFile extends \Robo\Tasks
{
    use \DigipolisGent\Robo\Task\Deploy\loadTasks;

    /**
     * Creates the symlinks.
     */
    public function symlinks($source, $dest)
    {
        $this
            ->taskSymlinkFolderFileContents($source, $dest)
            ->run();
    }
}




class RoboFile extends \Robo\Tasks
{
    use \DigipolisGent\Robo\Task\Deploy\loadTasks;

    /**
     * Creates the symlinks.
     */
    public function symlinks($source, $dest)
    {
        $auth = new \DigipolisGent\Robo\Task\Deploy\Ssh\Auth\KeyFile('user', '/home/myuser/.ssh/id_dsa');
        $this->taskSsh('192.168.1.1', $auth)
            ->port(8022)
            ->timeout(15)
            ->remoteDirectory('/path/to/remote/dir')
            ->exec('vendor/bin/robo symlink ' . $source . ' ' . $dest)
            ->run();
    }
}


$filesystemConfig = [
    'local' => [
        'type' => 'Local',
        'root' => '/home/myuser/backups',
    ],
];

$dbConfig = [
    'development' => [
        'type' => 'mysql',
        'host' => 'localhost',
        'port' => '3306',
        'user' => 'root',
        'pass' => 'password',
        'database' => 'test',
        'singleTransaction' => true,
        'ignoreTables' => [],
    ],
    'production' => [
        'type' => 'mysql',
        'host' => 'localhost',
        'port' => '3306',
        'user' => 'root',
        'pass' => 'password',
        'database' => 'test',
        'ignoreTables' => [],
        'structureTables' => [],
        'tables' => [],
        'dataOnly' => false,
        'orderedDump' => false,
        'singleTransaction' => true,
        'extra' => '--opt',
    ],
];
// Store a backup of the development database in /home/myuser/backups/dev.sql.tar.gz.
$result = $this->taskDatabaseBackup($filesystemConfig, $dbConfig)
    ->database('development')
    ->destination('dev.sql')
    ->compression('tar')
    ->run();


$filesystemConfig = [
    'local' => [
        'type' => 'Local',
        'root' => '/home/myuser/backups',
    ],
];

$dbConfig = [
    'development' => [
        'type' => 'mysql',
        'host' => 'localhost',
        'port' => '3306',
        'user' => 'root',
        'pass' => 'password',
        'database' => 'test',
        'singleTransaction' => true,
        'ignoreTables' => [],
    ],
    'production' => [
        'type' => 'mysql',
        'host' => 'localhost',
        'port' => '3306',
        'user' => 'root',
        'pass' => 'password',
        'database' => 'test',
        'ignoreTables' => [],
        'structureTables' => [],
        'tables' => [],
        'dataOnly' => false,
        'orderedDump' => false,
        'singleTransaction' => true,
        'extra' => '--opt',
    ],
];
// Restore a backup of the development database located at /home/myuser/backups/dev.sql.tar.gz.
$result = $this->taskDatabaseRestore($filesystemConfig, $dbConfig)
    ->database('development')
    ->source('dev.sql.tar.gz')
    ->compression('tar')
    ->run();


$dbConfig = [
    'production' => [
        // Specify it's a mysql database.
        'type' => 'mysql',
        // Specify the database credentials.
        'host' => 'localhost',
        'port' => '3306',
        'user' => 'root',
        'pass' => 'password',
        'database' => 'test',
        // Tables to exclude from the export. This option will be ignored if the
        // 'tables' configuration option is set, because all tables will be
        // excluded except the ones specified in the 'tables' option. Therefore,
        // adding a table to the 'ignoreTables' would be the same as omitting it
        // from tbe 'tables' option if that option has a non-empty) value.
        'ignoreTables' => [],
        // Tables to only export the table structure for. A good example would
        // be a cache table, since most of the time you wouldn't want this
        // table's data in a backup. The structure of the tables specified here
        // will be exported even if the 'tables' configuration options has a
        // (non-empty) value and these tables are not in it.
        'structureTables' => [],
        // Tables to export. Leave empty to export all tables (except those
        // specified in the 'ignoreTables' configuration option).
        'tables' => [],
        // Export only data, not table structure.
        'dataOnly' => false,
        // Order by primary key and add line breaks for efficient diff in
        // revision control. Slows down the dump.
        'orderedDump' => false,
        // If singleTransaction is set to true, the --single-transcation flag
        // will be set. This is useful on transactional databases like InnoDB.
        // http://dev.mysql.com/doc/refman/5.7/en/mysqldump.html#option_mysqldump_single-transaction
        'singleTransaction' => true,
        // Extra options to pass to mysqldump (e.g. '--opt --quick').
        'extra' => '--opt',

    ],
];

class RoboFile extends \Robo\Tasks
{
    use \DigipolisGent\Robo\Task\Deploy\Commands\loadCommands;
}

/**
 * @hook on-event digipolis-db-config
 */
public function defaultDbConfig()
{
    $dbConfig = [];
    $dbConfig['default'] = [
        'type' => 'mysql',
        'host' => 'localhost',
        'port' => '3306',
        'user' => 'root',
        'pass' => '$up3r$3cr3tP@$$w0rD',
        'database' => 'my_database',
        'structureTables' => [],
        'extra' => '--skip-add-locks --no-tablespaces',
    ];

    return $dbConfig;
}

/**
 * @hook on-event digipolis-db-config
 */
public function defaultDbConfig()
{
    $dbConfig = [];
    $dbConfig['default'] = [
        'type' => 'mysql',
        'host' => 'localhost',
        'port' => '3306',
        'user' => 'root',
        'pass' => '$up3r$3cr3tP@$$w0rD',
        'database' => 'my_database',
        'structureTables' => [],
        'extra' => '--skip-add-locks --no-tablespaces',
    ];

    return $dbConfig;
}