Skip to content

Instantly share code, notes, and snippets.

@aertmann
Last active September 16, 2015 09:31
Show Gist options
  • Save aertmann/d4340baee2b3d85feb66 to your computer and use it in GitHub Desktop.
Save aertmann/d4340baee2b3d85feb66 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@github.com:acme/acme.git');
$application->setOption('localPackagePath', FLOW_PATH_DATA . 'Checkout' . DIRECTORY_SEPARATOR . $deployment->getName() . DIRECTORY_SEPARATOR . 'Live' . 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('/var/www/acme');
$application->setOption('keepReleases', 5);
$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);
// 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) && rm -rf Web/_Resources/Static(N)')
);
$workflow->beforeStage('migrate', 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('migrate', array('typo3.surf:shell:clearMemcachedCaches'), $application);
// Clear PHP 5.5+ OpCache (required for php-fpm)
$resetScriptFilename = 'surf-opcache-reset-' . uniqid() . '.php';
$workflow->defineTask('fn:clearopcache',
'typo3.surf:shell',
array('command' => 'cd {currentPath}/Web && echo "<?php if (function_exists(\"opcache_reset\")) { opcache_reset(); } @unlink(__FILE__); echo \"cache cleared\";" > ' . $resetScriptFilename . ' && curl -s "http://acme.com/' . $resetScriptFilename . '"')
);
$workflow->afterStage('switch', array('fn:clearopcache'), $application);
$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/'
)
));
});
$node = new Node('Production');
$node->setHostname('acme.com');
$node->setOption('username', 'acme');
$application->addNode($node);
@hlubek
Copy link

hlubek commented Jul 21, 2015

Hey Aske!

Thx for sharing this. I'd suggest to do the cache clearing after "switch". If a request happens between migrate and switch you could end up with inconsistent cache entries.

... and for the opcache reset there's a new 'typo3.surf:php:webopcacheresetexecute' task included in Surf which can be used to clear the cache (well, it does the curl command on the host running Surf, but that could be improved).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment