Slide 1

Slide 1 text

Automation with Wercker and Container Builder Keishin Yokomaku / shibuya.apk #13

Slide 2

Slide 2 text

Automation with Wercker and Container Builder About Me ▸ Keishin Yokomaku ▸ Drivemode, Inc. / Principal Engineer ▸ KeithYokoma: GitHub / Twitter / Qiita / Tumblr / Stack Overflow ▸ Books: Mobile App Dev Guide / Android Academia / Grimoire of Android ▸ Fun: Gymnastics / Cycling / Photography / Motorsport ▸ Today’s Quote: “Power is everything.” 2

Slide 3

Slide 3 text

Automation with Wercker and Container Builder 3

Slide 4

Slide 4 text

4 “Wercker͸͍͍ͧ”

Slide 5

Slide 5 text

Automation with Wercker and Container Builder Wercker? ▸ Docker-native CI/CD Automation Platform ▸ ࣗಈͰ Docker ίϯςφΛςετɺσϓϩΠͰ͖ΔαʔϏε ▸ Docker ΠϝʔδΛ pull ͖ͯͯ͠ίϯςφΛ্ཱͪ͛Δ ▸ ίϯςφ಺ͰίϚϯυΛ࣮ߦ͢Δ ▸ ύΠϓϥΠϯͰςετͱσϓϩΠΛ෼཭Ͱ͖Δ ▸ ςετ͕ਖ਼ৗऴྃͨ͠ͱ͖ͷΈσϓϩΠ͕࣮ߦ͞ΕΔ 5

Slide 6

Slide 6 text

Automation with Wercker and Container Builder Wercker for Android CI ▸ Docker Πϝʔδ͑͋͞Ε͹Ϗϧυ͕Ͱ͖Δ ▸ Android ΞϓϦΛϏϧυ͢ΔͨΊʹඞཁͳ΋ͷ͕͋Ε͹… ▸ Android SDK & NDK ▸ Java ▸ etc… 6

Slide 7

Slide 7 text

Automation with Wercker and Container Builder Wercker for Android CD ▸ Android ΞϓϦͷσϓϩΠ => apk ͷ഑৴ ▸ apk Λ഑৴ͯ͘͠ΕΔαʔϏεʹσϓϩΠ͢Ε͹… ▸ DeployGate ▸ fastlane ▸ etc… 7

Slide 8

Slide 8 text

8 “׬શʹཧղͨ͠”

Slide 9

Slide 9 text

Automation with Wercker and Container Builder Steps 1.Dockerfile ͔Β Docker ΠϝʔδΛϏϧυ 2.Ϗϧυͨ͠ΠϝʔδΛ dockerhub ͳͲͷϨδετϦʹొ࿥ 3.Ϗϧυ͍ͨ͠ϦϙδτϦʹwercker.yml Λ഑ஔ 4.Wercker ͷઃఆ 9

Slide 10

Slide 10 text

Automation with Wercker and Container Builder Building a Docker image ▸ Dockerfile Λͭ͘Ζ͏(ྫ) ▸ Ubuntu Λϕʔεʹ ▸ Android SDK ͱ Java ΛΠϯετʔϧͯ͠ ▸ ඞཁͳ؀ڥม਺Λ੔͑ͨΠϝʔδ ▸ e.g. http://bit.ly/2ngAz0S 10

Slide 11

Slide 11 text

