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
CIハンズオン@PHPカンファレンス福岡-開発
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Kaz Watanabe
June 27, 2015
Programming
180
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
CIハンズオン@PHPカンファレンス福岡-開発
Kaz Watanabe
June 27, 2015
More Decks by Kaz Watanabe
See All by Kaz Watanabe
開発エンジニアが取り組む DevSecOps ~ GitHub Enterprise × Azure での実践~
kaz29
0
35
Greenは本当にGreenか? - B/GデプロイとAPI自動テストで安心デプロイ
kaz29
1
190
CI/CD/IaC 久々に0から環境を作ったらこうなりました
kaz29
1
490
開発エンジニアが実践するDevSecOps
kaz29
0
150
PHPCon福岡2024-Azureもなかなかいいですよ.pdf
kaz29
2
370
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
Mujeres en SEO Summit 2026 - Greatest Disaster Hits en Web Performance
guaca
0
190
例外の正しい扱い方 そのエラー try-catchして大丈夫?
jinwatanabe
0
260
C# and C++ Interoperability - cho-dotnetnew
harukasao
0
290
フロントエンドとバックエンドで「1文字」を揃えよう
youkidearitai
PRO
0
720
CSC307 Lecture 17
javiergs
PRO
0
320
dRuby over BLE
makicamel
2
380
メソッドのジェネリクスでGoの夢は広がるか? / Kyoto.go #65
utgwkk
3
850
AI 輔助遺留系統現代化的經驗分享
jame2408
1
830
The NotImplementedError Problem in Ruby
koic
1
850
Vite+ Unified Toolchain for the Web
naokihaba
0
320
Oxlintのカスタムルールの現況
syumai
6
1.1k
なぜ型を書くのか? TSKaigi2026で改めて考える #tskaigi_smarthr
kajitack
0
100
Featured
See All Featured
Six Lessons from altMBA
skipperchong
29
4.3k
Leo the Paperboy
mayatellez
7
1.8k
Balancing Empowerment & Direction
lara
6
1.2k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.7k
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
440
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
240
Google's AI Overviews - The New Search
badams
0
1k
Bash Introduction
62gerente
615
220k
The agentic SEO stack - context over prompts
schlessera
0
820
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.2k
Designing for Performance
lara
611
70k
Are puppies a ranking factor?
jonoalderson
1
3.6k
Transcript
$",&1)1ͰֶͿ ܧଓతΠϯςάϨʔγϣϯϋϯζΦϯ ։ൃฤ @PHPΧϯϑΝϨϯεԬ 2015/6/27
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 merge origin/step2 $ composer install --dev
DATABASEΛMigration
DATABASEΛMigration $ cd /var/www/application/current/app $ Console/cake Migrations.migration run all
http://192.168.33.10/posts
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݁ՌΛදࣔ
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 Documentation
υΩϡϝϯτΛੜ͢Δ
υΩϡϝϯτΛੜ͢Δ 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 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
։ൃฤ Fin @kaz_29