Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CIハンズオン@PHPカンファレンス福岡-開発

 CIハンズオン@PHPカンファレンス福岡-開発

Kaz Watanabe

June 27, 2015
Tweet

More Decks by Kaz Watanabe

Other Decks in Programming

Transcript

  1. WHO? • Θͨͳ΂͔ͣͻΖ(@kaz_29) • ߹ಉձࣾ decr (decr.jp) • PHP(CakePHP)ͰWebΞϓϦ։ൃ •

    Πϯϑϥߏஙɾӡ༻ • iOSΞϓϦ։ൃ #beer #iosdev #cakephp #cat #camp #golf #chef #vagrant
  2. ͦͷલʹ… $ git update-index --add --chmod=+x Console/cake $ git add

    -u $ git commit -m “cakeίϚϯυʹ࣮ߦݖΛ෇༩” $ git push origin master
  3. BUILDͷઃఆ <?xml version="1.0" encoding="UTF-8"?> <!-- Phing build config file. @link

    http://www.phing.info/ --> <project name="blogapp" default="build"> <!-- Properties --> <property name="basedir" value="${phing.dir}" /> <property name="appdir" value="${basedir}/app" /> <property name="logdir" value="${appdir}/tmp/logs" /> <!-- Build(1) --> <target name="build" depends="prepare,caketest"/> <!-- Prepare(2) --> <target name="prepare" description="Prepare for build"> <exec dir="${appdir}" executable="${appdir}/Console/cake" output="${logdir}/migration.log" checkreturn="true"> <arg line="migrations.migration" /> <arg line="run" /> <arg line="all" /> </exec> </target> <!-- CakePHP unit test with PHPUnit(3) --> <target name="caketest" description="Run CakePHP unit tests with PHPUnit"> <exec dir="${appdir}" executable="${appdir}/Console/cake" output="${logdir}/caketest.log" checkreturn="true"> <arg line="test" /> <arg line="app" /> <arg line="AllTests" /> </exec> </target> </project> /var/www/application/current/build.xml
  4. BUILDπʔϧΛಋೖ — मਖ਼Λίϛοτ $ git add build.xml $ git commit

    -m ‘ϏϧυϑΝΠϧΛ௥Ճ' $ git push origin master
  5. UnitTest݁ՌΛදࣔ͢Δ — build.xmlΛमਖ਼ <target name="caketest" description="Run CakePHP unit tests with

    PHPUnit"> <exec dir="${appdir}" executable="${appdir}/Console/cake" output="${logdir}/caketest.log" checkreturn="true"> <arg line="test" /> <!-- ͔͜͜Β --> <arg line="--log-junit=${appdir}/reports/unittest.xml" /> <arg line="--coverage-html=${appdir}/reports" /> <arg line="--coverage-clover=${appdir}/reports/ coverage.xml" /> <!-- ͜͜·Ͱ௥Ճ --> <arg line="app" /> <arg line="AllTests" /> </exec> </target>
  6. UnitTest݁ՌΛදࣔ͢Δ — मਖ਼Λίϛοτ $ git add build.xml $ git commit

    -m 'Ϣχοτςετͷ݁ՌΛϑΝΠϧ ʹग़ྗ' $ git push origin master
  7. UnitTest݁ՌΛදࣔ͢Δ — app/phpunit.xmlΛमਖ਼(ΧόϨοδͷআ֎ઃఆΛ௥Ճ) <phpunit> <filter> <blacklist> <directory suffix=".php">Plugin</directory> <directory suffix=".php">Test</directory>

    <directory suffix=".php">Vendor</directory> <!-- ͔͜͜Β --> <directory suffix=".php">Config/bootstrap</directory> <file>Config/database.php</file> <-- ͜͜·Ͱ௥Ճ --> </blacklist> </filter> </phpunit>
  8. UnitTest݁ՌΛදࣔ͢Δ — मਖ਼Λίϛοτ $ git add app/phpunit.xml $ git commit

    -m 'ΧόϨοδআ֎ର৅Λ௥Ճ' $ git push origin master
  9. Behatͷ݁ՌΛදࣔ͢Δ — build.xmlΛमਖ਼ … <target name="build" depends="prepare,caketest,behat"/> … <!-- ͔͜͜Β

    --> <target name="behat" description="Run CakePHP acceptance test with Behat"> <exec command="find ${appdir}/tmp -type d -print | xargs chmod 777" escape="false" /> <exec dir="${appdir}" executable="${appdir}/Console/cake" output="${logdir}/behat.log" checkreturn="true"> <arg line="Bdd.story" /> <arg line="--format=junit" /> <arg line="--out=${appdir}/reports" /> </exec> </target> <!-- ͜͜·Ͱ௥Ճ -->
  10. ੩తղੳͷઃఆΛ͢Δ $ cd /var/www/application/current/app $ composer require --dev "cakephp/cakephp-codesniffer:0.1.*" $

    composer require --dev "phpmd/phpmd:2.*" $ composer require --dev "sebastian/phpcpd:2.*"
  11. ੩తղੳͷઃఆΛ͢Δ — मਖ਼Λίϛοτ $ git add composer.json composer.lock $ git

    commit -m 'ΠϯεϖΫγϣϯπʔϧͷ௥Ճ' $ git push origin master
  12. ੩తղੳͷઃఆΛ͢Δ — build.xmlΛमਖ਼(1) … <!-- Properties --> <property name="basedir" value="${phing.dir}"

    /> <property name="appdir" value="${basedir}/app" /> <property name="logdir" value="${appdir}/tmp/logs" /> <!-- vendorbindir ௥Ճ --> <property name="vendorbindir" value="${appdir}/Vendor/bin" /> <!-- Build --> <target name="build" depends="prepare,caketest,behat,phpcs,phpmd,phpcpd"/> …
  13. ੩తղੳͷઃఆΛ͢Δ — build.xmlΛमਖ਼(2) - PHPCodeSnifferͷઃఆΛ௥Ճ … <target name="phpcs" description="Find coding

    standard violations using PHP_CodeSniffer."> <exec dir="${basedir}" executable="${vendorbindir}/phpcs" output="$ {logdir}/phpcs.log"> <arg line="--config-set" /> <arg line="installed_paths" /> <arg line="${appdir}/Vendor/cakephp/cakephp-codesniffer" /> </exec> <exec dir="${basedir}" executable="${vendorbindir}/phpcs" output="$ {logdir}/phpcs.log"> <arg line="--ignore=Test,Vendor,Plugin" /> <arg line="--report=checkstyle" /> <arg line="--report-checkstyle=${appdir}/reports/checkstyle.xml" /> <arg line="--standard=CakePHP" /> <arg line="--extensions=php" /> <arg line="${appdir}" /> </exec> </target>
  14. ੩తղੳͷઃఆΛ͢Δ — build.xmlΛमਖ਼(3) - PHPMDͷઃఆΛ௥Ճ … <target name="phpmd" description="Perform project

    mess detection using PHPMD"> <exec dir="${basedir}" executable="${vendorbindir}/phpmd" output="${logdir}/phpmd.log"> <arg line="${appdir}" /> <arg line="xml" /> <arg line="codesize,unusedcode,design,naming" /> <arg line="--exclude ${appdir}/Test,${appdir}/Vendor,$ {appdir}/Plugin" /> <arg line="--reportfile ${appdir}/reports/phpmd.xml" /> </exec> </target>
  15. ੩తղੳͷઃఆΛ͢Δ — build.xmlΛमਖ਼(4) - PHPCPDͷઃఆΛ௥Ճ … <target name="phpcpd" description="Perform project

    mess detection using PHPMD"> <exec dir="${basedir}" executable="${vendorbindir}/phpcpd" output="${logdir}/phpcpd.log"> <arg line="--exclude Vendor" /> <arg line="--exclude Plugin" /> <arg line="--exclude webroot" /> <arg line="--log-pmd ${appdir}/reports/phpcpd.xml" /> <arg line="--names *.php,*.cpt" /> <arg line="${appdir}" /> </exec> </target>
  16. ੩తղੳͷઃఆΛ͢Δ — मਖ਼Λίϛοτ $ git add build.xml $ git commit

    -m 'ΠϯεϖΫγϣϯͷ࣮ߦΛ௥Ճ' $ git push origin master
  17. ੩తղੳͷઃఆΛ͢Δ — build.xmlΛमਖ਼(5) - PHPMDͷআ֎σΟϨΫτϦ௥Ճ … <target name="phpmd" description="Perform project

    mess detection using PHPMD"> <exec dir="${basedir}" executable="${vendorbindir}/phpmd" output="${logdir}/phpmd.log"> <arg line="${appdir}" /> <arg line="xml" /> <arg line="codesize,unusedcode,design,naming" /> <!-- ͜͜ʹઃఆΛ௥Ճ(,${appdir}/Config/Migration,${appdir}/Config/Schema) --> <arg line="--exclude ${appdir}/Test,${appdir}/Vendor,$ {appdir}/Plugin,${appdir}/Config/Migration,${appdir}/Config/Schema" /> <!- ͜͜·Ͱ --> <arg line="--reportfile ${appdir}/reports/phpmd.xml" /> </exec> </target>
  18. ੩తղੳͷઃఆΛ͢Δ — मਖ਼Λίϛοτ $ git add build.xml $ git commit

    -m 'PMDͷআ֎σΟϨΫτϦΛ௥Ճ' $ git push origin master
  19. υΩϡϝϯτΛੜ੒͢Δ — build.xmlΛमਖ਼(1) … <target name="build" depends=“prepare,caketest,behat,phpcs,phpmd,phpcpd,phpdoc"/> … <!—- ҎԼΛ௥Ճ

    —> <target name="phpdoc" description="Generate Application Documentation using phpDocumentor"> <exec dir="${basedir}" executable="phpdoc" output="${logdir}/phpdoc.log" checkreturn="true"> <arg line="run" /> <arg line="-t ${appdir}/reports/doc" /> <arg line="-d ${appdir}/" /> <arg line="-e php" /> <arg line="-i ${appdir}/Vendor/,${appdir}/Plugin/,${appdir}/Test/,$ {appdir}/Config/" /> <arg line="-p" /> </exec> </target>
  20. υΩϡϝϯτΛੜ੒͢Δ app/Model/Post.phpʹҎԼͷ༷ʹίϝϯτΛ௥Ճ <?php App::uses('AppModel', 'Model'); /** * Post Model *

    * ϒϩάهࣄ༻ϞσϧͰ͢ * * @copyright php_ci_book * @link https://github.com/phpcibook/blogapp/blob/master/app/Model/Post.php * @since 1.0 * @auther ࡞੒ऀͷ໊લ <[email protected]> * */ class Post extends AppModel { …
  21. υΩϡϝϯτΛੜ੒͢Δ app/Model/Post.phpʹҎԼͷ༷ʹίϝϯτΛ௥Ճ class Post extends AppModel { /** * Ұཡදࣔ࣌ͷλΠτϧʹ࢖༻͢ΔΧϥϜ໊

    * * @var string */ public $displayField = 'title'; /** * όϦσʔγϣϯϧʔϧ * * @var array */ public $validate = [
  22. ຊ൪؀ڥʹDEPLOY͢Δ $ cd /var/www/application/current $ mkdir deploy $ cd deploy

    $ cap install CapistranoͷDeployεΫϦϓτͷͻͳܗΛ࡞੒
  23. ຊ൪؀ڥʹDEPLOY͢Δ deploy/config/deploy/production.php <?php Environment::configure('production', true, [ 'MYSQL_DB_HOST' => 'localhost', 'MYSQL_USERNAME'

    => 'webapp', 'MYSQL_PASSWORD' => 'passw0rd', 'MYSQL_DB_NAME' => 'blog', 'MYSQL_PREFIX' => '', 'debug' => 0, ], function() { }); ຊ൪αʔόʔ༻ͷઃఆϑΝΠϧΛ௥Ճ
  24. ຊ൪؀ڥʹDEPLOY͢Δ $ cd /var/www/application/current/deploy/config/deploy $ vim production.rb server '192.168.33.200', roles:

    %w{web app db}, user: 'vagrant', ssh_options: { password: fetch(:password) }, cake_env: "production", app_config:'production.php', group: 'vagrant' Deployઌͷઃఆ
  25. ຊ൪؀ڥʹDEPLOY͢Δ $ cd /var/www/application/current/deploy/ $ vim reploy.rb — 5ߦ໨ͷϦϙδτϦURLΛ֤ࣗमਖ਼ set

    :repo_url, '[email protected]:phpcibook/blogapp.git' # (2) DeployεΫϦϓτΛमਖ਼ ϑΝΠϧͷৄࡉ͸ stypi_ deploy.rbࢀর