Skip to content

Instantly share code, notes, and snippets.

@ulrikkold
Forked from mhuber84/AdditionalConfiguration.php
Created August 21, 2014 12:57
Show Gist options
  • Save ulrikkold/73aba6045660ad0e7901 to your computer and use it in GitHub Desktop.
Save ulrikkold/73aba6045660ad0e7901 to your computer and use it in GitHub Desktop.
<?php
$deploymentName = 'My.OneNodeDeployment';
$applicationName = 'My.OneNode';
// SSH username. Authentication via private/public key
$username = 'user';
// Url to the project git repository
$repositoryUrl = 'ssh://host.com/git/my/onenode.git';
// Path to the TYPO3 source on the server
$typo3srcPath = '/data/TYPO3/CMS/TYPO3_6-2-3';
// Path to the shared/editorial files on the server
$filesPath = '/data/projects/My/OneNode/files';
// Path to the web directory on the server
$webDirectoryPath = '/data/projects/My/OneNode';
// URLs for smoke tests
$backendURL = 'http://onenode.my.projects.localhost/typo3';
$backendURLAdditionalCurlParameters = '';
$frontendURL = 'http://onenode.my.projects.localhost';
$frontendURLAdditionalCurlParameters = '-u:user:secret';
/**
* The host on which we want to do the test deployment.
*/
// A speaking name to identify this host
$host = 'server';
// Hostname, used to connect via ssh
$hostname = 'server.onenode.my.projects.localhost';
// Port, used to connect via ssh
$port = '22';
// The deployment path is not the document root!
// The document root has to be: '[deploymentPath]/releases/current'.
$deploymentPath = '/data/projects/My/OneNode/Deployment';
// Database connection configuration on this host (f.e. used for backups)
$dbconHost = 'localhost';
$dbconPort = '3306';
$dbconUsername = 'user';
$dbconPassword = 'secret';
$dbconDatabase = 'projects_my_onenode';
?>
<?php
/* *
* Typical TYPO3 Surf deployment for TYPO3 CMS with one target node *
* *
* It is free software; you can redistribute it and/or modify it under *
* the terms of the GNU Lesser General Public License, either version 3 *
* of the License, or (at your option) any later version. *
* *
* The TYPO3 project - inspiring people to share! *
* */
/** @var \TYPO3\Surf\Domain\Model\Deployment $deployment */
/**
* config.php is not versionized with git so we can have different configs to develop this deployment script
*/
$deploymentConfigPathAndFilename = FLOW_PATH_ROOT . 'Build/Surf/Resources/My.OneNodeDeployment/config.php';
if (!file_exists($deploymentConfigPathAndFilename)) {
exit(sprintf("The deployment config file %s does not exist.\n", $deploymentConfigPathAndFilename));
}
require($deploymentConfigPathAndFilename);
/**
* Application and host
*/
$application = new \TYPO3\Surf\Application\BaseApplication($applicationName);
$application->setOption('repositoryUrl', $repositoryUrl);
$application->setOption('transferMethod', 'git');
$application->setOption('packageMethod', 'git');
$application->setOption('updateMethod', NULL);
$application->setOption('branch', 'live');
$application->setDeploymentPath($deploymentPath);
$node = new \TYPO3\Surf\Domain\Model\Node($host);
$node->setHostname($hostname);
$node->setOption('username', $username);
$node->setOption('port', $port);
$application->addNode($node);
$deployment->addApplication($application);
/**
* Create workflow
*/
$workflow = new \TYPO3\Surf\Domain\Model\SimpleWorkflow();
/**
* Set backend lock on current live
*/
$setbackendlockOptions = array(
'command' => 'cd {currentPath} && typo3/cli_dispatch.phpsh lowlevel_admin setBElock',
'rollbackCommand' => 'cd {currentPath} && typo3/cli_dispatch.phpsh lowlevel_admin clearBElock',
);
$workflow->defineTask('my.onenodedeployment:setbackendlock', 'typo3.surf:shell', $setbackendlockOptions);
$workflow->beforeStage('initialize', 'my.onenodedeployment:setbackendlock');
/**
* Set symlinks to typo3_src and shared files on next live
*/
$setsymlinksOptions = array(
'command' => 'cd {releasePath} && ln -s ' . $typo3srcPath . ' typo3_src && ln -s ' . $filesPath . ' files',
);
$workflow->defineTask('my.onenodedeployment:setsymlinks', 'typo3.surf:shell', $setsymlinksOptions);
$workflow->afterStage('transfer', 'my.onenodedeployment:setsymlinks');
/**
* Set AdditionalConfiguration.php on next live
*/
$setadditionalconfigurationOptions = array(
'command' => 'cd {releasePath} && echo ' . escapeshellarg(\TYPO3\Flow\Utility\Files::getFileContents(FLOW_PATH_ROOT . 'Build/Surf/Resources/My.OneNodeDeployment/AdditionalConfiguration.php')) . ' > typo3conf/AdditionalConfiguration.php',
);
$workflow->defineTask('my.onenodedeployment:setadditionalconfiguration', 'typo3.surf:shell', $setadditionalconfigurationOptions);
$workflow->afterStage('transfer', 'my.onenodedeployment:setadditionalconfiguration');
/**
* Do database backup on current live
*/
$dodatabasebackupOptions = array(
'command' => 'cd {currentPath} && mysqldump -u' . $dbconUsername . ' -p' . $dbconPassword . ' -h' . $dbconHost . ' -P' . $dbconPort . ' --default-character-set=utf8 -l --opt --skip-extended-insert ' . $dbconDatabase . ' > deploymentbackup.sql',
'rollbackCommand' => 'cd {currentPath} && rm deploymentbackup.sql',
);
$workflow->defineTask('my.onenodedeployment:dodatabasebackup', 'typo3.surf:shell', $dodatabasebackupOptions);
$workflow->beforeStage('migrate', 'my.onenodedeployment:dodatabasebackup');
/**
* Clear all caches on next live
*/
$clearallcachesbeforemigrationOptions = array(
'command' => 'cd {releasePath} && rm -rf typo3temp/Cache/* && typo3/cli_dispatch.phpsh extbase cacheapi:clearsystemcache && typo3/cli_dispatch.phpsh extbase cacheapi:clearallcaches',
'rollbackCommand' => 'cd ' . $webDirectoryPath . ' && rm -rf typo3temp/Cache/* && typo3/cli_dispatch.phpsh extbase cacheapi:clearsystemcache && typo3/cli_dispatch.phpsh extbase cacheapi:clearallcaches',
);
$workflow->defineTask('my.onenodedeployment:clearallcachesbeforemigration', 'typo3.surf:shell', $clearallcachesbeforemigrationOptions);
$workflow->beforeStage('migrate', 'my.onenodedeployment:clearallcachesbeforemigration');
/**
* Set git tag
*/
$settagOptions = array(
'tagName' => '{deploymentName}-{releaseIdentifier}',
'description' => 'Deployed with {deploymentName} at ' . date('Y-m-d H:i') . '
Release identifier is {releaseIdentifier}',
'pushTag' => TRUE,
);
$workflow->defineTask('my.onenodedeployment:settag', 'typo3.surf:git:tag', $settagOptions);
$workflow->addTask('my.onenodedeployment:settag', 'cleanup');
/**
* Do database compare on next live
*
* 1=ACTION_UPDATE_CLEAR_TABLE ,2=ACTION_UPDATE_ADD ,3=ACTION_UPDATE_CHANGE ,4=ACTION_UPDATE_CREATE_TABLE ,5=ACTION_REMOVE_CHANGE ,6=ACTION_REMOVE_DROP ,7=ACTION_REMOVE_CHANGE_TABLE ,8=ACTION_REMOVE_DROP_TABLE
*
* @see EXT:coreapi/Classes/Service/DatabaseApiService.php
*/
$dodatabasecompareOptions = array(
'command' => 'cd {releasePath} && typo3/cli_dispatch.phpsh extbase databaseapi:databasecompare 2,3,4,5,6,7,8',
'rollbackCommand' => 'cd {currentPath} && mysql -u' . $dbconUsername . ' -p' . $dbconPassword . ' -h' . $dbconHost . ' -P' . $dbconPort . ' ' . $dbconDatabase . ' < deploymentbackup.sql',
);
$workflow->defineTask('my.onenodedeployment:dodatabasecompare', 'typo3.surf:shell', $dodatabasecompareOptions);
$workflow->addTask('my.onenodedeployment:dodatabasecompare', 'migrate');
/**
* Clear all caches on current live (was next live)
*/
$clearallcachesafterswitchOptions = array(
'command' => 'cd ' . $webDirectoryPath . ' && rm -rf typo3temp/Cache/* && typo3/cli_dispatch.phpsh extbase cacheapi:clearsystemcache && typo3/cli_dispatch.phpsh extbase cacheapi:clearallcaches',
'rollbackCommand' => 'cd ' . $webDirectoryPath . ' && rm -rf typo3temp/Cache/* && typo3/cli_dispatch.phpsh extbase cacheapi:clearsystemcache && typo3/cli_dispatch.phpsh extbase cacheapi:clearallcaches',
);
$workflow->defineTask('my.onenodedeployment:clearallcachesafterswitch', 'typo3.surf:shell', $clearallcachesafterswitchOptions);
$workflow->afterStage('switch', 'my.onenodedeployment:clearallcachesafterswitch');
/**
* Test if backend is available
*/
$isbackendavailableOptions = array(
'url' => $backendURL,
'remote' => TRUE,
'expectedStatus' => 200,
'additionalCurlParameters' => '-A \'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36\' ' . $backendURLAdditionalCurlParameters,
);
//$workflow->defineTask('my.onenodedeployment:isbackendavailable', 'typo3.surf:test:httptest', $isbackendavailableOptions);
//$workflow->addTask('my.onenodedeployment:isbackendavailable', 'cleanup');
/**
* Test if frontend is available
*/
$isfrontendavailableOptions = array(
'url' => $frontendURL,
'remote' => TRUE,
'expectedStatus' => 200,
'additionalCurlParameters' => '-A \'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36\' ' . $frontendURLAdditionalCurlParameters,
);
//$workflow->defineTask('my.onenodedeployment:isfrontendavailable', 'typo3.surf:test:httptest', $isfrontendavailableOptions);
//$workflow->addTask('my.onenodedeployment:isfrontendavailable', 'cleanup');
$deployment->setWorkflow($workflow);
/**
* Remove backend lock on old live (was current live)
*/
$removebackendlockOptions = array(
'command' => 'cd {previousPath} && typo3/cli_dispatch.phpsh lowlevel_admin clearBElock',
'rollbackCommand' => 'cd {previousPath} && typo3/cli_dispatch.phpsh lowlevel_admin setBElock',
);
$workflow->defineTask('my.onenodedeployment:removebackendlock', 'typo3.surf:shell', $removebackendlockOptions);
$workflow->addTask('my.onenodedeployment:removebackendlock', 'cleanup');
/**
* Compress database backup
*/
$compressdatabasebackupOptions = array(
'command' => 'cd {previousPath} && gzip deploymentbackup.sql',
'rollbackCommand' => 'cd {previousPath} && gunzip deploymentbackup.sql.gz',
);
$workflow->defineTask('my.onenodedeployment:compressdatabasebackup', 'typo3.surf:shell', $compressdatabasebackupOptions);
$workflow->addTask('my.onenodedeployment:compressdatabasebackup', 'cleanup');
/**
* Delete all releases older than 6 days, but keeps at least 5 releases
*/
$deleteoldreleasesOptions = array(
'command' => 'cd {deploymentPath} && ls -At1 --ignore=previous --ignore=current --ignore=next releases/ | tail -n +5 | xargs -n1 basename|xargs -n1 -I{} find releases/ -name {} -type d -mtime +6 | xargs -r rm -rf',
);
$workflow->defineTask('my.onenodedeployment:deleteoldreleases', 'typo3.surf:shell', $deleteoldreleasesOptions);
$workflow->addTask('my.onenodedeployment:deleteoldreleases', 'cleanup');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment