Skip to content

Instantly share code, notes, and snippets.

@Sebobo
Last active September 13, 2018 04:02
Show Gist options
  • Save Sebobo/4deda266a6367d75d80033297dac2424 to your computer and use it in GitHub Desktop.
Save Sebobo/4deda266a6367d75d80033297dac2424 to your computer and use it in GitHub Desktop.
TYPO3 v8 surf example
stages:
- build
- deploy
variables:
COMPOSER_PROCESS_TIMEOUT: "1200"
NODE_ENV: "production"
cache:
key: "$CI_BUILD_REF_NAME"
paths:
- cache_*.tar
build:
stage: build
script: composer install
deploy-staging:
stage: deploy
script: ./surf.phar deploy staging --verbose
only:
- master
deploy-production:
stage: deploy
script: ./surf.phar deploy production --verbose
only:
- tags
<?php
use TYPO3\Flow\Utility\Files;
/** @var $deployment TYPO3\Surf\Domain\Model\Deployment "injected" into this script from Surf */
$baseUrl = 'https://www.example.org/';
$hostname = 'www.example.org';
$deploymentPath = '/var/www';
$username = 'foo';
$repository = '[email protected]:foo/bar.git';
$context = 'Production/Staging';
$nodename = 'exampleorg-staging';
$node = new TYPO3\Surf\Domain\Model\Node($nodename);
$node
->setHostname($hostname)
->setOption('username', $username);
$application = new TYPO3\Surf\Application\TYPO3\CMS($nodename);
$application
->setOption('applicationWebDirectory', 'web')
->setOption('TYPO3\\Surf\\Task\\Php\\WebOpcacheResetCreateScriptTask[scriptBasePath]', Files::concatenatePaths(array($deployment->getWorkspacePath($application), 'web')))
->setOption('TYPO3\\Surf\\Task\\TYPO3\\CMS\\SymlinkDataTask[applicationRootDirectory]', 'web')
->setOption('keepReleases', 3)
->setOption('composerCommandPath', 'composer')
->setOption('updateMethod', null)
->setOption('repositoryUrl', $repository)
->setOption('baseUrl', $baseUrl)
->setContext($context)
->setDeploymentPath($deploymentPath)
->addNode($node);
if (getenv('GIT_COMMIT')) {
$application->setOption('sha1', getenv('GIT_COMMIT'));
} else if (getenv('GIT_BRANCH')) {
$application->setOption('branch', getenv('GIT_BRANCH'));
}
$deployment->addApplication($application);
$deployment->onInitialize(function() use ($deployment) {
// Delete directories task currently needed, because of web folder in TYPO3 v8 via composer
// This can be removed when all Surf tasks and typo3console can handle the web folder
$deployment->getWorkflow()
->beforeStage('transfer', 'TYPO3\\Surf\\Task\\Php\\WebOpcacheResetCreateScriptTask')
->afterStage('switch', 'TYPO3\\Surf\\Task\\Php\\WebOpcacheResetExecuteTask')
->removeTask('TYPO3\\Surf\\Task\\TYPO3\\CMS\\CreatePackageStatesTask')
->defineTask('pt:DeleteDirectoriesTask', 'TYPO3\\Surf\\Task\\ShellTask', [
'command' => 'rm -rf {releasePath}/web/fileadmin {releasePath}/web/uploads'
])
->beforeTask('TYPO3\\Surf\\Task\\TYPO3\\CMS\\SymlinkDataTask', 'pt:DeleteDirectoriesTask');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment