Save 37% off PRO during our Black Friday Sale! »

Gitlab-RunnerからDockerコンテナを起動して テストする構成を用意した

F0e950c6bf20815f3d169f063d3c5d4f?s=47 Aipa
August 27, 2021

Gitlab-RunnerからDockerコンテナを起動して テストする構成を用意した

やらないほうが良い構成なので注意

F0e950c6bf20815f3d169f063d3c5d4f?s=128

Aipa

August 27, 2021
Tweet

Transcript

  1. ͪΌΜ΀Δʔͱʔ͘ ΞΠύʔୂ௕ 2021/07/30

  2. ࣗݾ঺հ

  3. ࣗݾ঺հ • ΞΠύʔʢAipaʣୂ௕ʢຬ31ࡀʣ • ͪΎΒσʔλגࣜձࣾ • ৭ʑ΍ΔਓͰ͢ • ࠷ۙ͸Vue.jsͱҟৗݕ஌ษڧ͍ͯ͠·͢ •

    ΰδϥ͕޷͖Ͱ͢
  4. ࠓ೔࿩͢͜ͱ

  5. ࠓ೔࿩͢͜ͱ ↑ΨΠΨϯ

  6. ࠓ೔࿩͢͜ͱ ʘDockerΝΞΞΞΞΞΞΞΞΞʂىಈʂʂʂʗ ʢ͠ͳ͍ʣ

  7. ࠓ೔࿩͢͜ͱʢਅ໘໨ʣ • VueΛCI؀ڥͰE2EςετͰ͖Δ؀ڥΛ༻ҙ͠ ͍ͨ • Gitlab-Runner͔ΒDockerίϯςφΛىಈͯ͠ ςετ͢Δߏ੒Λ༻ҙͨ͠ • ϋϚͬͨͷͰ஌ݟڞ༗

  8. ߏ੒ʹ͍ͭͯ

  9. ߏ੒ʹ͍ͭͯ Gitlab Gitlab Runner ΅ͨͪ͘ %PDLFSEFBNPO

  10. CI ࣮ߦϑϩʔ

  11. CI࣮ߦϑϩʔ Gitlab ΅ͨͪ͘ $ git push Gitlab Runner %PDLFSEFBNPO

  12. Gitlab ΅ͨͪ͘ ʮgit pushʯΛtriggerʹ pipelineɾjobىಈ Gitlab Runner CI࣮ߦϑϩʔ %PDLFSEFBNPO

  13. Gitlab ΅ͨͪ͘ Gitlab Runner %PDLFSEFBNPO CI࣮ߦϑϩʔ Docker-compose ίϯςφىಈ Docker compose

  14. Gitlab ΅ͨͪ͘ $ git clone CI࣮ߦϑϩʔ Gitlab Runner %PDLFSEFBNPO Docker

    compose
  15. Gitlab ΅ͨͪ͘ Gitlab Runner CI࣮ߦϑϩʔ Docker compose $ docker-compose up

    %PDLFSEFBNPO
  16. Gitlab ΅ͨͪ͘ Gitlab Runner CI࣮ߦϑϩʔ Docker compose ςετ࣮ߦத %PDLFSEFBNPO

  17. Gitlab ΅ͨͪ͘ Gitlab Runner CI࣮ߦϑϩʔ Docker compose ςετͷ݁ՌΛฦ͢ %PDLFSEFBNPO

  18. Gitlab ΅ͨͪ͘ Gitlab Runner CI࣮ߦϑϩʔ Docker compose $ docker-compose down

    $ docker-compose rm ʘόΠόΠʗ ʘ·ͨͶʗʘ͡Ό͋ͷʗ %PDLFSEFBNPO
  19. ΈΜͳͷٙ໰ʢ༧૝ʣ

  20. Gitlab ΅ͨͪ͘ Gitlab Runner %PDLFSEFBNPO ٙ໰ᶃ Docker-compose ίϯςφىಈ Docker compose

    ίϯςφ͔Βίϯςφىಈʁʁʁ
  21. Gitlab ΅ͨͪ͘ Gitlab Runner ٙ໰ᶄ Docker compose $ docker-compose up

    %PDLFSEFBNPO ίϯςφ͔Βίϯςφىಈʁʁʁ
  22. Ͱ͖ΔΜͰ͢

  23. ΍Γํ͸̎ͭ • Docker in Dockerʢdindʣ • Dockerίϯςφ಺͔ΒDockerΛ࢖͏ • Docker outside

    of Docker (dood) • Dockerίϯςφىಈ࣌ʹϗετͷDocker deamonͷ socket fileΛϚ΢ϯτͯ͠ɺϗετͷDocker deamonͱ΍ ΓऔΓͰ͖ΔΑ͏ʹ͢Δ • ͙͙ͬͯΈΔͱͬͪ͜ͷ΄͏͕Gitlab-runnerʹ͸͍͋ͬͯ ΔΑ͏ͳͷͰͬͪ͜ʹͨ͠ • https://jpetazzo.github.io/2015/09/03/do-not-use- docker-in-docker-for-ci/
  24. Πϝʔδ Ҿ༻: Dockerίϯςφ಺͔ΒDockerΛ࢖͏͜ͱʹ͍ͭͯ https://esakat.github.io/esakat-blog/posts/docker-in-docker/

  25. )PTU Gitlab ΅ͨͪ͘ Gitlab Runner %PDLFSEFBNPO ͭ·Γʁ CJOENPVOU WBSSVOEPDLFSTPDL WBSSVOEPDLFSTPDL

  26. Gitlab ΅ͨͪ͘ Gitlab Runner %PDLFSEFBNPO ͭ·Γʁ WBSSVOEPDLFSTPDL Docker-compose ίϯςφىಈ )PTU

    WBSSVOEPDLFSTPDL
  27. Gitlab ΅ͨͪ͘ Gitlab Runner %PDLFSEFBNPO ͭ·Γʁ WBSSVOEPDLFSTPDL Docker-compose ίϯςφىಈ )PTU

    WBSSVOEPDLFSTPDL Docker compose
  28. Gitlab ΅ͨͪ͘ Gitlab Runner %PDLFSEFBNPO ͞Βʹʁ )PTU WBSSVOEPDLFSTPDL Docker compose

    WBSSVOEPDLFSTPDL CJOENPVOU
  29. Gitlab ΅ͨͪ͘ Gitlab Runner %PDLFSEFBNPO ͞Βʹʁ $ docker-compose up )PTU

    WBSSVOEPDLFSTPDL Docker compose WBSSVOEPDLFSTPDL
  30. Gitlab ΅ͨͪ͘ Gitlab Runner %PDLFSEFBNPO ͞Βʹʁ $ docker-compose up )PTU

    WBSSVOEPDLFSTPDL Docker compose WBSSVOEPDLFSTPDL CJOENPVOU
  31. Dockerίϯςφ͔ΒίϯςφΛ ىಈ͢Δ͜ͱ͕Ͱ͖·ͨ͠ ىಈͨͥ͠ʂʂʂ

  32. ϋϚΓͲ͜Ζ ͙͑͑͑͑

  33. Gitlab ΅ͨͪ͘ Gitlab Runner %PDLFSEFBNPO )PTU Docker compose Ͳ͕ͬͪϦϙδτϦΛclone͍ͯ͠Δʁ ᶃ

  34. Gitlab Runner %PDLFSEFBNPO )PTU Docker compose Ͳ͕ͬͪϦϙδτϦΛclone͍ͯ͠Δʁ ͬͪ͜ Gitlab ΅ͨͪ͘

  35. Gitlab Runner %PDLFSEFBNPO )PTU WPMVNF Docker compose Ͳ͕ͬͪϦϙδτϦΛclone͍ͯ͠Δʁ ͬͪ͜ʹॻ͖ࠐ·ΕΔ WPMVNF

    Gitlab ΅ͨͪ͘
  36. Gitlab Runner %PDLFSEFBNPO )PTU WPMVNF Docker compose ϋϚΓϙΠϯτ ͬͪ͜ʹॻ͖ࠐ·ΕΔ WPMVNF

    Gitlab ΅ͨͪ͘ $ docker-compose up WPMVNF WPMVNF ͬͪ͜ ʹ͸ͳ͍ ͬͪ͜ʹ ΋͸ͳ͍ ͬͪ͜ʹ͸ͳ͍ ϓϩδΣΫτͷ ιʔείʔυ͸ʁ ɾТɾʆ ʁ
  37. Gitlab Runner %PDLFSEFBNPO )PTU WPMVNF Docker compose ϋϚΓϙΠϯτ ͬͪ͜ʹॻ͖ࠐ·ΕΔ WPMVNF

    Gitlab ΅ͨͪ͘ $ docker-compose up WPMVNF WPMVNF ͬͪ͜ ʹ͸ͳ͍ ͬͪ͜ʹ ΋͸ͳ͍ ͬͪ͜ʹ͸ͳ͍ ϓϩδΣΫτͷ ιʔείʔυ͸ʁ ɾТɾʆ ʁ ಈ͔ͳ͍
  38. Gitlab Runner %PDLFSEFBNPO )PTU WPMVNF Docker compose Ϛ΢ϯτ͢Ε͹͑͑΍Μ WPMVNF Gitlab

    ΅ͨͪ͘ $ docker-compose up WPMVNF WPMVNF ͍ͭ΋ͷ W QXE CVJMETHSPVQQSPKFDU
  39. Gitlab Runner %PDLFSEFBNPO )PTU WPMVNF Docker compose Ϛ΢ϯτ͢Ε͹͑͑΍Μ WPMVNF Gitlab

    ΅ͨͪ͘ $ docker-compose up WPMVNF WPMVNF ͍ͭ΋ͷ W QXE CVJMETHSPVQQSPKFDU ͬͪ͜ʹ͸ͳ͍ ϓϩδΣΫτͷ ιʔείʔυ͸ʁ ɾТɾʆ ʁ
  40. Gitlab Runner %PDLFSEFBNPO )PTU WPMVNF Docker compose Ϛ΢ϯτ͢Ε͹͑͑΍Μ WPMVNF Gitlab

    ΅ͨͪ͘ $ docker-compose up WPMVNF WPMVNF ͍ͭ΋ͷ W QXE CVJMETHSPVQQSPKFDU ͬͪ͜ʹ͸ͳ͍ ϓϩδΣΫτͷ ιʔείʔυ͸ʁ ɾТɾʆ ʁ ಈ͔ͳ͍
  41. ༹͚Δΰδϥ࣌ؒ

  42. Gitlab Runner %PDLFSEFBNPO )PTU WPMVNF Docker compose ͳͥʁʁʁ WPMVNF Gitlab

    ΅ͨͪ͘ $ docker-compose up CVJMETHSPVQQSPKFDUCVJMETHSPVQQSPKFDU WPMVNF W QXE CVJMETHSPVQQSPKFDU  QXE ͸%PDLFSDPNQPTFίϯςφ্͔Βࢀর ͨ݁͠ՌͷσΟϨΫτϦͰ͋ΔʢͦΕ͸ͦ͏ʣ ྫ͑͹ QXE ˠCVJMETHSPVQQSPKFDUͱ͢Δ ͕ɺϚ΢ϯτ͞ΕΔͷ͸ϗετଆͷ σΟϨΫτϦύεΛϚ΢ϯτ͠Α͏ͱ͢Δ Ϛ΢ϯτ͍ͨ͠ͷ͸ͬͪ͜ ͦ͏͡Όͳͯ͘ɺϗετͷ CVJMETHSPVQQSPKFDU ΛϚ΢ϯτ͠Α͏ͱ͢Δ WPMVNF
  43. Gitlab Runner %PDLFSEFBNPO )PTU WPMVNF Docker compose ϗετϚ΢ϯτͨ͠Β͑͑΍Μʂʂ IPNFVCVOUVBQQ Gitlab

    ΅ͨͪ͘ $ docker-compose up WPMVNF WPMVNF ྫ͑͹͜͏
  44. Gitlab Runner %PDLFSEFBNPO )PTU WPMVNF ϗετϚ΢ϯτͨ͠Β͑͑΍Μʂʂ IPNFVCVOUVBQQ Gitlab ΅ͨͪ͘ WPMVNF

    WPMVNF $ docker-compose down $ docker-compose rm ʘόΠόΠʗ ʘ·ͨͶʗʘ͡Ό͋ͷʗ ফ͑ͳ͍ ΰϛ͕࢒Δ ଟ෼ɺ(JUMBC3VOOFSͷ ઃఆͰͰ͖ΔͬΆ͍͚Ͳ ΍Γ͔͕ͨΘ͔ΒΜɾɾɾ
  45. Gitlab Runner %PDLFSEFBNPO )PTU WPMVNF IPNFVCVOUVBQQ Gitlab ΅ͨͪ͘ WPMVNF WPMVNF

    $ docker-compose down $ docker-compose rm ʘόΠόΠʗ ʘ·ͨͶʗʘ͡Ό͋ͷʗ ফ͑ͳ͍ ΰϛ͕࢒Δ ଟ෼ɺ(JUMBCSVOOFSͷઃ ఆͰͰ͖ΔͬΆ͍͚Ͳ΍ Γ͔͕ͨΘ͔ΒΜɾɾɾ ΰϛ͸ย෇͚͍ͨ
  46. ωοτͷւΛ͞·ΑͬͯΔͱ ਆهࣄΛݟ͚ͭ·ͨ͠

  47. https://medium.com/@patrick.winters/mounting-volumes-in-sibling-containers-with-gitlab-ci-534e5edc4035

  48. Gitlab Runner %PDLFSEFBNPO )PTU Docker compose ਆͷखॱ Gitlab ΅ͨͪ͘ 

    ࠓͷ+PCͰىಈ͍ͯ͠Δ$POUBJOFSJEΛ୳͢  $POUBJOFSJE͔ΒϚ΢ϯτ͍ͯ͠ΔWPMVNF ͷϗετͷσΟϨΫτϦύεΛ୳͢  ͷ݁ՌΛ؀ڥม਺ʹೖΕΔ  EPDLFSDPNQPTFVQ
  49. Gitlab Runner %PDLFSEFBNPO )PTU Docker compose ਆͷखॱ Gitlab ΅ͨͪ͘ 

    ࠓͷ+PCͰىಈ͍ͯ͠Δ$POUBJOFSJEΛ୳͢ FYQPSU$0/5"*/&3@*%AEPDLFSQTRGlMBCFMDPNHJUMBCHJUMBCSVOOFSKPCJE$*@+0#@*%A
  50. Gitlab Runner %PDLFSEFBNPO )PTU Docker compose ਆͷखॱ Gitlab ΅ͨͪ͘ $POUBJOFSJE͔ΒϚ΢ϯτ͍ͯ͠ΔWPMVNFͷϗετͷσΟϨΫτϦύεΛ୳͢

    FYQPSU.:@130+&$5@1"5)AEPDLFSJOTQFDUG\\SBOHF.PVOUT^^\\JGFR%FTUJOBUJPOaCVJMETa^^\\4PVSDF^^\\FOE^^\\FOE^^$0/5"*/&3@*%A WPMVNF ͍ͭ͜ͷϗετͷσΟϨΫτϦύεΛऔಘ͢Δ WBSMJCEPDLFSWPMVNFTSVOYYYYYYGCKRYYYYYYYYYDPODVSSFOUYYYYYYYYYYEDYYYYYYYYY@EBUB
  51. Gitlab Runner %PDLFSEFBNPO )PTU Docker compose ਆͷखॱ Gitlab ΅ͨͪ͘ ͷ݁ՌΛ؀ڥม਺ʹೖΕΔ

    FYQPSU.06/5@1"5)\.:@130+&$5@1"5)^\$*@130+&$5@1"5)^ WPMVNF
  52. Gitlab Runner %PDLFSEFBNPO )PTU Docker compose ਆͷखॱ Gitlab ΅ͨͪ͘ ىಈʂ

    EPDLFSDPNQPTFVQ WPMVNF
  53. Gitlab Runner %PDLFSEFBNPO )PTU WPMVNF Docker compose ਆͷखॱ WPMVNF Gitlab

    ΅ͨͪ͘ $ docker-compose up WPMVNF WPMVNF Ϛ΢ϯτͰ͖ͨʂʂʂ
  54. Gitlab Runner %PDLFSEFBNPO )PTU WPMVNF Docker compose ਆͷखॱ WPMVNF Gitlab

    ΅ͨͪ͘ $ docker-compose up WPMVNF WPMVNF Ϛ΢ϯτͰ͖ͨʂʂʂ Α͔ͬͨͶʙʙʙ
  55. ·ͱΊ

  56. ·ͱΊ • ർΕͨ • doodΛ஌Εͨ • ߏ੒Λ஌Βͳ͍ͱ࣌ؒΛ༹͔͢ͷͰ·ͣ͸஌ Ζ͏ • ྑ͍CIϥΠϑΛ

  57. None