Introducció a Phing php - digitals girona setembre 2014
-
Upload
alex-corretge -
Category
Technology
-
view
2.040 -
download
4
description
Transcript of Introducció a Phing php - digitals girona setembre 2014
![Page 1: Introducció a Phing php - digitals girona setembre 2014](https://reader034.fdocument.pub/reader034/viewer/2022042522/559b3a5f1a28ab0b3f8b47aa/html5/thumbnails/1.jpg)
PHINGAutomatitzant les tasques de
desenvolupament, integració i operacions
Digitals Girona 4 de Setembre de 2.014
CoEspai
![Page 2: Introducció a Phing php - digitals girona setembre 2014](https://reader034.fdocument.pub/reader034/viewer/2022042522/559b3a5f1a28ab0b3f8b47aa/html5/thumbnails/2.jpg)
SOBRE MI• Més de 25 anys de professional IT, més de
15 amb PHP.
• Especialista en sistemes IBM i & z, Linux, Apache, MySQL i PHP i tantes altres tecnologies relacionades.
• Apassionat per la informatització dels processos industrials, logístics i de desenvolupament.
• Un dels primers PHP Zend Certified Engineer.
• http://corretge.cat
• @corretge
Àlex Corretgé
![Page 3: Introducció a Phing php - digitals girona setembre 2014](https://reader034.fdocument.pub/reader034/viewer/2022042522/559b3a5f1a28ab0b3f8b47aa/html5/thumbnails/3.jpg)
SOBRE LA XERRADA
• Automatización tasques repetitives
• El perquè dels Project Build Systems.
• Què és Phing?
• Ús, Exemples i Extensió
![Page 4: Introducció a Phing php - digitals girona setembre 2014](https://reader034.fdocument.pub/reader034/viewer/2022042522/559b3a5f1a28ab0b3f8b47aa/html5/thumbnails/4.jpg)
Les tasques repetitives s’han d’automatitzar. Si no es pot,
s’han de subcontractar.
![Page 5: Introducció a Phing php - digitals girona setembre 2014](https://reader034.fdocument.pub/reader034/viewer/2022042522/559b3a5f1a28ab0b3f8b47aa/html5/thumbnails/5.jpg)
PERQUÈ UNA BUILD?
• Usualment, els Build Systems compilen, testegen i paquetitzen.
• Desplegament aplicacions a producció.
• Desplegament entorns de desenvolupament.
• Ajuda garantir idempotència en els processos.
![Page 6: Introducció a Phing php - digitals girona setembre 2014](https://reader034.fdocument.pub/reader034/viewer/2022042522/559b3a5f1a28ab0b3f8b47aa/html5/thumbnails/6.jpg)
QUÈ EXECUTEM A LA BUILD?
• TOT!
• Paquetitzar l’aplicació (git, zip, etc…)
• Precompilar templates, less, etc…
• Deploy de la Base de Dades.
• Code Sniffer i altres…
• Documentar aplicació.
• Executar tests.
• Aixecar processos background.
• etc…
![Page 7: Introducció a Phing php - digitals girona setembre 2014](https://reader034.fdocument.pub/reader034/viewer/2022042522/559b3a5f1a28ab0b3f8b47aa/html5/thumbnails/7.jpg)
PERQUÈ PHING?• Executable allà on s’executi PHP.
• Sense dependències de Java (ant) o C (make).
• Més de 120 Tasks predefinides.
• Fàcil de crear les pròpies Tasks emprant PHP.
• Integrat a Jenkins i CruiseControl.
![Page 8: Introducció a Phing php - digitals girona setembre 2014](https://reader034.fdocument.pub/reader034/viewer/2022042522/559b3a5f1a28ab0b3f8b47aa/html5/thumbnails/8.jpg)
QUÈ ÉS PHING?• PHing Is Not GNU make :)
• Project Build System basat en Apache Ant.
• Automatització de tasques repetitives.
• Targets en XML, Tasks en PHP
• Flexible i extensible Build Framework.
• Una eina per governar-les totes!
![Page 9: Introducció a Phing php - digitals girona setembre 2014](https://reader034.fdocument.pub/reader034/viewer/2022042522/559b3a5f1a28ab0b3f8b47aa/html5/thumbnails/9.jpg)
One Tool to rule
them all!
![Page 10: Introducció a Phing php - digitals girona setembre 2014](https://reader034.fdocument.pub/reader034/viewer/2022042522/559b3a5f1a28ab0b3f8b47aa/html5/thumbnails/10.jpg)
HISTÒRIA• Duncan Davidson (2000) crea Ant per compilar Tomcat.
• Inici projecte del Binarycloud Framework com a conversor de metadades existents en XML a arrays en PHP sense instal·lar JVM per l’Ant.
• Andreas Aderhold (2002) lidera phing 1.0 (PHP 4)
• Hans Lellelid (2003) i Michiel Rook (2005) lideren la versió 2.0 (PHP 5)
• Actualment desenvolupant versió 3.0
• 113 contribuïdors al repositori git oficial, 30 a l’equip de desenvolupament.
![Page 11: Introducció a Phing php - digitals girona setembre 2014](https://reader034.fdocument.pub/reader034/viewer/2022042522/559b3a5f1a28ab0b3f8b47aa/html5/thumbnails/11.jpg)
ARA, L’EINA
![Page 12: Introducció a Phing php - digitals girona setembre 2014](https://reader034.fdocument.pub/reader034/viewer/2022042522/559b3a5f1a28ab0b3f8b47aa/html5/thumbnails/12.jpg)
INSTAL·LACIÓ• Paquet PEAR
• Paquet PHAR
• Composer com a requeriment de projecte
• Composer global
• git clone
![Page 13: Introducció a Phing php - digitals girona setembre 2014](https://reader034.fdocument.pub/reader034/viewer/2022042522/559b3a5f1a28ab0b3f8b47aa/html5/thumbnails/13.jpg)
VIA COMPOSER GLOBAL
Executar : composer global require phing/phing:2.*
Editar ~/.bash_profile i afegir o modificar el PATH : export PATH=/Users/[elTeuUsuari]/.composer/vendor/bin/:$PATH
Executar : phing -v
![Page 14: Introducció a Phing php - digitals girona setembre 2014](https://reader034.fdocument.pub/reader034/viewer/2022042522/559b3a5f1a28ab0b3f8b47aa/html5/thumbnails/14.jpg)
VIA COMPOSER PROJECTE
Afegir a composer.json: { "require-dev": { "phing/phing": "2.*" } }
Executar :
vendor/bin/phing -v
![Page 15: Introducció a Phing php - digitals girona setembre 2014](https://reader034.fdocument.pub/reader034/viewer/2022042522/559b3a5f1a28ab0b3f8b47aa/html5/thumbnails/15.jpg)
ARA, LA FEINA
![Page 16: Introducció a Phing php - digitals girona setembre 2014](https://reader034.fdocument.pub/reader034/viewer/2022042522/559b3a5f1a28ab0b3f8b47aa/html5/thumbnails/16.jpg)
BUILD.XML
• Llista de fites de la Build: Targets
• Accions per assolir la fita: Tasks
![Page 17: Introducció a Phing php - digitals girona setembre 2014](https://reader034.fdocument.pub/reader034/viewer/2022042522/559b3a5f1a28ab0b3f8b47aa/html5/thumbnails/17.jpg)
![Page 18: Introducció a Phing php - digitals girona setembre 2014](https://reader034.fdocument.pub/reader034/viewer/2022042522/559b3a5f1a28ab0b3f8b47aa/html5/thumbnails/18.jpg)
ESQUELET APLICACIÓ
• Crear l’esquelet de directoris de l’aplicació.
• Pot ser executada per after-install de composer
• Tasks: mkdir, chown, chmod, gitclone, …
![Page 19: Introducció a Phing php - digitals girona setembre 2014](https://reader034.fdocument.pub/reader034/viewer/2022042522/559b3a5f1a28ab0b3f8b47aa/html5/thumbnails/19.jpg)
ESQUELET APLICACIÓ<target name="getDrupal" description="Clone the Drupal repository">
<delete dir="${drupal.workingdir.resolved}" includeemptydirs="true" verbose="true" failonerror="false" />
<mkdir dir="${drupal.workingdir.resolved}" />
<!-- Clone drupal core -->
<gitclone repository="http://git.drupal.org/project/drupal.git" targetPath="${drupal.workingdir.resolved}" />
</target>
![Page 20: Introducció a Phing php - digitals girona setembre 2014](https://reader034.fdocument.pub/reader034/viewer/2022042522/559b3a5f1a28ab0b3f8b47aa/html5/thumbnails/20.jpg)
CONFIG.INI• Definició de propietats de la build i de l’aplicació en arxiu .ini
• Un arxiu al repositori, l’altre git ignorat per al sistema on s’executa la build.
• Podem generar una classe o un arxiu .yaml amb totes les propietats de la build parsejant
$this->project->getProperties();
• Task: property
![Page 21: Introducció a Phing php - digitals girona setembre 2014](https://reader034.fdocument.pub/reader034/viewer/2022042522/559b3a5f1a28ab0b3f8b47aa/html5/thumbnails/21.jpg)
CONFIG.INI
<!-- Carreguem configuració, primer projecte, després particularitats -->
<property file=“etc/config.ini.sample" />
<property file=“etc/config.ini" override="true" />
![Page 22: Introducció a Phing php - digitals girona setembre 2014](https://reader034.fdocument.pub/reader034/viewer/2022042522/559b3a5f1a28ab0b3f8b47aa/html5/thumbnails/22.jpg)
ORGANITZANT TARGETS
• No cal tenir tots els targets en un sól arxiu. <import file="${tasks.dir}/phing/skel.xml" optional="false" />
<import file="${tasks.dir}/phing/qgpl.xml" optional="false" />
<import file="${tasks.dir}/phing/db.xml" optional="false" />
<import file=“${tasks.dir}/phing/app/pop.xml" optional="false" />
<import file=“${tasks.dir}/phing/app/fal.xml" optional="false" />
<import file=“${tasks.dir}/phing/app/svg.xml" optional="false" />
• Plugin phing per a NetBeans molt útil.
![Page 23: Introducció a Phing php - digitals girona setembre 2014](https://reader034.fdocument.pub/reader034/viewer/2022042522/559b3a5f1a28ab0b3f8b47aa/html5/thumbnails/23.jpg)
![Page 24: Introducció a Phing php - digitals girona setembre 2014](https://reader034.fdocument.pub/reader034/viewer/2022042522/559b3a5f1a28ab0b3f8b47aa/html5/thumbnails/24.jpg)
DBDEPLOY TASK
• Deployment de la base de dades amb fixtures per a projectes que no empren doctrine.
• Garantim que totes les instalacions estan al mateix nivell de codi i base de dades.
• Executable after-update composer
![Page 25: Introducció a Phing php - digitals girona setembre 2014](https://reader034.fdocument.pub/reader034/viewer/2022042522/559b3a5f1a28ab0b3f8b47aa/html5/thumbnails/25.jpg)
<pdosqlexec url="${db.driver}:host=${db.host};charset=utf8" encoding="utf8" userId="${db.root.user}" password="${db.root.pass}" onerror=“abort"> -- Creem la taula de dbdeploy USE ${db.name}; ! CREATE TABLE changelog ( change_number BIGINT NOT NULL, delta_set VARCHAR(10) NOT NULL, start_dt TIMESTAMP NOT NULL, complete_dt TIMESTAMP NULL, applied_by VARCHAR(100) NOT NULL, description VARCHAR(500) NOT NULL ); ALTER TABLE changelog ADD CONSTRAINT Pkchangelog PRIMARY KEY (change_number, delta_set); !</pdosqlexec>
![Page 26: Introducció a Phing php - digitals girona setembre 2014](https://reader034.fdocument.pub/reader034/viewer/2022042522/559b3a5f1a28ab0b3f8b47aa/html5/thumbnails/26.jpg)
<dbdeploy url="${db.driver}:dbname=${db.name};host=${db.host};charset=utf8" userId="${db.root.user}" password="${db.root.pass}" dir="${dbdeploy.delta.dir}" outputfile="${dbdeploy.do-script.file}" undooutputfile="${dbdeploy.undo-script.file}" checkAll="true" appliedBy="${db.adm.user}" /> <pdosqlexec url="${db.driver}:host=${db.host};dbname=${db.name};charset=utf8" encoding="utf8" userId="${db.adm.user}" password="${db.adm.pass}" onerror="abort" src="${dbdeploy.do-script.file}" />
![Page 27: Introducció a Phing php - digitals girona setembre 2014](https://reader034.fdocument.pub/reader034/viewer/2022042522/559b3a5f1a28ab0b3f8b47aa/html5/thumbnails/27.jpg)
CONTROL TASK
• Tasques per a “programar” en targets XML
• Blocs IF/THEN/ELSE control lògic.
• Blocs TRY/CATCH control d’errors.
• Blocs FILESET procés conjunts d’arxius (*).
![Page 28: Introducció a Phing php - digitals girona setembre 2014](https://reader034.fdocument.pub/reader034/viewer/2022042522/559b3a5f1a28ab0b3f8b47aa/html5/thumbnails/28.jpg)
<trycatch> <try> <exec command="phpunit --configuration dbunit.xml --log-junit ${build.dir}/var/dbunit/report/db.xml " passthru="true" checkreturn="true" /> <exec command="afplay usr/sounds/Quack.aiff" /> </try> <catch> <exec command="afplay usr/sounds/Laugh.aiff" /> </catch> <finally> <exec command="xsltproc ${build.dir}/usr/dbunit/report.xsl ${build.dir}/var/dbunit/report/db.xml > ${build.dir}/var/dbunit/report/index.html" /> <exec command="open var/dbunit/report/index.html" /> </finally> </trycatch>
![Page 29: Introducció a Phing php - digitals girona setembre 2014](https://reader034.fdocument.pub/reader034/viewer/2022042522/559b3a5f1a28ab0b3f8b47aa/html5/thumbnails/29.jpg)
EXTENENT PHING
• 120 tasks no són suficients ;)
• Targets avançats amb la combinació de phing tasks i comandes bash via task exec.
• Creació de tasques noves en PHP.
![Page 30: Introducció a Phing php - digitals girona setembre 2014](https://reader034.fdocument.pub/reader034/viewer/2022042522/559b3a5f1a28ab0b3f8b47aa/html5/thumbnails/30.jpg)
COMPOSER AUTOLOAD (*)
<adhoc>
<![CDATA[
require_once ‘lib/composer/autoload.php';
]]>
</adhoc>
![Page 31: Introducció a Phing php - digitals girona setembre 2014](https://reader034.fdocument.pub/reader034/viewer/2022042522/559b3a5f1a28ab0b3f8b47aa/html5/thumbnails/31.jpg)
COMPOSER.JSON{
"config": {
"component-dir": "lib/composer",
"vendor-dir": “lib/composer"
},
"require": {
"php": “>=5.3.2”,
"rcrowe/hippy": "0.6.*"
}
}
![Page 32: Introducció a Phing php - digitals girona setembre 2014](https://reader034.fdocument.pub/reader034/viewer/2022042522/559b3a5f1a28ab0b3f8b47aa/html5/thumbnails/32.jpg)
DEFINICIÓ DE LA TASCA <taskdef name="hipchat"
classname="rcrowe\Hippy\PhingTask" />
!
a lib/composer/rcrowe/phing-hipchat/src
└── rcrowe
└── Hippy
└── PhingTask.php
![Page 33: Introducció a Phing php - digitals girona setembre 2014](https://reader034.fdocument.pub/reader034/viewer/2022042522/559b3a5f1a28ab0b3f8b47aa/html5/thumbnails/33.jpg)
DEFINICIÓ DE LA TASCA<?php !namespace rcrowe\Hippy; !use Task; use Project; use BuildException; use rcrowe\Hippy\Transport\Guzzle; use rcrowe\Hippy\Client; use rcrowe\Hippy\Message; use rcrowe\Hippy\Queue;
!class PhingTask extends Task
{
public function main($transport = null)
{
$transport OR $transport = new Guzzle(
![Page 34: Introducció a Phing php - digitals girona setembre 2014](https://reader034.fdocument.pub/reader034/viewer/2022042522/559b3a5f1a28ab0b3f8b47aa/html5/thumbnails/34.jpg)
( DEMO )
![Page 35: Introducció a Phing php - digitals girona setembre 2014](https://reader034.fdocument.pub/reader034/viewer/2022042522/559b3a5f1a28ab0b3f8b47aa/html5/thumbnails/35.jpg)
Som el que fem repetidament. L'excel·lència,
doncs, no és un acte, sinó un hàbit.
![Page 36: Introducció a Phing php - digitals girona setembre 2014](https://reader034.fdocument.pub/reader034/viewer/2022042522/559b3a5f1a28ab0b3f8b47aa/html5/thumbnails/36.jpg)
L’HÀBIT DE CREAR,
REQUEREIX DE TEMPS.
QUE REITERIN LES MÀQUINES, NO ELS HUMANS!!!
![Page 37: Introducció a Phing php - digitals girona setembre 2014](https://reader034.fdocument.pub/reader034/viewer/2022042522/559b3a5f1a28ab0b3f8b47aa/html5/thumbnails/37.jpg)
MÉS INFORMACIÓ• http://www.phing.info
• https://github.com/phingofficial/phing
• http://www.slideshare.net/mdekrijger/phing-7900127
• http://www.slideshare.net/domudall/phing-presentation
• http://www.slideshare.net/michieltcs/building-and-deploying-php-applications-with-phing
• http://www.slideshare.net/hozn/phing-building-with-php
• http://corretge.cat/category/sistemes/phing/
![Page 38: Introducció a Phing php - digitals girona setembre 2014](https://reader034.fdocument.pub/reader034/viewer/2022042522/559b3a5f1a28ab0b3f8b47aa/html5/thumbnails/38.jpg)
COM CONTRIBUIR-HI
• Agafar un ticket a http:// phing.info/trac/roadmap
• Després de programar, documentar i testejar, crear un pull request a http://github.com/phingofficial/phing
![Page 39: Introducció a Phing php - digitals girona setembre 2014](https://reader034.fdocument.pub/reader034/viewer/2022042522/559b3a5f1a28ab0b3f8b47aa/html5/thumbnails/39.jpg)
<echo> Moltes gràcies :)
</echo>