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

軽量なDockerイメージで
CIのビルド時間を短くしてみる

 軽量なDockerイメージで
CIのビルド時間を短くしてみる

Dbab5e5a1fd54531e1119ede6b3b9e65?s=128

Ryosuke Horie

May 10, 2017
Tweet

Transcript

  1. ܰྔͳDockerΠϝʔδͰ
 CIͷϏϧυ࣌ؒΛ୹ͯ͘͠ΈΔ Android Testing Bootcamp #6 Ryosuke Horie VASILY, inc.

  2. ࣗݾ঺հ @Horie1024 ▸ ງߐ ྄հ / Ryosuke Horie ▸ લ৬:

    ϙʔλϧαΠτ Web / ΞϓϦ։ൃ ▸ 2೥લʹVASILYʹத్ೖࣾ ▸ AndroidΤϯδχΞ ▸ ࠷ۙ͸iOSͷϓϩδΣΫτʹࢀՃ ▸ Twitter GitHub Qiita: @Horie1024
  3. ൃද಺༰ ൃද಺༰ ▸ DockerʹରԠͨ͠CIαʔϏε͕࠷ۙଟ͍ ▸ CIαʔϏε͸DockerΠϝʔδΛωοτϫʔΫӽ͠ʹPull ▸ ͦͷͨΊΠϝʔδͷαΠζ͸ॏཁ ▸ ΠϝʔδΛܰྔԽ͢Δํ๏Λࢼߦࡨޡ

    ▸ ϕʔεΠϝʔδΛมߋɺAndroid SDKͷ༰ྔ࡟ݮ ▸ Pullʹֻ͔Δ࣌ؒ୹ॖ -> Ϗϧυ͕࣌ؒ୹͘ͳΔͷͰ͸ʁ
  4. DockerʹରԠͨ͠CIαʔϏε ࠷ۙͷCIαʔϏε ▸ Ϗϧυ؀ڥΛDockerΠϝʔδͰ༻ҙͰ͖Δ ▸ Wercker ▸ Drone ▸ CircleCI

    ▸ Travis CI
  5. DockerʹରԠͨ͠CIαʔϏε DockerΠϝʔδͷ؅ཧ ▸ ϨδετϦαʔϏεΛར༻ ▸ Docker Hub ▸ Google Container

    Registry ▸ Amazon ECR ▸ QUAY.io Amazon ECR
  6. DockerʹରԠͨ͠CIαʔϏε DockerΠϝʔδͷPull ▸ ΠϝʔδΛϨδετϦ͔ΒPull ▸ Ϗϧυ࣌ؒʹؚ·ΕΔ ▸ Πϯλʔωοτܦ༝ ▸ ΠϝʔδͷαΠζΛແࢹͰ͖ͳ͍

    Amazon ECR
  7. ΠϝʔδͷܰྔԽ ΠϝʔδαΠζͷ࡟ݮ ▸ ΠϝʔδΛPull͢Δ࣌ؒͷ୹ॖ ▸ Ϗϧυ࣌ؒͷ୹ॖʹܨ͕Δ ▸ ͍ܰͷ͸ྑ͍

  8. ΠϝʔδͷܰྔԽ Ͳ͏ܰྔԽ͢Δͷ͔ʁ ▸ ܰྔͳOSΛϕʔεΠϝʔδʹ͢Δ ▸ ෆཁͳύοέʔδΛΠϯετʔϧ͠ͳ͍

  9. ΠϝʔδͷܰྔԽ Ͳ͏ܰྔԽ͢Δͷ͔ʁ ▸ ܰྔͳOSΛϕʔεΠϝʔδʹ͢Δ ▸ ෆཁͳύοέʔδΛΠϯετʔϧ͠ͳ͍

  10. ΠϝʔδͷܰྔԽ Alpine Linux ▸ ඇৗʹܰྔͳLinux distribution ▸ ެࣜͷDockerΠϝʔδͰ΋࠾༻ ▸ Alpine

    LinuxΛϕʔεͷΠϝʔδʹ ▸ ΠϝʔδαΠζͷ࡟ݮʹޮՌେ
  11. Πϝʔδͷ࡞੒ ૉͷΠϝʔδαΠζൺֱ IMAGE SIZE ubuntu: 16.04 117 MB alpine: 3.5

    3.99 MB ▸ ubuntuͱൺֱͯ͠ѹ౗తʹ͍ܰ ▸ ͜ͷαΠζࠩ෼ɺΠϝʔδ͕ܰ͘ͳΔ͸ͣ
  12. ΠϝʔδͷܰྔԽ Android SDKΛμ΢ϯϩʔυͨ͠ঢ়ଶ IMAGE SIZE ubuntu: 16.04 2.05 GB alpine:

    3.5 1.58 GB ▸ android-sdk_r24.4.1-linux͕ϕʔε ▸ android sdk update ▸ android-25, build-tools-25.0.3 ▸ extra-google-m2repository ▸ extra-android-m2repository ▸ ໿500 MBͷࠩ ▸ ͦ΋ͦ΋Android SDK͕ॏ͗͢Ͱ͸
  13. ΠϝʔδͷܰྔԽ Docker Hub্Ͱͷൺֱ ▸ Docker HubʹΠϝʔδΛ্͛ͨঢ়ଶ ▸ ѹॖޙͷΠϝʔδαΠζ͸྆ํ 1 GB

    ▸ ͋ΕɺαΠζ͕มΘΒͳ͍ɾɾʁ
  14. Ͳ͏͠Α͏

  15. ΠϝʔδͷܰྔԽ WerckerͰPullʹֻ͔Δ࣌ؒͷൺֱ ▸ औΓ׶͑ͣൺֱ ▸ 5ճฏۉ ▸ WerckerͷΩϟογϡ͕ޮ͍͍ͯͳ͍ঢ়ଶ ▸ alpineϕʔεͷΠϝʔδͷํ͕଎͍ʂ

    IMAGE TIME ubuntu: 16.04 54.2 s alpine: 3.5 46.8 s
  16. ΠϝʔδͷܰྔԽ Ͳ͏ܰྔԽ͢Δͷ͔ʁ ▸ ܰྔͳOSΛϕʔεΠϝʔδʹ͢Δ ▸ ෆཁͳύοέʔδΛΠϯετʔϧ͠ͳ͍

  17. ΠϝʔδͷܰྔԽ Ͳ͏ܰྔԽ͢Δͷ͔ʁ ▸ ܰྔͳOSΛϕʔεΠϝʔδʹ͢Δ ▸ ෆཁͳύοέʔδΛΠϯετʔϧ͠ͳ͍

  18. ΠϝʔδͷܰྔԽ Android SDKͷ༰ྔ࡟ݮ ▸ ࠷ۙ͸ϛχϚϜͳSDK͕μ΢ϯϩʔυͰ͖Δ ▸ android-sdk_r24.4.1-linux ໿570 MB ▸

    sdk-tools-linux-3859397 ໿160 MB
  19. ΠϝʔδͷܰྔԽ Android SDKΛμ΢ϯϩʔυͨ͠ঢ়ଶ IMAGE SIZE ubuntu: 16.04 1.53 GB alpine:

    3.5 1.04 GB ▸ sdk-tools-linux-3859397͕ϕʔε ▸ androidίϚϯυ͕deprecated ▸ sdkmanagerΛ࢖༻ ▸ android-25, build-tools-25.0.3 ▸ extra-google-m2repository ▸ extra-android-m2repository ▸ ໿500 MBͷࠩͳͷ͸มΘΒͳ͍
  20. ΠϝʔδͷܰྔԽ WerckerͰPullʹֻ͔Δ࣌ؒͷൺֱ ▸ 5ճฏۉ ▸ ΠϝʔδαΠζͷܰྔԽͰ଎౓޲্ ▸ 10ඵҎ্଎͘ͳͬͨ IMAGE TIME

    ubuntu: 16.04 39.4 s alpine: 3.5 30.2 s
  21. ΠϝʔδͷܰྔԽ Alpine LinuxϕʔεͷΠϝʔδ͕ྑͦ͞͏ ▸ ࠷΋Πϝʔδ͕ܰྔ ▸ Pullʹֻ͔Δ࣌ؒ΋୹͍ ▸ ͔͠͠ ▸

    AndroidΛϏϧυͰ͖͍ͯͳ͍(5/10 18:00ݱࡏ)
  22. ΠϝʔδͷܰྔԽ Alpine LinuxͰͷቕΓ ▸ sdkmanager͕࣮ߦͰ͖ͳ͍ ▸ Alpine LinuxͰ͸bash͕ೖ͍ͬͯͳ͍ͷ͕ݪҼ ▸ aapt͕࣮ߦͰ͖ͳ͍

    ▸ Cannot run program "aapt": error=2, No such file or directory ▸ glibc͕ೖ͍ͬͯͳ͍ɻAlpineͰglibcΛೖΕΔͷʹቕ·Δɻ ▸ lib.so.1͕ແ͍ͱౖΒΕΔɻ ▸ aapt͸32bit൛ͷglibcͰͳ͚Ε͹ͳΒͳ͍ ▸ 32bit൛ͷglibcΛΠϯετʔϧ <- ࠓ͜͜Ͱ ٧·Δ
  23. ·ͱΊ

  24. ·ͱΊ ▸ DockerΠϝʔδͷܰྔԽ͸େ੾ ▸ ϕʔεΠϝʔδͷมߋɺAndroid SDKͷαΠζ࡟ݮ͸ޮՌత ▸ Alpine Linuxͷߏ੒͸ඞཁ࠷খݶͷͨΊቕ·ΔՄೳੑ͋Γ ▸

    DebianɺArch LinuxͰࢼ͢ͱ͋·Γቕ·ΒͣʹܰྔԽͰ͖Δ͔΋͠Εͳ͍ ▸ ·ͣ͸Android SDKͷ࡟ݮ͔ΒखΛ෇͚Δͷ͕ྑͦ͞͏ ▸ androidίϚϯυ͕deprecatedʹͳͬͨͷ΋ྑ͍ػձ
  25. ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ

  26. appendix ʲิ଍ʳWerckerͷΠϝʔδΩϟογϡ ▸ Werckerͷ৔߹ΠϝʔδͷΩϟογϡΛউखʹͯ͘͠ΕΔ ▸ Ωϟογϡ͕͋Δ৔߹ΠϝʔδͷPullʹ͸ɺ1~2ඵ͔͔͔͠Βͳ͍ ▸ Ωϟογϡ͕ແ͍৔߹ͷϏϧυ࣌ؒͷ୹ॖʹ͸ΠϝʔδͷܰྔԽ͸ޮՌ͕͋Δ