Automation with Wercker and Container Builder Pushing the image to a registry ▸ Wercker ͕ѻ͑ΔϨδετϦ ▸ Docker Hub ▸ Google Container Registry ▸ Amazon ECR ▸ Private Registry(quay.io) ▸ ϓϥΠϕʔτϦϙδτϦʹ͠·͠ΐ͏ (http://bit.ly/2nuwkz9) 11

Slide 12

Slide 12 text

Automation with Wercker and Container Builder Build an image using ‘docker-machine' (mac) $ docker-machine start image-builder (mac) $ docker-machine ssh image-builder (docker-machine) $ ls Dockerfile (docker-machine) $ docker build -t account/repository:tag . (docker-machine) $ docker login (docker-machine) $ docker push account/repository:tag (docker-machine) $ exit (mac) $ docker-machine stop image-builder 12

Slide 13

Slide 13 text

Automation with Wercker and Container Builder Configure wercker.yml ▸ Android ΞϓϦͷϦϙδτϦʹ YAML ϑΝΠϧΛஔ͘ ▸ ໊લ͸ඞͣ wercker.yml ▸ ϏϧυɺσϓϩΠͦΕͧΕͷϋογϡ಺ʹϏϧυʹඞཁͳखॱΛॻ͘ ▸ ϏϧυͱσϓϩΠͰҟͳΔ Docker ΠϝʔδΛ࢖༻Մೳ 13

Slide 14

Slide 14 text

Automation with Wercker and Container Builder Configure wercker.yml build: box: id: account/repository username: $USERNAME password: $PASSWORD tag: tag steps: - script: name: assemble code: | ./gradlew —stacktrace —project-cache-dir=$WERCKER_CACHE_DIR assemble - script: name: test code: | ./gradlew —stacktrace —project-cache-dir=$WERCKER_CACHE_DIR test lint 14

Slide 15

Slide 15 text

Automation with Wercker and Container Builder Configure wercker.yml build: box: id: account/repository username: $USERNAME password: $PASSWORD tag: tag steps: - script: name: assemble code: | ./gradlew —stacktrace —project-cache-dir=$WERCKER_CACHE_DIR assemble - script: name: test code: | ./gradlew —stacktrace —project-cache-dir=$WERCKER_CACHE_DIR test lint 15

Slide 16

Slide 16 text

Automation with Wercker and Container Builder Configure wercker.yml build: box: id: account/repository username: $USERNAME password: $PASSWORD tag: tag steps: - script: name: assemble code: | ./gradlew —stacktrace —project-cache-dir=$WERCKER_CACHE_DIR assemble - script: name: test code: | ./gradlew —stacktrace —project-cache-dir=$WERCKER_CACHE_DIR test lint 16

Slide 17

Slide 17 text

Automation with Wercker and Container Builder Tips ▸ 1ͭͷεςοϓ͸10෼ͰλΠϜΞ΢τ ▸ ίϚϯυͷ࣮ߦ͕௕͘ͳΔͱ͖͸෼͚Δ ▸ Wercker ͷ Web ΠϯλϑΣʔεͰͷग़ྗ͕͔ͳΓγϯϓϧ ▸ ࠔͬͨͱ͖ʹ࢖͍͍ͨ৘ใ͸ echo Ͱग़ྗ͢ΔεςοϓΛ࡞Δ ▸ ϩάग़ྗ͕௕͍ͱ Web ΠϯλϑΣʔε͕ܹॏͳͷͰదٓௐ੔ 17

Slide 18

Slide 18 text

Automation with Wercker and Container Builder Saving artifacts ▸ after-steps ʹखॱΛॻ͘ ▸ ؀ڥม਺ʹอଘ৔ॴ͕ఆٛͯ͋͠Δ ▸ $WERCKER_REPORT_ARTIFACTS_DIR ▸ ೖΕ͍ͨ΋ͷ͚ͩ cp ͢Δ ▸ อଘͨ͠੒Ռ෺͸ Web ͔Βμ΢ϯϩʔυͰ͖Δ ▸ ৔ॴ͕෼͔ΓͮΒ͍ͷͰ஫ҙ 18

Slide 19

Slide 19 text

Automation with Wercker and Container Builder Saving artifacts 19

Slide 20

Slide 20 text

Automation with Wercker and Container Builder Saving artifacts after-steps: - script: name: save artifacts code: | ls -la ./app/build/outputs/ cp -r ./app/build/outputs/* ${WERCKER_REPORT_ARTIFACTS_DIR} cp -r ./app/build/reports/* ${WERCKER_REPORT_ARTIFACTS_DIR} 20

Slide 21

Slide 21 text

Automation with Wercker and Container Builder Saving artifacts after-steps: - script: name: save artifacts code: | ls -la ./app/build/outputs/ cp -r ./app/build/outputs/* ${WERCKER_REPORT_ARTIFACTS_DIR} cp -r ./app/build/reports/* ${WERCKER_REPORT_ARTIFACTS_DIR} 21

Slide 22

Slide 22 text

Automation with Wercker and Container Builder Connect Wercker with GitHub 22

Slide 23

Slide 23 text

Automation with Wercker and Container Builder Connect Wercker with GitHub ▸ ϦϙδτϦΛબΜͰ… ▸ ΦʔφʔΛબΜͰ… ▸ σϓϩΠΩʔΛ௥Ճͯ͠… ▸ public ͳϓϩδΣΫτͷ৔߹͸ https ܦ༝ͰΞΫηε͢ΔઃఆͰ΋ OK ▸ ׬ྃʂ 23

Slide 24

Slide 24 text

24

Slide 25

Slide 25 text

Automation with Wercker and Container Builder ӡ༻͢Δͱݟ͑ͯ͘Δ Wercker ͷखؒ ▸ SDK ͷΞοϓσʔτ΍αϙʔτϦϙδτϦͷΞοϓσʔτ ▸ Docker ΠϝʔδΛ࡞Γ௚͢͜ͱʹͳΔ͕…ʁ ▸ ຖճ docker-machine ͰϏϧυ…ʁ ▸ docker-machine ͱ Android Emulator ͸ಉ࣌ʹಈ͔ͤͳ͍ͧ…ʁ ▸ Πϝʔδ࡞Δ͚ͩͰ 10 ෼Ҏ্͔͔ΔΜ͚ͩͲ…ʁ ▸ λάͷ؅ཧΛࣗ෼Ͱߟ͑Δͷ໘౗͍͘͞Μ͚ͩͲ…ʁ 25

Slide 26

Slide 26 text

26

Slide 27

Slide 27 text

27 “ͦ͜ͰContainer BuilderͰ͢Α”

Slide 28

Slide 28 text

Automation with Wercker and Container Builder Container Builder? ▸ ͜Ε͸Կʁ ▸ Google ͷαʔϏε ▸ Dockerfile ΛΘͨ͢ͱࣗಈͰ Docker ΠϝʔδΛ࡞ͬͯϨδετϦʹొ࿥ͯ͠ ͘ΕΔ͍͢͝΍ͭ 28

Slide 29

Slide 29 text

Automation with Wercker and Container Builder Container Builder? ▸ ͜Ε͸Կʁ ▸ Google ͷαʔϏε ▸ Dockerfile ΛΘͨ͢ͱࣗಈͰ Docker ΠϝʔδΛ࡞ͬͯϨδετϦʹొ࿥ͯ͠ ͘ΕΔ͍͢͝΍ͭ 29

Slide 30

Slide 30 text

Automation with Wercker and Container Builder Container Builder ▸ Πϝʔδͷ TAG ͷ؅ཧํ๏ΛઃఆͰ͖Δ ▸ ݻఆͰ latest ͷ·· ▸ git ͷίϛοτ ID Λλάʹ͢Δ ▸ etc… ▸ GitHub ͱ࿈ܞͰ͖Δ 30

Slide 31

Slide 31 text

Automation with Wercker and Container Builder Workflow of updating Docker image ▸ Dockerfile Λฤू ▸ ίϛοτΛ push ▸ Container Builder ͕ϏϧυΛ࢝ΊΔ ▸ ׬ྃͨ͠Β৽͍͠λάΛ wercker.yml ʹઃఆ͢Δ 31

Slide 32

Slide 32 text

32 “׬શʹཧղͨ͠”

Slide 33

Slide 33 text

Automation with Wercker and Container Builder Configure Container Builder ▸ Google Cloud Console ͔Β Container Registry Λ։͘ ▸ Build triggers ͔Β GitHub ͷϦϙδτϦΛબ୒ͯ͠τϦΨʔΛઃఆ ▸ Ͳͷϒϥϯνͷ push ͰϏϧυΛ࢝ΊΔ͔ ▸ Dockerfile ͷ৔ॴ ▸ Πϝʔδ໊ 33

Slide 34

Slide 34 text

Automation with Wercker and Container Builder Configure Container Builder ▸ Dockerfile ͷϏϧυ ▸ 10෼Ҏ্͔͔ΔͱλΠϜΞ΢τ͢Δ ▸ cloudbuild.yaml Λ͔ͭͬͯௐ੔͢ΔΑ͏มߋ 34

Slide 35

Slide 35 text

Automation with Wercker and Container Builder cloudbuild.yaml timeout: 40m steps: - name: gcr.io/cloud-builders/docker args: ['build', '--tag=gcr.io/$PROJECT_ID/$REPO_NAME:$COMMIT_SHA', '.'] images: ['gcr.io/$PROJECT_ID/$REPO_NAME:$COMMIT_SHA'] 35

Slide 36

Slide 36 text

Automation with Wercker and Container Builder cloudbuild.yaml timeout: 40m steps: - name: gcr.io/cloud-builders/docker args: ['build', '--tag=gcr.io/$PROJECT_ID/$REPO_NAME:$COMMIT_SHA', '.'] images: ['gcr.io/$PROJECT_ID/$REPO_NAME:$COMMIT_SHA'] 36

Slide 37

Slide 37 text

Automation with Wercker and Container Builder cloudbuild.yaml timeout: 40m steps: - name: gcr.io/cloud-builders/docker args: ['build', '--tag=gcr.io/$PROJECT_ID/$REPO_NAME:$COMMIT_SHA', '.'] images: ['gcr.io/$PROJECT_ID/$REPO_NAME:$COMMIT_SHA'] 37

Slide 38

Slide 38 text

Automation with Wercker and Container Builder cloudbuild.yaml timeout: 40m steps: - name: gcr.io/cloud-builders/docker args: ['build', '--tag=gcr.io/$PROJECT_ID/$REPO_NAME:$COMMIT_SHA', '.'] images: ['gcr.io/$PROJECT_ID/$REPO_NAME:$COMMIT_SHA'] 38

Slide 39

Slide 39 text

Automation with Wercker and Container Builder cloudbuild.yaml timeout: 40m steps: - name: gcr.io/cloud-builders/docker args: ['build', '--tag=gcr.io/$PROJECT_ID/$REPO_NAME:$COMMIT_SHA', '.'] images: ['gcr.io/$PROJECT_ID/$REPO_NAME:$COMMIT_SHA'] 39

Slide 40

Slide 40 text

Automation with Wercker and Container Builder Change wercker.yml ▸ Google Container Registry ͔ΒҾͬுͬͯ͘ΔΑ͏ʹ͢Δ ▸ JSON Ͱೝূ͢ΔํࣜʹͳΔ ▸ username ͸ඞͣ _json_key ▸ ೝূ৘ใͷೖͬͨ JSON ͸؀ڥม਺ʹೖΕ͓ͯ͘ ▸ gcr.io ΛϨδετϦʹࢦఆ͢Δ 40

Slide 41

Slide 41 text

Automation with Wercker and Container Builder Change wercker.yml build: box: id: account/repository username: $USERNAME password: $PASSWORD tag: tag box: id: gcr.io// username: _json_key passwrod: $GCR_JSON_KEY_FILE registry: https://gcr.io tag: 41

Slide 42

Slide 42 text

Automation with Wercker and Container Builder $GCR_JSON_KEY_FILE as Environment variable in Wercker CI { “type”: “service_account”, “project_id”: “PROJECT_ID”, “private_key_id”: “hogefugapiyofoobarbaz”, “private_key”: “——-BEGIN PRIVATE KEY——-\nhogehoge\n——-END PRIVATE KEY——-” “client_email”: “[email protected]” …… } 42

Slide 43

Slide 43 text

Automation with Wercker and Container Builder Wercker + Container Builder ▸ Ϗϧυ؀ڥΛ Docker Πϝʔδʹ٧ΊࠐΊΔ ▸ ϏϧυɾσϓϩΠ؀ڥʹԿ͕ඞཁ͔ίʔυʹམͱͤΔ ▸ ίʔυʹམͱͨ͠ Dockerfile ΛϦϏδϣϯ؅ཧͰ͖Δ ▸ ΠϝʔδΛ࢖ͬͯ CI/CD ͕Ͱ͖Δ ▸ ΠϝʔδΛϗετͯ͘͠ΕΔ৔ॴ͔Β pull ͢Δ͚ͩͰ࢖͑Δ 43

Slide 44

Slide 44 text

Automation with Wercker and Container Builder Wercker + Container Builder ▸ CI ؀ڥΛ CI/CD ͢Δ ▸ खݩͷ PC ͷϦιʔεΛ࢖ΘͣʹΠϝʔδΛϏϧυͰ͖Δ ▸ Docker ΠϝʔδͷϦϏδϣϯ؅ཧΛࣗಈԽͰ͖Δ ▸ ؀ڥΛม͑Δ࣌͸ TAG Λม͑Δ͚ͩ 44

Slide 45

Slide 45 text

Automation with Wercker and Container Builder Keishin Yokomaku / shibuya.apk #13