TYPO3 Surf

A first introduction

TYPO3 UserGroup Cologne // October 23rd, 2014 // Pixelpark AG

“Software deployment is all of the activities that make a software system available for use.” http://en.wikipedia.org/wiki/Software_deployment

History

  • FTP / SCP
  • SVN / (GIT)
  • Rsync
  • ANT / (Phing)
  • Bash- / Shell-Scripts
  • Capistrano
  • ...

What we want...

...and maybe need!

  • Multiple sources / environments / destinations
  • Code & database migrations
  • Run tests before launch
    • Smoke test
    • Unit tests
    • Functional tests
    • Behat tests
    • Whatever you want to test in some way tests
  • Clean up / compiling / warm up caches
  • Simple / automatic rollbacks
  • Zero downtime deployments

Who is already in the

FLOW?

 

 

 

 

 

 

 

Surf the wave

Tree structure

Before deployment

  • cache
    • (localgitclone)
  • releases
    • 20140813100912
    • 20140918115523
    • 20141018201235
    • 20141022181618
    • 20141023202122
    • current -> 20141023202122
    • previous -> 20141022181618
  • shared

Tree structure

During deployment

  • cache
    • (localgitclone)
  • releases
    • 20140813100912
    • 20140918115523
    • 20141018201235
    • 20141022181618
    • 20141023202122
    • 20141023202434
    • current -> 20141023202122
    • next -> 20141023202434
    • previous -> 20141022181618
  • shared

Tree structure

After deployment

  • cache
    • (localgitclone)
  • releases
    • 20140813100912
    • 20140918115523
    • 20141018201235
    • 20141022181618
    • 20141023202122
    • 20141023202434
    • current -> 20141023202434
    • next -> 20141023202434
    • previous -> 20141023202122
  • shared

Simple workflow: Stages


<?php
/**
 * Order of stages that will be executed
 *
 * @var array
 */
protected $stages = array(
    // Initialize directories etc. (first time deploy)
    'initialize',
    // Local preparation of and packaging of application assets (code and files)
    'package',
    // Transfer of application assets to the node
    'transfer',
    // Update the application assets on the node
    'update',
    // Migrate (Doctrine, custom)
    'migrate',
    // Prepare final release (e.g. warmup)
    'finalize',
    // Smoke test
    'test',
    // Do symlink to current release
    'switch',
    // Delete temporary files or previous releases
    'cleanup'
);
                    

Simple deployment configuration


<?php
/**
 * Deployment configuration for TUGCGN.
 */

/**
 * @var $deployment \TYPO3\Surf\Domain\Model\Deployment
 */

// setup the workflow
$workflow = new \TYPO3\Surf\Domain\Model\SimpleWorkflow();
$deployment->setWorkflow($workflow);
// setup the application
$application = new \TYPO3\Surf\Application\BaseApplication('tugcgnApplication');
// setup the target host
$node = new \TYPO3\Surf\Domain\Model\Node('tugcgn.de');
$node->setOptions(array(
    'username' => 'deploy',
    'port' => '22',
    'hostname' => '185.15.192.112'
));
$application->addNode($node);
$application
    ->setOption('repositoryUrl', 'ssh://yourgitserver.com:29418/tugcgn.git')
    ->setDeploymentPath('/var/www/tugcgn/');
$deployment->addApplication($application);
                    

Non public SCM / Rsync deployments


<?php

// Some other stuff

$application
    ->setOption('repositoryUrl', 'ssh://yourgitserver.int:29418/tugcgn.git')
    ->setOption('packageMethod', 'git')
    ->setOption('transferMethod', 'rsync')
    ->setOption('updateMethod', NULL)
    ->setOption('keepReleases', 3)
    ->setDeploymentPath('/var/www/tugcgn/');

$deployment->addApplication($application);
                    

Own tasks


<?php
/**
 * set file permissions
 */
$setFilePermissions = array(
    'command' => '{releasePath}/setFilePermissions.sh'
);

$workflow->defineTask(
    'mw.tugcgn:setFilePermissions',
    'typo3.surf:shell',
    $setFilePermissions
);
$workflow->afterStage('migrate', 'mw.tugcgn:setFilePermissions');

$deployment->onInitialize(function() use ($workflow, $application) {
    $workflow->removeTask('typo3.surf:flow:setfilepermissions');
});
                    

Let's ship it!

[vagrant@tugcgn htdocs]$ ./flow surf:deploy tugcgn-stage

TYPO3 CMS deployments with Surf?


<?php
namespace TYPO3\Surf\Application\TYPO3;

/*                                                                        *
 * This script belongs to the TYPO3 Flow package "TYPO3.Surf".            *
 *                                                                        *
 *                                                                        */

/**
 * A TYPO3 CMS application template
 * @TYPO3\Flow\Annotations\Proxy(false)
 */
class CMS extends \TYPO3\Surf\Application\BaseApplication {

    /**
     * Constructor
     *
     * @param string $name
     */
    public function __construct($name = 'TYPO3 CMS') {
        parent::__construct($name);
    }
}
                    

Known issue

Support of symlinks for Resources (#51676)

 

Symlink to data folder

/var/www/tugcgn.de/htdocs/releases/current/Data/
->
/var/www/tugcgn.de/htdocs/shared/Data/

 

Data folder

/var/www/tugcgn.de/htdocs/shared/Data/Persistent/
Resources/107bed85ba5e9bae0edbae879bbc2c26d72033ab

Published resource from frontend perspective

http://tugcgn.de/_Resources/Persistent/
107bed85ba5e9bae0edbae879bbc2c26d72033ab.jpg
or
http://tugcgn.de/_Resources/Persistent/
107bed85ba5e9bae0edbae879bbc2c26d72033ab/filename.jpg

 

Published resource from technical perspective

/var/www/tugcgn.de/htdocs/releases/current/Web/_Resources/
Persistent/107bed85ba5e9bae0edbae879bbc2c26d72033ab.jpg
->
/var/www/tugcgn.de/htdocs/releases/20141021113435/Data/
Persistent/Resources/107bed85ba5e9bae0edbae879bbc2c26d72033ab

So, deploy everything with TYPO3 Surf?

Starting a basic website in 2014:

1. Install Node

2. Install Bower

3. Pick CSS framework

4. Pick responsive approach

...

47. Write some HTML

iamdevloper@twitter

Use the right tool(s) for the right job!

Find the workflow that fit your needs!

Thank you!

Questions?

Credits

Used images:

https://flic.kr/p/dLnud / https://flic.kr/p/9ty8k9 / https://flic.kr/p/dr6gws / https://flic.kr/p/ediLaQ / https://flic.kr/p/5bXkeN / https://flic.kr/p/o5AFFA

 

References:

https://git.typo3.org/Packages/TYPO3.Surf.git / http://www.rensadmiraal.nl/blog/typo3-surf-with-rsync-support.html / http://de.slideshare.net/mhelmich/scalable-deployment-architectures-with-typo3-surf-git-and-jenkins / http://etobi.de/blog/tag/typo3-surf/ / https://forge.typo3.org/projects/package-typo3-surf