Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
CakePHPで学ぶ継続的インテグレーション ハンズオン@大阪 開発編
Search
Kaz Watanabe
November 01, 2014
Programming
300
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
CakePHPで学ぶ継続的インテグレーション ハンズオン@大阪 開発編
Kaz Watanabe
November 01, 2014
More Decks by Kaz Watanabe
See All by Kaz Watanabe
開発エンジニアが取り組む DevSecOps ~ GitHub Enterprise × Azure での実践~
kaz29
0
38
Greenは本当にGreenか? - B/GデプロイとAPI自動テストで安心デプロイ
kaz29
1
200
CI/CD/IaC 久々に0から環境を作ったらこうなりました
kaz29
1
490
開発エンジニアが実践するDevSecOps
kaz29
0
170
PHPCon福岡2024-Azureもなかなかいいですよ.pdf
kaz29
2
380
Azure Container Apps + Bicep 〜 こんな感じで運用しています
kaz29
3
1.3k
20220908_フロントエンドパフォーマンス改善.pdf
kaz29
2
200
PHP製のPodCast配信用WebアプリをReact+Next.jsなSSGで作り直してみた話
kaz29
3
720
バックエンドエンジニアの私がお勧めする SPAフロントエンド開発環境
kaz29
6
6.3k
Other Decks in Programming
See All in Programming
<title><a id="</title>君はこのHTMLをパースできるか"></a></title> #雑LT_study
pizzacat83
0
160
為什麼你並不需要ViewModel / No, you don't need a ViewModel
lovee
1
500
Flow は今どうなっているか
mizdra
PRO
0
640
引き算の組織 ― アウトカムとAIに全振りするために辞めたこと ― / Organization by Subtraction
hirokiyamamoto14
PRO
0
260
仕様駆動開発へのトライを機に チームに適合する手法を模索し続けている話
freee
PRO
0
580
使いながら育てる Claude Code — 開発フローの1コマンド化 × 繰り返し指摘の自動仕組み化
shiki_kakaku
0
1.9k
PHP に部分適用が来るぞ!……ところで何それ?おいしいの? #phpcon / phpcon-2026
shogogg
0
710
全PRの83%がAIレビューだけでマージできるようになった開発組織はその後どうなったか
athug
1
1.9k
関東Kaggler会_NVIDIA_Nemotron_コンペ_振り返り
rick_ds
0
670
VibeCodingからAgenticWorkflowへ
starfish719
0
680
AIと壁打ちしながら進めるコスト管理
fufuhu
0
180
php-fpmのプロセスが枯渇した日-調査・対処・そして本当にやるべきだったこと-
shibuchaaaan
0
320
Featured
See All Featured
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
210
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.1k
Design in an AI World
tapps
1
280
Amusing Abliteration
ianozsvald
1
250
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
1
2.1k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
2.4k
The Limits of Empathy - UXLibs8
cassininazir
1
610
Building Applications with DynamoDB
mza
96
7.2k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
290
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.6k
Fireside Chat
paigeccino
42
4k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.4k
Transcript
$",&1)1ͰֶͿ ܧଓతΠϯςάϨʔγϣϯϋϯζΦϯ ։ൃฤ @DevLoveؔ 2014/11/1
WHO? • Θͨͳ͔ͣͻΖ(@kaz_29) • ߹ಉձࣾ decr (decr.jp) • PHP(CakePHP)ͰWebΞϓϦ։ൃ •
Πϯϑϥߏஙɾӡ༻ • iOSΞϓϦ։ൃ #beer #iosdev #cakephp #cat #camp! #golf #chef #vagrant
WHO?
ಈ࡞ڥ
BeHat • ϏϔΠϏΞ(ৼ)ۦಈ։ൃ (BDD:Behaviour Driven Development) • ετʔϦʔϕʔεͷςεςΟϯάϑϨʔϜϫʔΫ
BeHat 'FBUVSFͷهड़ྫ
BeHat 'FBUVSFͷ࣮ߦྫ
BeHat #%%։ൃϓϩηε
࠷ॳͷεϓϦϯτ͕ ऴΘΔॴἬϫʔϓ͠·͢
࠷ॳͷεϓϦϯτ͕ ྃͨ͠ঢ়ଶΛ࡞ ! host $ vagrant ssh develop $ cd
/var/www/application/current/app $ git checkout master $ composer install --dev
DATABASEΛMigration
DATABASEΛMigration ! $ cd /var/www/application/current/app $ Console/cake Migrations.migration run all
None
UnitTest $ cd /var/www/application/current/app $ Console/cake Test app AllTests
None
StoryTest $ cd /var/www/application/current/app $ Console/cake Bdd.story
None
JenkinsʹࠐΜͰ͍͖·͢ʂ
ͦͷલʹ… $ git update-index --add --chmod=+x Console/cake $ git add
-u $ git commit -m “cakeίϚϯυʹ࣮ߦݖΛ༩” $ git push origin master
BUILDπʔϧΛಋೖ ! — phingΛಋೖ $ cd /var/www/application/current/app $ composer require
--dev "phing/phing:~2.8"
PHINGͷઆ໌
BUILDπʔϧΛಋೖ ! — मਖ਼Λίϛοτ $ git add composer.json composer.lock $
git commit -m 'PhingΛՃ' !
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
BUILDπʔϧΛಋೖ ! — ϏϧυΛ࣮ߦ $ cd /var/www/application/current $ app/Vendor/bin/phing !
BUILDπʔϧΛಋೖ ! — मਖ਼Λίϛοτ $ git add build.xml $ git
commit -m ‘ϏϧυϑΝΠϧΛՃ' $ git push origin master !
BUILDπʔϧΛಋೖ
BUILDπʔϧΛಋೖ
BUILDπʔϧΛಋೖ cd ${WORKSPACE}/app composer install --dev cd ${WORKSPACE} app/Vendor/bin/phing -logger
phing.listener.DefaultLogger
ϏϧυΛ࣮ߦʂ
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>
UnitTest݁ՌΛදࣔ͢Δ ! — मਖ਼Λίϛοτ $ git add build.xml $ git
commit -m 'Ϣχοτςετͷ݁ՌΛϑΝΠϧ ʹग़ྗ' $ git push origin master
UnitTest݁ՌΛදࣔ͢Δ
UnitTest݁ՌΛදࣔ͢Δ app/reports/unittest.xml
UnitTest݁ՌΛදࣔ͢Δ
UnitTest݁ՌΛදࣔ͢Δ app/reports/ app/reports/coverage.xml मਖ਼ͨ͠Βอଘͯ͠Ϗϧυ࣮ߦ νΣοΫ͢Δ
UnitTest݁ՌΛදࣔ͢Δ
UnitTest݁ՌΛදࣔ͢Δ ConfigσΟϨΫτϦͷΧόϨοδ͕͍ʂ
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>
UnitTest݁ՌΛදࣔ͢Δ ! — मਖ਼Λίϛοτ $ git add app/phpunit.xml $ git
commit -m 'ΧόϨοδআ֎ରΛՃ' $ git push origin master
UnitTest݁ՌΛදࣔ͢Δ ΧΠθϯͨ͠ʂ
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> <!-- ͜͜·ͰՃ -->
Behatͷ݁ՌΛදࣔ͢Δ ! — मਖ਼Λίϛοτ $ git add build.xml $ git
commit -m 'BehatςετΛՃ' $ git push origin master
Behatͷ݁ՌΛදࣔ͢Δ app/reports/*.xml ʹमਖ਼ मਖ਼ͨ͠Βอଘͯ͠Ϗϧυ࣮ߦ
Behatͷ݁ՌΛදࣔ͢Δ
੩తղੳΛ࣮ߦ͢Δ $ 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.*"
੩తղੳΛ࣮ߦ͢Δ ! — मਖ਼Λίϛοτ $ git add composer.json composer.lock $
git commit -m 'ΠϯεϖΫγϣϯπʔϧͷՃ' $ git push origin master
੩తղੳΛ࣮ߦ͢Δ — 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"/> …
੩తղੳΛ࣮ߦ͢Δ — 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>
੩తղੳΛ࣮ߦ͢Δ — 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>
੩తղੳΛ࣮ߦ͢Δ — 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>
੩తղੳΛ࣮ߦ͢Δ ! — मਖ਼Λίϛοτ $ git add build.xml $ git
commit -m 'ΠϯεϖΫγϣϯͷ࣮ߦΛՃ' $ git push origin master
੩తղੳΛ࣮ߦ͢Δ app/reports/checkstyle.xml app/reports/phpmd.xml app/reports/phpcpd.xml मਖ਼ͨ͠Βอଘͯ͠Ϗϧυ࣮ߦ
੩తղੳΛ࣮ߦ͢Δ MigrationͱSchemaʹܯࠂ
੩తղੳΛ࣮ߦ͢Δ — 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>
੩తղੳΛ࣮ߦ͢Δ ! — मਖ਼Λίϛοτ $ git add build.xml $ git
commit -m 'PMDͷআ֎σΟϨΫτϦΛՃ' $ git push origin master
੩తղੳΛ࣮ߦ͢Δ ΧΠθϯͨ͠ʂ
υΩϡϝϯτΛੜ͢Δ — 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>
υΩϡϝϯτΛੜ͢Δ ! $ git add build.xml $ git commit -m
'υΩϡϝϯτੜͷ࣮ߦΛՃ' $ git push origin master
υΩϡϝϯτΛੜ͢Δ
υΩϡϝϯτΛੜ͢Δ ՃΛԡͯ͠ҎԼͷΑ͏ʹઃఆ app/reports/doc/ index.html API Documen
υΩϡϝϯτΛੜ͢Δ
υΩϡϝϯτΛੜ͢Δ 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 { …
υΩϡϝϯτΛੜ͢Δ app/Model/Post.phpʹҎԼͷ༷ʹίϝϯτΛՃ class Post extends AppModel { ! /** *
Ұཡදࣔ࣌ͷλΠτϧʹ༻͢ΔΧϥϜ໊ * * @var string */ public $displayField = 'title'; ! /** * όϦσʔγϣϯϧʔϧ * * @var array */ public $validate = [
υΩϡϝϯτΛੜ͢Δ ! $ git add app/Model/Post.php $ git commit -m
'DocBlockίϝϯτΛՃ' $ git push origin master मਖ਼ͨ͠Βอଘͯ͠Ϗϧυ࣮ߦ
υΩϡϝϯτΛੜ͢Δ
ຊ൪ڥʹDEPLOY͢Δ
ຊ൪ڥʹDEPLOY͢Δ $ vagrant ssh deploy $ ssh-keygen อଘॴ,ύεϑϨʔζೖྗ(ۭͰվߦͰ) $ cat
~/.ssh/id_rsa.pub ! ެ։伴Λίϐʔ
ຊ൪ڥʹDEPLOY͢Δ Add deploy keyΛΫϦοΫͯ͠ެ։伴ΛՃ
ຊ൪ڥʹDEPLOY͢Δ $ cd /var/www/application/current $ mkdir deploy $ cd deploy
$ cap install ! — .gitignoreʹҎԼΛՃ deploy/config/deploy/production.php CapistranoͷDeployεΫϦϓτͷͻͳܗΛ࡞
ຊ൪ڥʹ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() { }); ຊ൪αʔόʔ༻ͷઃఆϑΝΠϧΛՃ
ຊ൪ڥʹ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ઌͷઃఆ
ຊ൪ڥʹ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ࢀর
ຊ൪ڥʹDEPLOY͢Δ $ cd /var/www/application/current/deploy/ $ cap production deploy Please enter
Server password: (): vagrant
ຊ൪ڥʹDEPLOY͢Δ $ cd /var/www/application/current/deploy/ $ cap production deploy Please enter
Server password: (): vagrant
։ൃฤ Fin @kaz_29