ä»åããã¤ããHeroku+Symfony2ãã¿ã§ãã
ååã®è¨äºã§ãHerokuã§Symfony2ã¢ããªã±ã¼ã·ã§ã³ããããã¤ã§ããããã«ãªãã¾ããããããããã°ãã¹ããéãã¦ããªããªã¨æãã¾ããã
ã¡ããã¨ãããããã¯ããä½ããªããã¹ãã¯å¿
é ï¼ã¨ãããã¨ã§ããªã³ã©ã¤ã³CIãµã¼ãã¹ã®Travis CIã¨é£æºãã¦ãã¹ããéããå¾ã«Herokuã«èªåçã«ãããã¤ã§ããããã«ãã¦ã¿ã¾ãã
ã¾ãããã¹ãã®ã«ãã¬ãã¸ã¬ãã¼ããç»é¢ã§ç¢ºèªã§ããããã«ãCoverallsã¨ãé£æºããããã«ãã¾ããã
ä»åã®ç®æ¨
- GitHubã«ããSymfony2ã¢ããªã±ã¼ã·ã§ã³ãTravis CIçµç±ã§Herokuã«ãããã¤ã§ããããã«ãã
- Travis CIã¨Coverallsã¨é£æºãã¦ãã¹ãã®ã«ãã¬ãã¸ã確èªã§ããããã«ãã
ç°å¢
- Mac OS X 10.9.2
- Git 1.8.5.2
- Symfony2 (2.3.16)
- PHP 5.5.14
- heroku-toolbelt 3.9.6
- travis(ã³ãã³ã) 1.6.16
åææ¡ä»¶
- ã½ã¼ã¹ã³ã¼ããGitHubã®Publicãªãã¸ããªã¨ãã¦ç»é²ããã¦ãããã¨ããã©ã¤ãã¼ããªãã¸ããªã ã¨Travis CIã¯ææã«ãªãã¾ã
- Herokuã¢ããªã±ã¼ã·ã§ã³ã¨ãã¦åãããããã«ãã¦ãããã¨
- Herokuã§Symfony2ããããã¤ãã¦åãããããã«ãã ãåèã«Herokuã§ã¢ããªã±ã¼ã·ã§ã³ãåãããããã«ãã¦ããã¦ãã ãã
Travis CIã¨ã¯
ç°¡åã«ããã°ããªã³ã©ã¤ã³ã§CI(ç¶ç¶çã¤ã³ãã°ã¬ã¼ã·ã§ã³)ãã¦ããããµã¼ãã¹ã§ããæè¿ã¯Travis CIã®ä»ãCircleCIãwerckerãdrone.ioãªã©ãå¤ããªãªã¼ã¹ããã¦ãã¾ãã
CIãã¼ã«ã¨ããã°ãJenkinsãæãæµ®ãã¹ã人ãå¤ãããåèªèº«ãä»äºã§Jenkinså çã«ã¯æ¥é ãããä¸è©±ã«ãªã£ã¦ããå®çªãã¼ã«ã§ãããèªåã§Jenkinsãã¤ã³ã¹ãã¼ã«ããããã©ã°ã¤ã³å ¥ãããç´°ããè¨å®ãããã®ãå¤ããå人éçºç¨ã«ä½¿ãã®ã¯æ·å± ãé«ããªã¨æãã¾ãã
ãã®ç¹ããªã³ã©ã¤ã³CIãµã¼ãã¹ã ã¨ãããã¤ããã®ã«å¿ è¦ãªãã¼ã«ãªã©ãç¨æããã¦ãããè¨å®ãã¡ã¤ã«ããªãã¸ããªã«ç½®ãã ãã§å®è¡ãããã¨ãã§ãã¦ãã¾ãã¾ããã¾ããå種ãã¼ã«ãã¢ããã°ã¬ã¼ãããããªã©ã¡ã³ããã³ã¹ããå¿ è¦ããªãã®ã大ããªã¡ãªããã§ãã
å¤ãã®ãªã³ã©ã¤ã³CIãµã¼ãã¹ãããã¾ãããä»åã¯æ¬¡ã®çç±ã§Travis CIã使ã£ã¦ã¿ã¾ããã
- Travis CIã使ã£ã¦ããåèè¨äºãå¤ã調ã¹ããã
- Travis CIã¨Herokuã®é£æºæ¹æ³ãç°¡åãã
- åèURL : Travis CI: Heroku Deployment
- ãããªãã¯ãªãªãã¸ããªãªãç¡æã§ã§ãã
- 大æµã®CIãµã¼ãã¹ã¯ãããªãã¯ãªãªãã¸ããªã ã¨ç¡æãå¤ãã§ã
- ãã©ã¤ãã¼ããªãªãã¸ããªã§ãwerckerã ã¨ç¡æãªã®ã§ä»å¾è©¦ãã¦ã¿ããã§ã
ã§ã¯ãå®éã«è¨å®ãã¦ããã¾ãã
ãã¼ã«ã«ç°å¢ã§ãã¹ããéãããã«ãã
ä½ã¯ã¨ãããããã¹ããéããªãã¨ãããã¤ãéããªãã®ã§ãã¾ããã¹ããéãããã«ãã¾ãã
ãã¹ãã³ã¼ããç¡ã人ã¯ãã¹ãã³ã¼ããæ¸ãã¦ãã ããã
$ cd ./symfony2
$ phpunit -c app
ãã¹ããéã£ããä¸æ¦ãGitHubã«Pushãã¦ããã¾ãã
$ git push origin master
Travis CIã¨GitHubãé£æºãã
ãã©ã¦ã¶ä¸ã§æä½ãã¾ãã
- Travis CIã«GitHubã¢ã«ã¦ã³ãã§ãã°ã¤ã³ãã
- å³ä¸ã®ã¢ã«ã¦ã³ãå âãAccountsããã¯ãªãã¯ãã
- Travis CIã¨é£æºããããªãã¸ããªã®å³å´ã®ã¹ã¤ããããONãã«ãã
ããã表示ããã¦ããªãå ´åã¯ããSync nowããã¿ã³ãã¯ãªãã¯ãã
Herokuã®APIãã¼ãæå·åãã
Travis CIã§Herokuã¸ãããã¤ããéã«APIãã¼ãå¿ è¦ã§ãããå¾è¿°ããè¨å®ãã¡ã¤ã«(.travis.yml)ã«APIãã¼ããã®ã¾ã¾è¨è¿°ããã®ã¯ã»ãã¥ãªãã£çã«å±éºãªã®ã§æå·åãã¾ãã
travisã³ãã³ããå¿ è¦ãªã®ã§ã¤ã³ã¹ãã¼ã«ãã¾ãã
$ gem install travis
$ travis --version
1.6.16
Herokuã®APIãã¼ãåå¾ãã¾ãã
$ heroku auth:token
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"ãçã®APIãã¼ã§ãã
Herokuã®APIãã¼ãæå·åãã¾ãã
$ travis encrypt -r [ãªãã¸ããªå] HEROKU_API_KEY=[Herokuã®APIãã¼]
# e.g.
$ travis encrypt -r ohsawa0515/heroku-symfony2 HEROKU_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
secure: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
"XXX..."ãæå·åãããHerokuã®APIãã¼ã¨ãªãã¾ãã
.travis.yml ãç·¨éãã¦git pushãã
Travis CIã®è¨å®ãè¨å®ãã¡ã¤ã«(.travis.yml)ã§è¡ãã¾ãã
Composerã§Symfony2ãã¤ã³ã¹ãã¼ã«ããã¨ãã§ã«.travis.yml ãå
¥ã£ã¦ãããããããã使ãã¾ãã
# è¨èªãPHPã«æå®ãã¾ã
language: php
# PHPã®ãã¼ã¸ã§ã³ãæå®ãã¾ã
# è¤æ°ãã¼ã¸ã§ã³ãæå®ããã¨ãããããã®ãã¼ã¸ã§ã³ã«å¯¾ãã¦Travis CIã®ãã«ããå®è¡ããã¾ã
php:
- 5.5
# CIãã対象ã®ãã©ã³ããæå®ãã¾ã
# PullRequestããããã©ã³ãã¯ä¾å¤ã§ãã©ããªãã©ã³ãã§ããã«ããå®è¡ããã¾ã
branches:
only:
- master
- develop
# CIããåã«å®è¡ãããã³ãã³ããªã©ãæå®ãã¾ã
before_script:
# ã»ãã·ã§ã³ç®¡çã«Memcachedã¢ã¸ã¥ã¼ã«ã使ã£ã¦ãããããã¢ã¸ã¥ã¼ã«ãã¤ã³ã¹ãã¼ã«ãã¦ãã¾ã
- printf "\n" | pecl install memcached
- echo "extension=memcached.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
# composer.jsonã«è¨è¼ããã¦ããã¢ã¸ã¥ã¼ã«ãªã©ãã¤ã³ã¹ãã¼ã«ãã¾ã
- composer install -n --dev
# CIããéã«å®è¡ãããã³ãã³ããæå®ãã¾ã
# ããã§PHPUnitãå®è¡ãã¦ãã¾ã
script:
- mkdir -p build/logs
- phpunit -c app
# ãã¹ãå®è¡å¾ã«ãããã¤å
ãè¨å®ãã¾ã
deploy:
# ãããã¤å
ãHerokuã«æå®ãã¾ã
provider: heroku
# å
ã»ã©æå·åããHerokuã®APIãã¼ãæå®ãã¾ã
api_key:
secure: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
# ãããã¤ããããã©ã³ãã¨Herokuã®ã¢ããªã±ã¼ã·ã§ã³ãæå®ãã¾ã
# æå®ãã以å¤ã®ãã©ã³ãã§ã¯Herokuã«ãããã¤ããã¾ãã
app:
# developãã©ã³ãã§heroku-symfony2-0515ã¨ããHerokuã¢ããªã±ã¼ã·ã§ã³ã«ãããã¤ãã
develop: heroku-symfony2-0515
ããã§å®éã«åãã確èªãã¦ã¿ã¾ãã
$ git add -A && git commit -m "add heroku deploy"
$ git push origin master
GitHubã«$ git push
ããã¨èªåçã«Travis CIã§ãã«ããå®è¡ããããã¹ããæ£å¸¸ã«éãã¨Herokuã«ãããã¤ãããããã«ãªãã¾ãã
æ£å¸¸ã«çµäºããã¨ã以ä¸ã®å³ã®ããã«"passed"ã«ãªãã¾ãã
Coverallsã¨é£æºãã
次ã«ãã¹ãã®ã«ãã¬ãã¸ãã¬ãã¼ããã¦ãããCoverallsã¨é£æºãã¦ã¿ã¾ãã
é£æºããããã«ã¯ãCoveralls ã«ã¢ã¯ã»ã¹ããGitHubã¢ã«ã¦ã³ãã§ãµã¤ã³ã¤ã³ãã¾ãã
ãªãã¸ããªä¸è¦§ã表示ãããã®ã§ãã³ã¼ãã«ãã¬ãã¸ã表示ãããããªãã¸ããªãONã«ããã°ã¢ã«ã¦ã³ãä¸ã®é£æºã¯å®äºã§ãã
composerã§php-coverallsãã¤ã³ã¹ãã¼ã«
Coverallsã使ãã«ã¯APIã使ãå¿ è¦ãããã®ã§ãããPHPã§Coverallsãå®è¡ãã¦ãããphp-coverallsã使ãã¾ãã
# composer.json
{
"require-dev": {
# 以ä¸è¿½è¨
"satooshi/php-coveralls": "dev-master"
}
}
composer install
ãcomposer update
ããã°ã¤ã³ã¹ãã¼ã«ã¯å®äºã§ãã
app/phpunit.xml.dist ãç·¨éãã
ã«ãã¬ãã¸ãåç
§ã§ããããã«app/phpunit.xml.dist
ãç·¨éãã¾ãã
<?xml version="1.0" encoding="UTF-8"?>
<!-- http://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit
backupGlobals = "false"
backupStaticAttributes = "false"
colors = "true"
convertErrorsToExceptions = "true"
convertNoticesToExceptions = "true"
convertWarningsToExceptions = "true"
processIsolation = "false"
stopOnFailure = "false"
syntaxCheck = "false"
bootstrap = "bootstrap.php.cache" >
<testsuites>
<testsuite name="Project Test Suite">
<directory>../src/*/*Bundle/Tests</directory>
<directory>../src/*/Bundle/*Bundle/Tests</directory>
</testsuite>
</testsuites>
<!-- è¿½è¨ -->
<logging>
<log type="coverage-clover" target="../build/logs/clover.xml"/>
</logging>
<!-- 追è¨çµãã -->
<!-- ...以ä¸çç¥ -->
</phpunit>
Symfony2ã®å ´åãphpunit.xml.dist
ãapp/
以ä¸ã«ãããããtargetã®ãã¹(../build/logs/clover.xml
)ã«æ³¨æãã¦ãã ããã
.travis.yml ãç·¨éãã
å
ã»ã©ã®.travis.yml
ãç·¨éãã¾ãã
language: php
php:
- 5.5
branches:
only:
- master
- develop
before_script:
- printf "\n" | pecl install memcached
- echo "extension=memcached.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
- composer install -n --dev
script:
- mkdir -p build/logs
- phpunit -c app
# 以ä¸ã追è¨
- php vendor/bin/coveralls -v
deploy:
provider: heroku
api_key:
secure: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
app:
develop: heroku-symfony2-0515
README.mdã«ã¯ãafter_script
ã«è¨å®ãã¦ãã¾ãããafter_script
ã ã¨Herokuã§ãããã¤ããå¾ã«å®è¡ããã¦ãã¾ããä½æ
ãåããªãã£ãã®ã§ãscript
ã«æ¸ãã¾ããã
.coveralls.yml ãä½æãã
Coverallsã®è¨å®ã.coveralls.yml
ã«è¨è¿°ãã¦ãSymfony2ãã£ã¬ã¯ããªç´ä¸(.travis.yml
ã¨åãé層)ã«ç½®ãã¾ãã
service_name: travis
src_dir: src
coverage_clover: build/logs/clover.xml
json_path: build/logs/coveralls-upload.json
exclude_no_stmt: true
ãã¼ã«ã«ã§Coverallsãå®è¡($ php vendor/bin/coveralls -v
)ããå ´åãrepo_token
ã¨ãããã©ã¡ã¼ã¿ã«Coverallsã«ãã¼ã¯ã³ãè¨å®ãã¾ãããTravics CIçµç±ã§å®è¡ããå ´åã¯repo_token
ãã©ã¡ã¼ã¿ãè¨å®ãã¾ããã
ãã®è¾ºããåéããã¦repo_token
ã«ãã¼ã¯ã³ãè¨å®ããç¶æ
ã§ãããã¤ããéãTravis CIã®ãã°ã«ãRequirements are not satisfied.ãã¨è¡¨ç¤ºãããCoverallsã®æ¹ãã«ãã¬ãã¸ã表示ããã¾ããã§ãããçµå±ãphp-coverallsã®ã½ã¼ã¹ãè¦ã¦ãã£ã¨åå ãçªãæ¢ãã¾ããã
ããã§ãªãã¸ããªã«Commitãã¦GitHubã«Pushããã°ãTravis CIã®ãã«ãå®è¡å¾ã«Coverallsã§ãã¹ãã«ãã¬ãã¸ã表示ãããããã«ãªãã¯ãã§ãã
ãããªé¢¨ã«ã«ãã¬ãã¸ã表示ãããããã«ãªãã¾ããã«ãã¬ãã¸ã16%ã¨ä½ãã®ã¯ãã¢ç¨ã«ä½ã£ãã³ã¼ãã ããã§ã(ã¨è¨ã訳ãã¦ã¿ã)ã
"BUILD"åã"COMMIT"åã®ãªã³ã¯å ãã¯ãªãã¯ããã¨ãã«ãã¬ãã¸ã®è©³ç´°ã表示ããã¾ãããã¡ã¤ã«ä¸è¦§ã表示ã§ãã¦ãã¹ããã©ã®ãããã«ãã¼ã§ãã¦ããããåããããã«ãªã£ã¦ãã¾ãã
ãã¡ã¤ã«ã®ãªã³ã¯å ãã¯ãªãã¯ããã¨ããã®ãã¡ã¤ã«å ã®è©³ç´°ãè¦ããã®ã§ãã・・・
ãã¹ãééã£ã¦ããã®ã表示ããã¾ããã
ããã§ããGit repo root directoryãã空ã«ãã¦ããGit repo sub directoryãã«ãsrcãã¨å
¥åãã¦UPDATEãã¾ãã
ãã¹ãåãã°ãã½ã¼ã¹ã³ã¼ãã表示ãããè¡åä½ã§ãã¹ããã«ãã¼ããç¯å²ãåããããã«ãªãã¾ãã
赤ãè¦ããã¦ããè¡ã¯ãã¹ããã«ãã¼ãã¦ããªãè¡ã§ãã
æå¾ã«
GitHubãTravis CIãCoverallsã¨é£æºãã¦Symfony2ã¢ããªã±ã¼ã·ã§ã³ãHerokuã«ãããã¤ããããã«è¨å®ã§ãã¾ããã
ä»ã«ãã©ã¤ãã©ãªã®ãã¼ã¸ã§ã³ã¢ãããéç¥ãã¦ãããversioneyeãã¢ããªã±ã¼ã·ã§ã³ã®ã½ã¼ã¹ã³ã¼ããã¹ãã£ã³ãã¦èå¼±æ§ã診æãã¦ãããSensioLabsInsightãªã©ããããèªåã§ä¸ããç°å¢ãæ§ç¯ããªãã¦ãããã«éçºã§ãã¦ãã¾ãç°å¢ãã§ãã¦ã¨ã¦ã便å©ã§ããã
å¤ãã®ãµã¼ãã¹ããªãªã¼ã¹ãããéçºå¹çãåä¸ã§ããæ©ä¼ãå¢ãã¦ããã®ã§ãæ¥é ããæ å ±åéãã¦ä¹ãé ããªãããã«ããããã®ã§ãã