ç§ãã¡ã®äŒç€Ÿã§CI / CDãã»ããã¢ããããçµéšãå ±æããåæ§ã®ãããžã§ã¯ãæ§é ããæã¡ã®å Žåã¯ãã³ãããèãããããšæããŸãã
誰ã«ããã®èšäºã¯åœ¹ã«ç«ã€ãããããŸããïŒ
- ãããžã§ã¯ãã«ã¯ãããã€ãã®åå¥ã®ã¢ããªã±ãŒã·ã§ã³ãªããžããªãå«ãŸããŠããŸãã
- åãªããžããªããã¹ãã«åæ Œããããšã確èªããå¿ èŠããããŸãã
- ãªããžããªéã®ããŒãžã§ã³ã®äºææ§ã確èªããå¿ èŠããããŸãã
- ãŸã æéããããŸãããããããžã§ã¯ããdockerã«è»¢éããããšãèšç»ããŠãã ããã
- Ansibleãã¬ã€ããã¯ãããã€ãèŠããã§ãã
Docker And Ansibleã䜿çšããç¶ç¶çé ä¿¡ã匷ããå§ãããŸãã ç§ãã¡ã¯ãœãªã¥ãŒã·ã§ã³ã®éçºã«åºã¥ããŠããŸããã
CI / CDã®ã¿ã¹ã¯
å¹³åããŠç§ãã¡ã®ãããžã§ã¯ãã®1ã€ã¯ãrest-apiãä»ããŠçžäºäœçšãã4ã5åã®ãªããžããªã§ãã ããããã€ã¯ããµãŒãã¹ã¢ãŒããã¯ãã£ãšèŠãªããããã©ããã¯å®ãã§ã¯ãããŸãããããããèæ ®ããŠãCI / CDã«å¯ŸããŠæ¬¡ã®ã¿ã¹ã¯ãèšå®ããŸãã
- åã¡ã€ã³ãã©ã³ãã®åãªããžããªã«ã¯ãåäœããïŒãã¹ãæžã¿ã®ïŒã³ãŒããå¿ èŠã§ãã
- åãã©ã³ããšåã¿ã°ã¯ããããžã§ã¯ãå ã®ãã¹ãŠã®ãªããžããªéã§å®å šã«äžè²«ããŠããå¿ èŠããããŸãã
- éçºçšã®ãªããžããªãå®å šã«ãŸãã¯åå¥ã«ããŒã«ã«ã«ãããžã§ã¯ããå±éã§ããå¿ èŠããããŸãã
- ãã¹ããã¹ããŒãžã³ã°ãå®çšŒåãªã©ãããŸããŸãªç°å¢ã§ãããžã§ã¯ããå±éã§ããå¿ èŠããããŸãã
ããã§ã¯å§ããŸãããã
CI / CDã»ããã¢ãã
æºå段é
- git-flowã«åãæ¿ããŸããã ã«ã¹ã¿ã vcsã¯ãŒã¯ãããŒã¯ããã¯ã©ã·ãã¯ããšæ¯èŒããŠãç¹ã«åå¿è ã«ãšã£ãŠåé·ã§è€éã§ããããšãããããŸããã
- æ¯é±ã®ã¹ããªã³ãã¯è£œåã®æ°ããããŒãžã§ã³ã§ãã ã¿ã¹ã¯ãããŒãžã£ãŒã®åã¿ã¹ã¯ã¯ãããããã°ã§ããããšæ©èœã§ããããšãç¹å®ã®ããŒãžã§ã³ã«é¢é£ä»ããããŸãã ã¹ããªã³ãã®æåŸã«ããåãªããžããªã«ã¯ããã®ããŒãžã§ã³ã®ãã®ã«ãã§äœãããªãã£ãå Žåã§ããæ°ããããŒãžã§ã³ã®ã¿ã°ããããŸãã äŸå€ã¯ãã¹ããªã³ãã®ããã«ãããžã§ã¯ãã®ãªããžããªãå€æŽãããŠããªãå Žåã§ãã
- ããŒã«èŠæ±ãä»ããŠã®ã¿ããã¹ã¿ãŒã«çŽæ¥ããã·ã¥ãããã©ã³ããéçºããã³ãªãªãŒã¹ããããšãçŠæ¢ããŸããã
- Jenkinsã§ã®ã¢ã»ã³ããªãšãã¹ãã®ããã«ãäžèšã®ãã©ã³ãã®ããŒã«ãªã¯ãšã¹ãã«ããã¯ãæããŸããã
- Jenkinsã«ãããã¹ãã«æåãããCode Reviewã®æ¿èªããªãã«ãããŒã«ãªã¯ãšã¹ãã®ããŒãžãçŠæ¢ããŸããã
CIããŒã«ãšããŠããŠããããã¹ããšAPIçµ±åãã¹ããå®è¡ããJenkinsãéžæããŸããã
CDããŒã«ãšããŠ-Ansible + Dockerã
æåã®ã¹ããããå¥åã®ãªããžããªãŒã®ã»ããã¢ãã
ãããžã§ã¯ãå ã®åãªããžããªã®æ§é ãå€æŽããŸããã
app |-src |-docker | |-ci | |-develop | |-release |-requirements |-Jenkinsfile |-Makefile
ããŒã«ãªã¯ãšã¹ãã«èšå®ãããããã¯ã¯ãJenkinsã«ãªããžããªã®ãã¹ããå¿ èŠã§ããããšãäŒããŸãã Jenkinsã¯Jenkinsfileãæ€çŽ¢ããŠå®è¡ããŸãã åŸè ã¯ãMakefileã³ãã³ããé çªã«åŒã³åºããŠãã³ã³ãããæ§ç¯ããŠãã¹ãããŸãã Makefileã¯ãã / docker / ciãã£ã¬ã¯ããªããdocker -composeã³ãã³ããå®è¡ããŸãã JenkinsfileããçŽæ¥å®è¡ããããã«docker-composeãæ§æããŠããªãã®ã¯ãªãã§ããïŒ ãã¹ãŠã®ãªããžããªã®æ±çšæ§ãç¶æããããã ããªãã¡ ãªããžããªãç°ãªããšãã«ããšå®è¡ã«ç°ãªãdocker-composeã³ãã³ããå¿ èŠã«ãªãããããã®éãã¯Makefileã§èšå®ãããŸããJenkinsfileã®ãã«ããšå®è¡ã®ã€ã³ã¿ãŒãã§ã€ã¹ã¯åžžã«åãã§ãã
NBã èšäºã®æåŸã«ãäŸã®ãããªããžããªãžã®ãªã³ã¯ããããŸãã
ãŸããMakefileã«ã¯ãéçºã¢ãŒãã§ãªããžããªãããŒã«ã«ã§ã¢ã»ã³ãã«ããã³èµ·åããããã®ã³ãã³ãããããŸã-ãã¹ããã·ã³ããDockerãžã®ãœãŒã¹ã®è»¢éãæ§æãããŠãããæ°ããå€æŽã確èªããããã«makeã³ãã³ãã䜿çšããŠè¡ãå¿ èŠãããã®ã¯ãdocker-composeã®ã¿ã§ãã Makefile + ./docker/developããããæ åœããŸãã
./docker/releaseã«ã¯ããã¹ã/ã¹ããŒãžã³ã°ç°å¢ãªã©ã®ãªããžããªã¢ã»ã³ããªèšå®ããããŸããèšå®ã¯åŸã§äœ¿çšãããŸãã
2çªç®ã®ã¹ãããã è¿œå ã®devopsãªããžããªãŒã®ã»ããã¢ãã
äžè¬çãªãªããžããªã®ç®çã¯ããããžã§ã¯ãã«å«ãŸãããªããžããªãå±éãããšãã«ãããžã§ã¯ãã®æŽåæ§ãä¿æããããšãšãçµ±åãã¹ãã®å¯èœæ§ãç¶æããããšã§ãã
ãªããžããªæ§é
devops |-ansible | |-plays | |-roles |-projects | |-project_1 | | |-apps | | | |-app_1 | | | |-app_2 | | | |-app_3 | | | |-... | | |-docker | | | |-ci-api | | | |-ci-selenium-gherkin | | | |-develop | | | |-testing | | | |-staging | | | |-production | | |-Makefile |-requirements |-Jenkinsfile |-Makefile
ãŸãããã®ãªããžããªãçµ±åãã¹ããå®è¡ããæ¹æ³ã
æãç°¡åãªããšã§ã¯ãããŸããããç§ã¯èª¬æããããšããŸãã
ã¢ããªã±ãŒã·ã§ã³ã®ãããªããžããªã®å Žåãšåæ§ã«ãããŒã«ãªã¯ãšã¹ãäžã«ãã«ãããã³ãã¹ãã³ãã³ããå®è¡ããJenkinsfileããã³Makefileãã¡ã€ã«ããããŸãã ãã«ãèšå®ã¯./projects/PROJECT/docker/ci-apiã«ãããŸãããPROJECTãã¯çŸåšã®ãããžã§ã¯ãã®ååã§ãã ã¢ã»ã³ããªã«ã¯ãç®çã®ãã©ã³ã/ã¿ã°å ã®åãªããžããªã®ã¯ããŒã³äœæãapiãã¹ã¿ãŒã³ã³ããã®èµ·åãå«ãŸããŸãã
ãå¿ èŠãªãã©ã³ã/ã¿ã°ãã¯ããã¹ãŠã®ãªããžããªã®äžè¬çãªãã©ã³ãïŒãã¹ã¿ãŒãéçºããªãªãŒã¹ïŒããŸãã¯ãããžã§ã¯ãã®ã¿ã°ããŒãžã§ã³ã®ããããããã¹ãããããšããŠããŸãã ã¿ã°ã¯åãªããžããªã«é 眮ããå¿ èŠããããŸãã 次ã«ããå¿ èŠãªããã®ãšäžèŽããååã§devopsãªããžããªãŒã«ãã©ã³ããäœæããŸãã ãã®åŸãããŒã«ãªã¯ãšã¹ããè¡ãããšãã§ããŸãã
Jenkinsã¯ãéžæããã¿ã°/ãã©ã³ãã«ãã£ãŠãããžã§ã¯ãããã«ãããããšããŸãããªããžããªã«ãªããžããªããªãå Žåããã¹ãã¯å€±æããŸãã ãããžã§ã¯ãã®çµã¿ç«ãŠã«æåãããšãããã¹ããã¬ãŒã ã¯ãŒã¯ããèµ·åããŸãããã®ãã¹ããã¬ãŒã ã¯ãŒã¯ã§ã¯ãPostmanãšãã®ãŠãŒãã£ãªãã£ãã³ãã³ãã©ã€ã³ïŒNewmanïŒã«äœ¿çšããŸãã ãã¹ããæåããå Žå-åºåã§ãããŒã«ãªã¯ãšã¹ããããŒãžãããã¹ãæžã¿ã®ã¿ã°ãdevopsãªããžããªã«é 眮ããŸãã ãã®ã¿ã°ã®ååšã¯ããããžã§ã¯ãã®ãã®ããŒãžã§ã³ããã¹ããããŠããããšã瀺ããŠããŸãã
Postmanãã¹ããå®è¡ããã«ã¯ã ã³ãã³ãã³ã³ãããŒã«æ¿å ¥ãããå ±æã³ã¬ã¯ã·ã§ã³ãžã®ãªã³ã¯ãå¿ èŠã§ãã
ãããå¯äžã®ã¿ã€ãã®çµ±åãã¹ãã§ãããå°ãåŸã§gherkinãŸãã¯seleniumã«ãããã¹ããè¿œå ããŸããå°ãªããšãdocker / ci-selenium-gherkinãã£ã¬ã¯ããªã¯ãã§ã«ååšããŸãã
次ã«ããã®ãªããžããªã®CDæ©èœã«ã€ããŠèª¬æããŸãã
ããã§ã. /ansibleã«ã¯ãç»åå šäœãçµã¿ç«ãŠãŠç°ãªããµãŒããŒãç°å¢ã«é ä¿¡ããããã®ãããžã§ã¯ãå šäœã®ã³ã³ãããŒã«ããã«ããããŸãã
- developer.yml-ãããžã§ã¯ãå šäœãããŒã«ã«ã«ãããã€ããããã®èšå®ã
- make-images.yml-ç¹å®ã®ããŒãžã§ã³ã®ãããžã§ã¯ãã§dockerã€ã¡ãŒãžãäœæããdockerã¬ãžã¹ããªã«ããã·ã¥ããŸãã
- deploy-and-run-images.yml-ç°ãªãç°å¢ã®ãµãŒããŒãžã®ãããžã§ã¯ãã®å±éã
å段èœã®å é ã«ã¯ããã®ã¹ã¯ãªãããå®è¡ãããã¬ã€ããã¯ããããŸãã
ãããã¯ã³ãã³ãã«ãã£ãŠéå§ãããŸãïŒ
$ ansible-playbook -i ../testing.ini make-images.yml -e 'project=todo ver=2017.1' - -i ../testing.ini -- inventory, , - make-images-yml -- playbook - -e 'project=todo ver=2017.1' -- , playbook, .
./ansible/plays/group_vars/all.ymlã«ã¯ãããžã§ã¯ãèšå®ããããŸãïŒ
- ãã®ãããžã§ã¯ãã«å±ãããªããžããªã
- ã©ã®docker-registryã䜿çšããããã©ã®ãã°ã€ã³ãã¹ã¯ãŒãã䜿çšãããã
- ç°å¢ããšã®åå¥èšå®ãªã©
ã芧ã®ãšããããã®ãªããžããªã¯å®å šã«1ã€ã®ãããžã§ã¯ãå°çšã§ããããããžã§ã¯ãåããã¬ã€ããã¯ã®ãã©ã¡ãŒã¿ãŒã«æž¡ãããããžã§ã¯ããã£ã¬ã¯ããªã¯ãããžã§ã¯ããã£ã¬ã¯ããªã«ãããŸãã ããã¯ããã®devopsãªããžããªãmaster-devopsãªããžããªããã®ãã©ãŒã¯ã§ãããä»ã®ãããžã§ã¯ãã®devopsãªããžããªããã©ãŒã¯ãããŠãããšããäºå®ã«ãããã®ã§ãã ãŸããåæ§ã®æ§é ã«ãããäœããå£ããªã¹ã¯ãªãã«ããã¹ã¿ãŒãã©ãŒã¯éããã³ãã©ãŒã¯èªäœã®éã§äžè¬çãªèšå®ãšç¡å¹ãªã³ãã³ãã®ã³ãŒãã亀æã§ããŸãã ããæ£ç¢ºã«ã¯ãansibleãã£ã¬ã¯ããªã¯å ±æããããã®ãªãã¡ã¯ã¿ãªã³ã°ã¯ãã¹ã¿ãŒãããã©ãŒã¯ãžããŸãã¯ãã®éã«ç°¡åã«è»¢éã§ããŸãã ãŸãããã¹ãŠã®ãã©ã€ããŒããããžã§ã¯ãèšå®ã¯ããããžã§ã¯ãå ã®åå¥ã®ãã£ã¬ã¯ããªã«ãããŸãã ãã¹ã¿ãŒãŸãã¯é£æ¥ããdevopsãªããžããªããã®ããŒã«ã¯ãçŸåšã®ããŒã«ãšç«¶åããŸããã
Dockerfileãé 眮ãããŠããã¢ããªã±ãŒã·ã§ã³ã®docker / releaseãã£ã¬ã¯ããªã«æ»ããŸãããã®ãã£ã¬ã¯ããªã¯ããã¹ã/ã¹ããŒãžã³ã°ããã³å®çšŒåç°å¢ã®ã¢ã»ã³ããªãæ åœããŸãã éçºä»¥å€ã®ãã¹ãŠã®ããã«ã 1ã€ã®ãªããžããªã®ãªãªãŒã¹ã¢ã»ã³ããªã ãã§ã¯ãä»ã®ãããžã§ã¯ããªããžããªãšçµã¿åãããå Žåã«ã®ã¿ãæçšãªãã®ã¯æäŸãããŸããã Ansibleã¯ãdevelop-buildã®å Žåã¯åãããžã§ã¯ãã®docker / developerãã£ã¬ã¯ããªãããDockerfileã¯ãªãªãŒã¹ç°å¢ã®ãã«ãïŒ docker / releaseãã£ã¬ã¯ããªïŒããååŸããããã«æ§æãããŠããŸãã
åèšãç§ãã¡ã¯äœãšãããããšãã§ããŸããïŒ
- ãªããžããªã®ã¯ããŒã³ãäœæããéçºããŒãžã§ã³ãå®è¡ããæ©èœ
- åãªããžããªã¯Jenkinsã«ãã£ãŠãã§ãã¯ãããŸãã
- äžè¬ããŒãžã§ã³ã«åŸã£ãŠããã¹ãŠã®ãªããžããªã«ããã£ãŠçµ±åãã¹ããå®è¡ããå ±éãªããžããªããããŸãã
- ansibleãã¬ã€ããã¯ïŒããŒã«ã«ã«å±éãããã¹ãŠã®ãããžã§ã¯ããªããžããªãéçºã¢ãŒãã§èµ·åããŸãã
- ansibleãã¬ã€ããã¯ïŒéžæãããç°å¢ã¹ããŒã ã«å¿ããŠç»åãåéãããããdocker-registryã«éä¿¡ããŸãã
- ansibleãã¬ã€ããã¯ïŒãµãŒããŒäžã§ãããžã§ã¯ããæ§æããŸãã
- ansibleãã¬ã€ããã¯ïŒãµãŒããŒäžã§ã¢ããªã±ãŒã·ã§ã³ãèµ·åããŸãã
ã·ã¹ãã ãå®èšŒããã¢ããªã±ãŒã·ã§ã³ãžã®ãªã³ã¯ïŒ
- todo_todo-todobackend.comãããžã§ã¯ãããã®ãã©ãŒã¯ã æ§é ãå€æŽãããã¹ããè¿œå ããŸããã todo'shkãäœæããŸãã
- todo_crm-ãŠãŒã¶ãŒãäœæããtodo_todoã«ãªã¯ãšã¹ããéä¿¡ããtodoãäœæããŠãŠãŒã¶ãŒã«ãã€ã³ãããŸãã
- todo_ops-èšå®ãå«ãdevopsãªããžããª