Phingified ci and deployment strategies ipc 2012

37
Phingified CI and Deployment Strategies Oliver Mueller | TEQneers Montag, 15. Oktober 12

Transcript of Phingified ci and deployment strategies ipc 2012

Page 1: Phingified ci and deployment strategies ipc 2012

Phingified CI and Deployment Strategies

Oliver Mueller | TEQneers

Montag, 15. Oktober 12

Page 2: Phingified ci and deployment strategies ipc 2012

About Me• Founder of and CEO at TEQneers [tɛknɪrz]

• Veteran PHP developer

• PHP since 1996 (v2.0)

• Living in Stuttgart, Germany

• like Flying, Photography, NYC

Montag, 15. Oktober 12

Page 3: Phingified ci and deployment strategies ipc 2012

TEQneers

Montag, 15. Oktober 12

Page 4: Phingified ci and deployment strategies ipc 2012

Agenda• Introduction to Phing

• Continues Integration

• Deployment Strategy Examples

• Q&A

Montag, 15. Oktober 12

Page 5: Phingified ci and deployment strategies ipc 2012

Hands Up!• Who knows or uses build tools?

• Who is using Continues Integration?

Montag, 15. Oktober 12

Page 6: Phingified ci and deployment strategies ipc 2012

Agenda• Introduction to Phing

• Continues Integration

• Deployment Strategy Examples

• Q&A

Montag, 15. Oktober 12

Page 7: Phingified ci and deployment strategies ipc 2012

Phing is not GNU make• PHP build tool

• based on Apache Ant

• Originally developed by Binarycloud

• Ported to PHP5 by Hans Lellelid

• Lead is Michiel Rook

Montag, 15. Oktober 12

Page 8: Phingified ci and deployment strategies ipc 2012

Why use build tools?• We all hate repetition

• We forget things

• We make mistakes

• We have other things todo

• Be independent of key staff

Montag, 15. Oktober 12

Page 9: Phingified ci and deployment strategies ipc 2012

Automate it!• Helps developers,

testers, administrators

• Great for new team members

• Consolidate scripts

• Standardize tasks

• Define task dependencies

• Improve quality

• Reduce errors

• Save time

Montag, 15. Oktober 12

Page 10: Phingified ci and deployment strategies ipc 2012

Installation• Use PEAR

# pear channel-discover pear.phing.info

# pear install [--alldeps] phing/phing

• Download package

# http://www.phing.info/trac/wiki/Users/Download

• GIT

# git clone git://github.com/phingofficial/phing.git

Montag, 15. Oktober 12

Page 11: Phingified ci and deployment strategies ipc 2012

Phing Features• Syntax Checks (PhpLint/JsLint)

• Testing (PHPUnit/SimpleTest)

• Static code analysis (pdepend)

• Version Control (SVN/GIT)

• Documentation (ApiGen/phpDox)

• File manipulation (mv/rm/chmod)

• Compression (Zip/Gzip)

Montag, 15. Oktober 12

Page 12: Phingified ci and deployment strategies ipc 2012

Montag, 15. Oktober 12

Page 13: Phingified ci and deployment strategies ipc 2012

<?xml version="1.0" encoding="UTF-8" ?><project name="php-git-wrapper" default="test">

<!-- PROPERTIES --> <property name="src" value="${project.basedir}/php-git-wrapper" /> <property file="build.properties" />

<!-- FILESETS --> <fileset dir="${src}/tests" id="tests"> <include name="**/*Test.php" /> <exclude name="**/Abstracts*.php" /> </fileset>

<!-- TARGETS --> <target name="prepare" description="Prepare environment" /> <target name="test" depends="prepare" description="Start PHPUnit" /> <target name="document" description="Generate HTML documentation" />

</project>

XML Build File

Montag, 15. Oktober 12

Page 14: Phingified ci and deployment strategies ipc 2012

# phing -l

Buildfile: /build.xml [property] Loading /build.propertiesDefault target:------------------------------------------------------ test Start PHPUnit Tests

