Skip to content

Instantly share code, notes, and snippets.

@egobude
Forked from aertmann/Latest.php
Last active August 29, 2015 14:16
Show Gist options
  • Save egobude/a3336e846b2b530026af to your computer and use it in GitHub Desktop.
Save egobude/a3336e846b2b530026af to your computer and use it in GitHub Desktop.
<?php
use TYPO3\Surf\Domain\Model\Node;
use TYPO3\Surf\Domain\Model\SimpleWorkflow;
$application = new \TYPO3\Surf\Application\TYPO3\Flow();
$application->setOption('repositoryUrl', 'git@git.acme.com:Distributions/Acme');
$application->setOption('localPackagePath', FLOW_PATH_DATA . 'Checkout' . DIRECTORY_SEPARATOR . $deployment->getName() . DIRECTORY_SEPARATOR . 'Latest' . DIRECTORY_SEPARATOR);
$application->setOption('composerCommandPath', 'composer');
$application->setOption('transferMethod', 'rsync');
$application->setOption('rsyncFlags', '--recursive --times --perms --links --delete');
$application->setOption('packageMethod', 'git');
$application->setOption('updateMethod', NULL);
$application->setContext('Production');
$application->setDeploymentPath('/acme');
$application->setOption('keepReleases', 2);
$deployment->addApplication($application);
$workflow = new SimpleWorkflow();
$workflow->setEnableRollback(TRUE);
// Prevent local Settings.yaml from being transferred
$workflow->defineTask('typo3.surf:shell:removeLocalConfiguration',
'typo3.surf:shell',
array('command' => 'cd "{releasePath}" && rm -f Configuration/Settings.yaml')
);
$workflow->beforeStage('migrate', array('typo3.surf:shell:removeLocalConfiguration'), $application);
// Patch using beard, if needed (see https://github.com/mneuhaus/Beard)
$workflow->defineTask('fn:beardpatch', 'typo3.surf:localshell', array('command' => 'cd "{workspacePath}" && php beard.phar patch'));
$workflow->beforeStage('transfer', 'fn:beardpatch');
// Remove resource links since they're absolute symlinks to previous releases (will be generated again automatically)
$workflow->defineTask('typo3.surf:shell:unsetResourceLinks',
'typo3.surf:shell',
array('command' => 'cd {releasePath} && rm -rf Web/_Resources/Persistent/*(N)')
);
$workflow->beforeStage('switch', array('typo3.surf:shell:unsetResourceLinks'), $application);
// Clear memcached based caches
$workflow->defineTask('typo3.surf:shell:clearMemcachedCaches',
'typo3.surf:shell',
array('command' => 'cd {releasePath} && FLOW_CONTEXT=Production ./flow cache:flushone TYPO3_TypoScript_Content && FLOW_CONTEXT=Production ./flow cache:flushone Flow_Mvc_Routing_Resolve && FLOW_CONTEXT=Production ./flow cache:flushone Flow_Mvc_Routing_Route')
);
$workflow->beforeStage('switch', array('typo3.surf:shell:clearMemcachedCaches'), $application);
// Clear PHP 5.5+ OpCache (required for php-fpm)
$workflow->beforeStage(
'transfer',
'typo3.surf:php:webopcacheresetcreatescript'
);
$workflow->afterStage(
'switch',
'typo3.surf:php:webopcacheresetexecute'
);
$deployment->setWorkflow($workflow);
$deployment->onInitialize(function() use ($workflow, $application) {
$workflow->setTaskOptions('typo3.surf:generic:createDirectories', array('directories' => array('shared/Data/Web/_Resources', 'shared/Data/Session')));
$workflow->setTaskOptions('typo3.surf:generic:createSymlinks', array(
'symlinks' => array(
'Web/_Resources' => '../../../shared/Data/Web/_Resources/',
'Data/Session' => '../../../shared/Data/Session/'
)
));
$workflow->setTaskOptions('typo3.surf:php:webopcacheresetexecute', array(
'baseUrl' => 'http://acme.com'
));
});
$node = new Node('Latest');
$node->setHostname('acme.com');
$node->setOption('username', 'acme.com');
$application->addNode($node);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment