Php task runners

Ignacio Velazquez
Ignacio VelazquezApplications Team Lead
task runners for php
ignacio velazquez ……….
/toc
• what is it?
• why?
• task runners
• phing
• robo
• summary
about me
/about-me/nass600
Software Engineer @ Hostelworld
nass600
nass600
nass600
what is it?
/what-is-it/project-stages
installation build qa doc deploy
/what-is-it/project-stages?p=2
down
deps
installation
create
db
run
migrat
load
fixt
/what-is-it/project-stages?p=3
unit
tests
qa
funct
tests
code
qual
gen
report
/what-is-it/definition
a task runner is a tool which provides the
mechanisms to run tasks in an ordered and
controlled fashion
why?
/why/lovely-script
/why/main-concept
automation
/why/main-concept?need-more=true
• Simplify repetitive task
• Save time
• Less human errors
• Easier to explain over the phone
• Deployment
• Builds/Packaging
• Single script entry point
task runners
/task-runners
phing
/phing/intro
• PHing Is Not Gnu make
• Started in 2004
• Ported previously to PHP 5
• 777 stars
• 3315 commits
• Very similar to Apache Ant
• Manifest in XML
/phing/installation
"require-dev": {
"phing/phing": "^2.16"
}
/phing/hello-world
<?xml version="1.0" encoding="UTF-8"?>
<project name="talk-php-task-runners" default="setup:install">
<property name="bin_dir" value="bin"/>
<target name="setup:install"
depends="setup:vendors, setup:run"
description="First install after the first clone"/>
<target name="setup:vendors" description="Remove and download latest version of all vendors">
<echo msg="Updating vendors..."/>
<delete dir="vendors"/>
<exec passthru="true" logoutput="true" checkreturn="true" command="composer install --ansi" />
<exec passthru="true" checkreturn="true" command="npm install" />
</target>
<target name="setup:run" description="Run server with hot reload">
<exec passthru="true" logoutput="true" checkreturn="true" command="${bin_dir}/console server:run" spawn="true"/>
<exec passthru="true" logoutput="true" checkreturn="true" command="npm run serve" />
</target>
</project>
/phing/config
build.dir=build
bin.dir=./bin
web.dir=./web
var.dir=./var
source=src
<?xml version="1.0" encoding="UTF-8"?>
<project name="portfolio" default="setup:run">
<property file="./build.properties"/>
<target name="setup:run"
description="Run server with hot reload">
<exec passthru="true"
logoutput="true"
checkreturn="true"
command="${bin.dir}/console server:run"
spawn="true"/>
<exec passthru="true"
logoutput="true"
checkreturn="true"
command="npm run serve" />
</target>
</project>
/phing/io
<echo msg="Phing rocks!" />
<echo message="Binarycloud, too." />
<echo>And don't forget Propel.</echo>
<echo file="test.txt" append="false">
This is a test message
</echo>
/phing/filesystem
<target name="list-files">
<delete dir="app-clone"/>
<mkdir dir="app-clone"/>
<copy todir="app-clone" includeemptydirs="true">
<fileset dir="./app" id="app-files">
<include name="**/*.yml"/>
<exclude name="**/parameters.yml"/>
</fileset>
</copy>
<foreach param="filename" target="echo-files">
<fileset refid="app-files"/>
</foreach>
</target>
<target name="echo-files" hidden="true">
<echo>file: ${filename}</echo>
</target>
/phing/filters-mappers
<fileset dir="src" id="assets">
<include name="**/*.css"/>
</fileset>
<delete dir="replica"/>
<mkdir dir="replica"/>
<copy todir="replica">
<fileset refid="assets"/>
<mapper type="flatten" />
<filterchain>
<replaceregexp>
<regexp pattern="n" replace=""/>
</replaceregexp>
</filterchain>
</copy>
/phing/integrations/vcs
<gitclone repository="git://github.com/path/to/repo/repo.git"
targetPath="${repo.dir.resolved}" />
<gitcheckout
repository="${repo.dir.resolved}"
branchname="mybranch" quiet="true"
forceCreate="true" />
/phing/integrations/deps
<composer command="install" composer="${dir.release}/composer.phar">
<arg value="--optimize-autoloader" />
<arg value="--working-dir" />
<arg path="${dir.release}" />
</composer>
/phing/integrations/testing
<phpunit printsummary="true"
pharlocation="vendor/bin/phpunit"
configuration="./phpunit.xml.dist">
<formatter type="xml" todir="${xmlreport.dir}" outfile="${report.name}"/>
</phpunit>
/phing/extending
<?php
require_once "phing/Task.php";
class MyEchoTask extends Task {
/**
* The message passed in the buildfile.
*/
private $message = null;
/**
* The setter for the attribute "message"
*/
public function setMessage($str) {
$this->message = $str;
}
/**
* The init method: Do init steps.
*/
public function init() {
// nothing to do here
}
/**
* The main entry point method.
*/
public function main() {
print($this->message);
}
}
<includepath classpath="src/AppBundle/Phing" />
<taskdef name="myecho"
classname="MyEchoTask" />
<myecho message="Hello World" />
robo
/robo/intro
• First release in 2014
• 1739 stars
• 1338 commits
• Written in PHP
• Manifest in PHP
• Symfony Components (console, finder, filesystem..)
/robo/installation
"require-dev": {
"consolidation/robo": "^1.1"
}
/robo/hello-world
<?php
use RoboTasks;
/**
* This is project's console commands configuration for Robo task runner.
*
* @see http://robo.li/
*/
class RoboFile extends Tasks
{
/**
* @var string Production environment
*/
const ENV_PROD = 'prod';
/**
* @var string Development environment
*/
const ENV_DEV = 'dev';
/**
* First install command
*
* @param string $env
* @return bool
*/
public function setupInstall($env = self::ENV_DEV)
{
$task = $this->taskComposerInstall();
if (self::ENV_PROD === $env) {
$task->noDev()->optimizeAutoloader();
putenv('SYMFONY_ENV=prod');
}
$result = $task->run();
if (!$result->wasSuccessful()) {
$this->say('Aborting installation due to some errors');
return false;
}
}
}
/robo/config
dir:
src: 'src'
bin: 'bin'
build: 'build'
bin:
composer: 'vendor/bin'
npm: 'node_modules/.bin'
public function setupInstall($env = self::ENV_DEV)
{
$config = RoboRobo::Config()->export();
// ...
}
/robo/io
public function identify()
{
$this->yell('Hey!!! Welcome to Winterfel', 'blue');
$this->io()->choice('Who are you?', [
'John Snow',
'Tyrion Lannister',
'Danaerys Targaryen'
]);
$this->ask('What do you do?');
$this->say('Best answer ever');
}
/robo/filesystem
public function logsWarmup()
{
$this->taskFilesystemStack()
->mkdir('logs')
->touch('logs/.gitignore')
->chgrp('www', 'www-data')
->symlink('/var/log/nginx/error.log', 'logs/error.log')
->run();
}
/robo/collections
$this->collectionBuilder()
->taskExec('uname -n')
->printOutput(false)
->storeState('system-name')
->taskFilesystemStack()
->defer(
function ($task, $state) {
$task->mkdir($state['system-name']);
}
)
->run();
/robo/integrations/vcs
$this->taskGitStack()
->stopOnFail()
->add('-A')
->commit('adding everything')
->push('origin','master')
->tag('0.6.0')
->push('origin','0.6.0')
->run();
/robo/integrations/deps
$this->taskComposerCreateProject()
->source('foo/bar')
->target('myBar')->run();
$this->taskNpmInstall()->run();
$this->taskBowerUpdate('path/to/my/bower')
->noDev()
->run();
$this->taskGulpRun('clean')
->silent()
->run();
/robo/integrations/testing
$this->taskPHPUnit()
->group('core')
->bootstrap('test/bootstrap.php')
->run();
$this->taskBehat()
->format('pretty')
->noInteraction()
->run();
/robo/integrations/sysadmin
$test = $this->taskDockerRun('test_env')
->detached()
->run();
$this->taskDockerExec($test)
->interactive()
->exec('./runtests')
->run();
/robo/extending
<?php
namespace BoedahRoboTaskDrush;
use RoboCommonCommandArguments;
use RoboTaskCommandStack;
class DrushStack extends CommandStack
{
use CommandArguments;
protected $argumentsForNextCommand;
protected $siteAlias;
protected $drushVersion;
public function __construct($pathToDrush = 'drush')
{
$this->executable = $pathToDrush;
}
public function drupalRootDirectory($drupalRootDirectory)
{
$this->printTaskInfo('Drupal root: <info>' . $drupalRootDirectory .
'</info>');
$this->option('-r', $drupalRootDirectory);
return $this;
}
public function uri($uri)
{
$this->printTaskInfo('URI: <info>' . $uri . '</info>');
$this->option('-l', $uri);
return $this;
}
}
<?php
namespace BoedahRoboTaskDrush;
trait loadTasks
{
protected function
taskDrushStack($pathToDrush = 'drush')
{
return $this->task(DrushStack::class,
$pathToDrush);
}
}
/robo/extending?page=2
<?php
use RoboTasks;
class RoboFile extends Tasks
{
use BoedahRoboTaskDrushloadTasks;
public function install()
{
$this->taskDrushStack()
->drupalRootDirectory('/var/www/html/some-site')
->uri('sub.example.com')
->maintenanceOn()
->updateDb()
->revertAllFeatures()
->maintenanceOff()
->run();
}
}
summary
/summary/comparison
phing robo
Started in 2004 2014
Written in PHP yes yes
Config format xml php
Parallel
execution
yes yes
Extendable yes yes
Verbose yes no
Learning Curve hard easy
IDE support yes yes
I/0 poor rich
Scalable yes yes
Symfony
Components
no yes
/summary/comparison?page=2
phing robo
Github stars 776 1691
Github
commits
3314 1335
Github PR 21 4
Github Issues 46 53
Github
contributors
150 95
questions
thanks!!!
https://slideshare.net/nass600/php-task-runners
1 of 46