Main targets:------------------------------------------------------ document Generate HTML documentation prepare Prepare environment test Start PHPUnit Tests

Target List

Montag, 15. Oktober 12

Page 15: Phingified ci and deployment strategies ipc 2012

A Closer LookMontag, 15. Oktober 12

Page 16: Phingified ci and deployment strategies ipc 2012

Extending Phing• Tasks (copy, mkdir, camouflage, ...)

• Types (strings, integer, boolean, DSN, ...)

• Selectors (contain, date, ...)

• Filters (replace, stripwhitespace, ...)

• Mappers (glob, regexp, ...)

• Loggers (xml, html, ...)

Montag, 15. Oktober 12

Page 17: Phingified ci and deployment strategies ipc 2012

Agenda• Introduction to Phing

• Continues Integration

• Deployment Strategy Examples

• Q&A

Montag, 15. Oktober 12

Page 18: Phingified ci and deployment strategies ipc 2012

Continues Integration• Automated build tools

• Short integration phase

• High frequency

• Focus on testing

• Source is XP

Montag, 15. Oktober 12

Page 19: Phingified ci and deployment strategies ipc 2012

Standard CI FlowDeveloper SVN CI

Ouch!

Job

ResultsFailure?

Montag, 15. Oktober 12

Page 20: Phingified ci and deployment strategies ipc 2012

Phingify CI

Montag, 15. Oktober 12

Page 21: Phingified ci and deployment strategies ipc 2012

Agenda• Introduction to Phing

• Continues Integration

• Deployment Strategy Examples

• Q&A

Montag, 15. Oktober 12

Page 22: Phingified ci and deployment strategies ipc 2012

DeploymentAll of the activities that make a software system available for use.

InstallationPackaging Distribution

Montag, 15. Oktober 12

Page 23: Phingified ci and deployment strategies ipc 2012

What matters• Product

• Project

• Library

• Framework

• Open-Source

• Proprietary code

• Dependencies

• Code size

• Configuration complexity

Montag, 15. Oktober 12

Page 24: Phingified ci and deployment strategies ipc 2012

Where matters• Self managed server

• Local server (intranet)

• Customer server

• Multi platform

• Single host

• Server farm

• Cluster

• Cloud

• Appliance

Montag, 15. Oktober 12

Page 25: Phingified ci and deployment strategies ipc 2012

Who matters• Internal administrators

• DevOps

• Customers with IT department

• Some developers

• Trained staff

• Anti geek

Montag, 15. Oktober 12

Page 26: Phingified ci and deployment strategies ipc 2012

Deployment Strategies

• zip

• phar

• composer

• pear

Packaging Distribution

• ftp

• scp

• rsync

• ssh

•web page

Installation

• shell scripts

• composer

• dep / apt-get

• rpm / yum

•MS WPI

• chef / puppet / juju

• version control

• zookeeper

• doozer

• noah

• accord

Montag, 15. Oktober 12

Page 27: Phingified ci and deployment strategies ipc 2012

<pearpkg2 name="phing" dir="${path.src}"> <option name="outputdirectory" value="./build"/> <option name="packagefile" value="package2.xml"/> <option name="packagedirectory" value="./${path.dist}"/> <option name="channel" value="my.pear.channel.com"/> <option name="description" value="${pkg.description}"/> <option name="apiversion" value="${version}"/> <option name="releaseversion" value="${version}"/> <option name="phpdep" value="5.4.0"/> <option name="pearinstallerdep" value="1.4.6"/> <option name="packagetype" value="php"/> <option name="notes" value="${pkg.relnotes}"/> <mapping name="maintainers"> <element> <element key="handle" value="foobar"/> <element key="email" value="[email protected]"/> </element> </mapping></pearpkg2>

PEAR

Montag, 15. Oktober 12

Page 28: Phingified ci and deployment strategies ipc 2012

<pharpackage destfile="${path.build}/package.phar" basedir="./" compression="bzip2"> <fileset dir="./classes"> <include name="**" /> </fileset> <metadata> <element name="version" value="${version}" /> <element name="authors"> <element name="Foo Bar"> <element name="e-mail" value="[email protected]" /> </element> </element> </metadata></pharpackage>

PHAR

Montag, 15. Oktober 12

Page 29: Phingified ci and deployment strategies ipc 2012

MS Web Platform InstallerMyApp.zip

MyApp root folder

Manifest.xml (required)

Parameters.xml (required)

Install.sql

MyApp-admin sub folder

MyApp-content sub folder

MyApp-includes sub folder

readme.txt

license.text

web.config

various other files

Montag, 15. Oktober 12

Page 30: Phingified ci and deployment strategies ipc 2012

{    "name": "teqneers/PHP-Stream-Wrapper-for-Git",    "description": "Git Streamwrapper for PHP",    "autoload": { "psr-0": { "TQ\\Git": "src/TQ" } }, "type": "library",    "license": "MIT",    "require": {        "php": ">=5.3.0",        "doctrine/orm": ">=2.2.3,<2.4-dev"    },    "scripts": {        "post-install-cmd": [            "TQ\\Git\\Setup::phingInstall"        ],        "post-update-cmd": [            "TQ\\Git\\Setup::phingUpdate"        ]    }}

Composer

Montag, 15. Oktober 12

Page 31: Phingified ci and deployment strategies ipc 2012

#!/bin/sh

cd /path/php-git-wrapperunzip php-git-wrapper_1.2.3.zip

# copy configuration file to new versioncopy php-git-wrapper/config.php php-git-wrapper_1.2.3/

# remove symlink and set new onerm appln -s app_1.2.3 app

# clean uprm -rf app_1.2.2

...

Shell Script

Montag, 15. Oktober 12

Page 32: Phingified ci and deployment strategies ipc 2012

name: php-git-wrappersummary: "PHP-Stream-Wrapper-for-Git"maintainer: "Foo Bar <[email protected]>"description: |

Install the PHP Stream Wrapper for git, relates to the mysql charm. Can be scaled to multiple server

requires: db: interface: mysqlprovides: proxy: git

Juju Charm

Montag, 15. Oktober 12

Page 33: Phingified ci and deployment strategies ipc 2012

Summary: A PHP stream wrapper made for GITName: php-git-wrapperVersion: 1.2Release: 3Copyright: GPLGroup: Development/LibrariesSource: https://github.com/PHP-Stream-Wrapper-for-Git.gitURL: https://github.com/teqneers/PHP-Stream-Wrapper-for-GitDistribution: Some LinuxVendor: TEQneers GmbH & Co. KGPackager: Oliver Mueller <[email protected]>

%descriptionUse it with your projects...%buildphing rpm%installphing install%files...

RPM Build

Montag, 15. Oktober 12

Page 34: Phingified ci and deployment strategies ipc 2012

<ftpdeploy host="your-server-001" username="very" password="secret" dir="/var/www/your-app"> <fileset refid="all-files"></ftpdeploy>

FTP / SCP

<scp username="very" password="secret" host="your-server-001" todir="/var/www/your-app"> <fileset refid="all-files"></scp>

Montag, 15. Oktober 12

Page 35: Phingified ci and deployment strategies ipc 2012

# ask which environment to use<input propertyname="env" validargs="dev,test,prod" />

# include file depending on environmnet<property file="properties.${env}"

# start update on remote server<ssh username="${login}" password="${password}" host="${server}" command="phing -f /var/www/app/build.xml update" />

SSH

Montag, 15. Oktober 12

Page 36: Phingified ci and deployment strategies ipc 2012

Q&AMontag, 15. Oktober 12

Page 37: Phingified ci and deployment strategies ipc 2012

contact me if you have any questions

email: [email protected]

twitter: @ogm66

web: www.teqneers.de

Thanks for listening

Have Fun!

Montag, 15. Oktober 12