typo3 surf - wiki.t3easy.de€™s typo3 surf and why this tool surf is a standalone phar / global...
TRANSCRIPT
TYPO3 SurfGet on your board!
Jan Kiesewetter @t3easy_de
What is a deploymentDo recurring tasks (manual or automatically) to install/update an application in an predetermined sequence
Download external dependencies
Generate assets
Upload data
(For me) Not an provisioning, use Ansible/Chef/Puppet for that!
A poor man’s deploymentTYPO3 Extension
git archive -o ${PWD##*/}.zip HEAD
add necessary non git files (e.g. vendor, node_modules) to zip
Login into backend, open extension manager upload extensions in the right order 🤔😱
Clear cache
Test frontend
TYPO3 site
get.typo3.org / composer install
Extension Manager install distribution
distribution requires TER ext…
Automation | I/O your deployment
Run the same tasks in the same order on every involved system, e.g. production and staging server
Get response
Role back if something breaks to avoid dirty environments
Surf, the end of the rainbow?
Why should you surf?
Save the application knowhow in code as you already do with the business logic
Be faster!
Avoid errors
Be cool 🏄
What’s TYPO3 Surf and why this tool
Surf is a standalone phar / global composer package since v2 (still beta)
Not a Flow Package anymore! (Und alle so: YEAH!)
It comes with ready2use workflows to deploy TYPO3 CMS, Flow, Neos Applications
It’s part of TYPO3, developed and used by core members
It’s written in PHP, every PHP developer can read the code and understand what it is doing and how to write own applications/tasks
It’s extendable and usable for almost every application
It can deploy multiple applications to multiple nodes with one deployment
Surf needs…
A git repository for each application, at least $repositoryUrl = 'file://' . dirname(__DIR__);for a single application
php, (composer), git, rsync (and some binaries on the node)
Surf commandsAvailable commands:
deploy describe help Displays help for a command list Lists commands migrate show simulate
Options: -h, --help Display this help message -q, --quiet Do not output any message -V, --version Display this application version --ansi Force ANSI output --no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Where to put the deployments
Structure inside of your application project .surf
ProjectXY.php <- This is the deployment recipe ProjectXY <- Folder for files that belongs to the recipe
Configuration what ever
web/index.php <- e.g. the TYPO3 index.php composer.json composer.lock
If you deploy multiple applications at once, you can save the surf configuration inside the main app or in a separate repository Global deployments ~/.surf/deployments/
The workspaces
Folder on the system running the surf command
~/.surf/workspace + name of the deployment + name of the app
~/.surf/workspace/MySite/TYPO3 CMS
~/.surf/workspace/Customer/TYPO3 CMS
C:\Users\User\AppData\Local\Surf\MySite\TYPO3 CMS
Base path can be changed throw env SURF_WORKSPACE
IT IS NOT TIDIED BETWEEN DEPLOYMENTS!!!
If you don’t commit your composer.lock it will be generated there and used for the next composer install
$application->setOption('TYPO3\\Surf\\Task\\Package\\GitTask[hardClean]', true);
Serve your Surf || Structure inside the remote deploymentPath cache
transfer (rsync target) releases
20170105185908 20170105214101 20170105223334 20170304112206 current -> ./20170105223334 previous -> ./20170105214101 next -> ./20170304112206 (just during deployment)
shared Data
fileadmin uploads
Point your production domain to $deploymentPath/releases/current/web (Point your smoke test domain to $deploymentPath/releases/next/web) (Point your previous domain to $deploymentPath/releases/previous/web)
Structure of a Surf I
A deployment has One workflow
The workflow hast multiple multiple tasks One release identifier „%Y%m%d%H%M%S“ One workspace base path Multiple options, e.g. initialDeployment used by TYPO3 CMS One or more applications
Structure of a Surf IIEach application has:
One deployment path One context (depending on the application) One transferMethod, rsync by default, but also git
The transferMethod is significant for where are tasks executed, „local“ or remote! Multiple options (inherited from Deployment) used are:
packageMethod, transferMethod, updateMethod repositoryUrl branch TYPO3 CMS has: context, scriptFileName, webDirectory, rsyncExcludes => [], initialDeployment TYPO3\\Surf\\Task\\Generic\\CreateDirectoriesTask[directories], TYPO3\\Surf\\Task\\Generic\\CreateSymlinksTask[symlinks]
One or more nodes (server, targets, hostings) each has hostname Multiple options (inherited from the deployment and the application)
Workflow, stages and tasksA workflow can have multiple stages, the SimpleWorkflow has the predefined stages:
initialize package transfer update migrate finalize test switch cleanup
A task belongs to one stage An application adds tasks to the workflow
Stage initialize
myproject-node.tld (TYPO3 CMS) TYPO3\Surf\Task\CreateDirectoriesTask
myproject-node.tld (TYPO3 CMS) TYPO3\Surf\Task\Generic\CreateDirectoriesTask
Stage package
myproject-node.tld (TYPO3 CMS) TYPO3\Surf\Task\Package\GitTask
myproject-node.tld (TYPO3 CMS) TYPO3\Surf\DefinedTask\Composer\LocalInstallTask
Stage transfer
myproject-node.tld (TYPO3 CMS) TYPO3\Surf\Task\Transfer\RsyncTask
myproject-node.tld (TYPO3 CMS) TYPO3\Surf\Task\Generic\CreateSymlinksTask
myproject-node.tld (TYPO3 CMS) TYPO3\Surf\Task\TYPO3\CMS\CreatePackageStatesTask
Stage update
myproject-node.tld (TYPO3 CMS) TYPO3\Surf\Task\TYPO3\CMS\SymlinkDataTask
myproject-node.tld (TYPO3 CMS) TYPO3\Surf\Task\TYPO3\CMS\CopyConfigurationTask
Stage migrate
myproject-node.tld (TYPO3 CMS) TYPO3\Surf\Task\TYPO3\CMS\SetUpExtensionsTask
Stage finalize
(No default tasks, your turn!)
Stage test
(No default tasks, your turn!)
Stage switch
myproject-node.tld (TYPO3 CMS) TYPO3\Surf\Task\SymlinkReleaseTask
Node "myproject-node.tld" is live!
myproject-node.tld (TYPO3 CMS) TYPO3\Surf\Task\TYPO3\CMS\FlushCachesTask
Stage cleanup
myproject-node.tld (TYPO3 CMS) TYPO3\Surf\Task\CleanupReleasesTask
Removing releases 20170112083003
How to hook in?Add tasks to the workflow from inside your deployment configuration
You can add own tasks before/after other tasks or to a stage
addTaskToStage, afterTask, beforeTask, beforeStage, afterStage
Develop a composer package that saves some global available applications and tasks for you
Maybe a Magento or Piwik Application with tasks to deploy them streamlined with TYPO3
Trigger, trigger, trigger!composer scripts, triggered during the deployment / composer installhttps://getcomposer.org/doc/articles/scripts.md
You can use something like „npm run-script build“ as composer post-install-cmd https://docs.npmjs.com/misc/scripts
You can use gulp as npm build script…
gulp tasks….
Example scriptsurf deploy > composer install > npm run-script > npm install, gulp, npm prune production
Database?!Database is migrated with typo3_console during the deployment by default(default: *.add,*.change, can be changed with $options['databaseCompareMode'])
Database is NOT dumped before migration… because?!
Backup a large DB will harm the live app
A rollback of a DB is hard, because it could have been changed on life after the deployment (new pages/CEs)
You can add a dump task to you workflow that fits your needs
https://github.com/TYPO3/Surf
http://a-w.io/talks/2015-t3cb-deployment/
https://github.com/helhum/TYPO3-Distribution/