More Related Content

What's hot(20)

Building and Deploying PHP Apps Using phingBuilding and Deploying PHP Apps Using phing
Building and Deploying PHP Apps Using phing
Mihail Irintchev2.6K views
Phing: Building with PHPPhing: Building with PHP
Phing: Building with PHP
hozn8.4K views
Automated Deployment With PhingAutomated Deployment With Phing
Automated Deployment With Phing
Daniel Cousineau4.5K views
Mastering Namespaces in PHPMastering Namespaces in PHP
Mastering Namespaces in PHP
Nick Belhomme16.7K views
Laravel Beginners Tutorial 1Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1
Vikas Chauhan75.6K views
Sinatra and friendsSinatra and friends
Sinatra and friends
Jiang Wu1.6K views
PhingPhing
Phing
mdekrijger3K views
Zend expressive workshopZend expressive workshop
Zend expressive workshop
Adam Culp1.7K views
Flask Introduction - Python MeetupFlask Introduction - Python Meetup
Flask Introduction - Python Meetup
Areski Belaid4.4K views
Learning Puppet Chapter 1Learning Puppet Chapter 1
Learning Puppet Chapter 1
Vishal Biyani6K views
Deploying PHP applications with PhingDeploying PHP applications with Phing
Deploying PHP applications with Phing
Michiel Rook13.9K views
Laravel for Web ArtisansLaravel for Web Artisans
Laravel for Web Artisans
Raf Kewl6.8K views

