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

Docker + Jenkinsでバッチ実行 / Using Docker and Jenkins execution batch

Docker + Jenkinsでバッチ実行 / Using Docker and Jenkins execution batch

2018.4.11 社内勉強会で発表した
Batch実行環境のスライド

9a71d9081335ef7d5ecfa86155c949af?s=128

yutachaos

April 12, 2018
Tweet

Transcript

  1. Jenkins + Docker 
 Batch࣮ߦ 2018/4/11
 
 ໦ଜ༐ଠ

  2. Batch࣮ߦͷྲྀΕ scheduled trigger (ఆظ࣮ߦ) Batch࣮ߦ༻ͷEC2 Jenkins༻ͷEC2 1. docker image pull


    (imageͷऔಘ) ECR 2. docker-compose run (batchॲཧͷ࣮ߦ) DB ,S3 ͳͲ 3. log͸CloudWatch logsʹग़ྗ
  3. Batchશମͷ࣮ߦͷྲྀΕ • Batchࣗମͷδϣϒεέδϡʔϥʔ؅ཧ͸JenkinsΛར༻ • EC2্ʹJenkinsΛઃఆͯ͠ར༻
 (ͦͷ͏ͪJenkins΋DockerԽ͍ͨ͠ɾɾɾ) • ֤BatchͷJobͷ੍ޚʹPipelineΛར༻

  4. Jenkins Pipelineͱ͸ • Jenkins2͔Βඪ४ར༻ग़དྷΔΑ͏ʹͳͬͨ(چpipeline plugin) • ֤Jobͷॲཧͷॱ൪΍ґଘؔ܎Λ੔ཧɾ࣮ߦ͢ΔͨΊͷػೳ • git؅ཧͯ͠ɺgit͔Β௚઀ϑΝΠϧΛಡΈग़࣮ͯ͠ߦ΋Մೳ •

    ॲཧ಺༰ΛGroovyͰॻ͘͜ͱ͕ग़དྷΔͷͰಈతͳॲཧ΋هड़ग़དྷΔ • pipelineܗࣜͰॻ͘ͱɺjobͷ಺༰͕visualize͕ग़དྷΔ(·ͩΠϚΠνͳ෦෼΋ ଟ͍͕ɺɺɺ) • doc • https://jenkins.io/doc/book/pipeline/

  5. Jenkinsfile ײ૝ • ೉͍͠ॴ • ৘ใ͕গͳ͍ͷͰֶशίετ͕͋Δ • ·ͩ৽͍͠ͷͰɺػೳͷมԽ͕ૣ͍ • ྑ͔ͬͨॴ

    • ίʔυϕʔεͰJobͷґଘੑΛॻ͚Δ • pipelineͷܗͰJobΛهࡌ͢ΔͱɺJobͷґଘੑ͕ݟ΍͍͢ • ScriptͰಈతͳparameter΋࡞੒ग़དྷΔ
  6. Batch࣮ߦ؀ڥ

  7. • ࣮ߦ؀ڥ͸DockerΛར༻ • Docker Imageͷbuild͸CircleCIͰߦ͍ɺECRʹpush͢Δ • Jenkins͔ΒDocker͕ೖ͍ͬͯΔEC2ʹରͯ͠ɺDockerΛىಈɺ Docker্ͰBatchΛ࣮ߦ Batchͷ࣮ߦ؀ڥ

  8. Docker BuildͷྲྀΕ Github Developer CircleCI ECR (Elastic Container Registry) git

    push build trigger docker push githubͷίʔυΛར༻ͯ͠ɺ
 dockerͷimageΛbuildΛߦ͏
  9. Dockerͷར༻ํ๏ • ֤RepositoryͰ͸DockerΛར༻ͯ͠։ൃ • MasterʹMerge͞ΕͨΒɺCircleCIͰDockerͷImageΛbuild,ECRͰ push͢ΔΑ͏ʹ͍ͯ͠Δ • BatchͰ͸ECR্ʹPush͞ΕͨImageΛར༻ͯ͠ɺEC2্ͰdockerΛ ىಈɺॲཧΛ࣮ߦ

  10. Batch࣮ߦ؀ڥͷ·ͱΊ • ೉͍͠ॴ • DockerΛར༻ͨ͠ࡍͷ؀ڥ৘ใͷ੔ཧ • 12 factors appతʹ͸؀ڥม਺ʹ੾Γग़͢ͷ͕ͩɺ؅ཧ͕େม •

    Parameter StoreΛ࢖ͬͯΈ͕ͨɺ·ͩ࢖͍ͮΒ͔ͬͨͷͰࠓճ͸அ೦͠·͠ ͨɻɻɻ • ྑ͔ͬͨॴ • DockerΛར༻ͨ͠෦෼ • ࣮ߦ؀ڥͷґଘΛ੔ཧ͠΍͘͢ͳͬͨ • Docker͑͞ೖ͍ͬͯΕ͹ɺಉ͡αʔόʔ্Ͱ৭ʑͳݴޠΛಈ͔ͤͨ • CloudWatch Logs΁ͷઃఆ͕͠΍͍͢
  11. ͋Γ͕ͱ͏͍͟͝·ͨ͠