Similar to Php task runners(20)

Lean Php PresentationLean Php Presentation
Lean Php Presentation
Alan Pinstein13.7K views
2019 11-bgphp2019 11-bgphp
2019 11-bgphp
dantleech440 views
Django dev-env-my-wayDjango dev-env-my-way
Django dev-env-my-way
Robert Lujo941 views
Deployment TacticsDeployment Tactics
Deployment Tactics
Ian Barber4.7K views
Docker for DevelopmentDocker for Development
Docker for Development
allingeek303 views
Intro To Node.jsIntro To Node.js
Intro To Node.js
Chris Cowan13.7K views
Toolbox of a Ruby TeamToolbox of a Ruby Team
Toolbox of a Ruby Team
Arto Artnik422 views
Ran Mizrahi - Symfony2 meets Drupal8Ran Mizrahi - Symfony2 meets Drupal8
Ran Mizrahi - Symfony2 meets Drupal8
Ran Mizrahi2.7K views
Release with confidenceRelease with confidence
Release with confidence
John Congdon1.8K views
Voiture tech talkVoiture tech talk
Voiture tech talk
Hoppinger502 views
Node.js basicsNode.js basics
Node.js basics
Ben Lin1.1K views
DevOps in PHP environment DevOps in PHP environment
DevOps in PHP environment
Evaldo Felipe160 views

Recently uploaded(20)

SAP FOR CONTRACT MANUFACTURING.pdfSAP FOR CONTRACT MANUFACTURING.pdf
SAP FOR CONTRACT MANUFACTURING.pdf
Virendra Rai, PMP11 views
Advanced API Mocking TechniquesAdvanced API Mocking Techniques
Advanced API Mocking Techniques
Dimpy Adhikary17 views
El Arte de lo PossibleEl Arte de lo Possible
El Arte de lo Possible
Neo4j28 views
WebAssemblyWebAssembly
WebAssembly
Jens Siebert32 views
Winter '24 Release Chat.pdfWinter '24 Release Chat.pdf
Winter '24 Release Chat.pdf
melbourneauuser9 views

Php task runners

Editor's Notes

  1. animate
  2. animate
  3. Animate to show parallel
  4. animate
  5. Purple color
  6. Fix this or remove it
  7. Fix this or remove it