Slide 1

Slide 1 text

GitLab CI x Docker ΄φφϮ Japanese: @zyunnosuke English: @morizyune Roppongirb #2

Slide 2

Slide 2 text

͠ڹ抑ΞҘ • morizyun(ϯϷυϲЀ);͚͜ݷڹͽϚϐϕͽ΅ၚ 㵕ͭͼ͚Δͯ • ̿ᯌ;ဴ;Ruby;Rails;̀͹ͼϣϺνΨ䨗͚ͼ ͚Δͯ

Slide 3

Slide 3 text

֟抨ͽͯ͢... • ͷ΀Ε΁ͩ΄ϤϹωЀ΅ md2key ͽ֢ΠΔͭ ͵̶@k0kubun ͫΩ̵͘Π͢;͚ͪͬ͜ΔͯѺ

Slide 4

Slide 4 text

About GitLab • GitHubμϺЄЀ̶̶̶̵͞GitHubͽ͚͚ͮΙΩ • ͳ΄᭗Πͽͯ͢… • Ӯ΄Ӿ΁΅ᐒٖϚϐϕϼЄμ΄ϊЄφᓕቘΨ(ry • Community Edition΀Ο僻ාͽςЄϝ΁ف΢Ο΢Ρ • ͿΩͿΩෛ䱛ᚆ᭄͢ے=> GitLab CI + Docker׎ڥ

Slide 5

Slide 5 text

About GitLab • GitHubμϺЄЀ̶̶̶̵͞GitHubͽ͚͚ͮΙΩ • ͳ΄᭗Πͽͯ͢… • Ӯ΄Ӿ΁΅ᐒٖϚϐϕϼЄμ΄ϊЄφᓕቘΨ(ry • Community Edition΀Ο僻ාͽςЄϝ΁ف΢Ο΢Ρ • ͿΩͿΩෛ䱛ᚆ᭄͢ے=> GitLab CI + Docker׎ڥ

Slide 6

Slide 6 text

䱛ᚆ奧Օ: Issue Management • θЀϝЀ୵ୗ΄όφμᓕቘ
 (GitHub΄ProjectΞ͡ϷϷЄφ෱͡͹͵)

Slide 7

Slide 7 text

䱛ᚆ奧Օ: Snippet • Gist ϶αμ΀φϘϧϐϕϑЄϸ

Slide 8

Slide 8 text

䱛ᚆ奧Օ: GitLab CI (๜氂) • GitLab ΄䱛ᚆ΄Ӟ᮱;ͭͼCI΄䱛ᚆ͘͢Ρ (GitLab 8.x͡Ο)

Slide 9

Slide 9 text

䱛ᚆ奧Օ: GitLab CI (๜氂) • GitLab ΄Ӿͽ CI / CD ͢ͽͣΡ

Slide 10

Slide 10 text

ͿΩ΀ίЄκϓμώϰҘ • GitLab ;΅㳨΁ Runner Ψ㳨΁αЀφϕЄϸ • Docker Container Ψ墋㶨΁㵕͡ͱΡ

Slide 11

Slide 11 text

ͿΩ΀ίЄκϓμώϰҘ • GitLab ;΅㳨΁ Runner Ψ㳨΁αЀφϕЄϸ • Docker Container Ψ墋㶨΁㵕͡ͱΡ Mac ͽiOS΄ϠϸϖΘݢᚆ

Slide 12

Slide 12 text

ͽΘRunner΄installᶎׯͮΙҘ • GitLabςЄϝURL;TokenΨ೰ਧͯΡͶͧ # Install Docker $ curl -sSL https://get.docker.com/ | sh # Install GitLab CI runner $ curl -L https://packages.gitlab.com/install/repositories/ runner/gitlab-ci-multi-runner/script.deb.sh | sudo bash $ sudo apt-get install gitlab-ci-multi-runner # Register the runner to GitLab $ sudo gitlab-ci-multi-runner register # => Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com ) # => Please enter the gitlab-ci token for this runner DockerπϫЀϖΨ ͺ͡͞ΡΞ͜΁ͯΡ Docker CI Runner ΨαЀφϕЄϸ GitLab ςЄϝ;Token Ψ೰ਧͯΡͶͧ https://gitlab.com/gitlab-org/gitlab-ci-multi-runner

Slide 13

Slide 13 text

ͩͩͽ΅ֺ;ͭͼ... (1) git push (2) ϓφϕ䋚ᤈ (4) Deploy (3) Build

Slide 14

Slide 14 text

Run RSpec • Travis CI;͡΄Ξ͜΁ .gitlab-ci.yaml ͽ戔ਧ image: ruby:2.3 services: - "postgres:latest" - "redis:latest" variables: RAILS_ENV: test stages: - test rspec: stage: test script: - 'bundle install --path vendor/bundle’ - 'bundle exec rake db:create' - 'bundle exec rake db:migrate' - 'bundle exec rspec --format=documentation spec' πϫЀϖΨ䋚ᤈͯΡDocker αϮЄυ Postgres΀Ϳϓφϕͽֵ͜DockerΘ 厏ह䄜හ(ኮᶎ͡Ο戔ਧݢᚆ) ϓφϕ΄ಋ殼Ψ懿ᬿ

Slide 15

Slide 15 text

Build Docker image • Docker αϮЄυΨ֢Ρֺ(.gitlab-ci.yaml) stages: - build build_docker_image_for_test: stage: build image: docker:1.10git script: - docker login -u="$DOCKER_USERNAME" - p="$DOCKER_PASSWORD" - docker build -t $DOCKER_IMAGE . - docker push $DOCKER_IMAGE only: master Docker ΄αϮЄυΨbuild master΁ϫЄυͭ͵Ο
 ᛔ㵕ϺЄϸίγϕ

Slide 16

Slide 16 text

Deploy docker image stages: - build deploy_to_production: tags: [docker] stage: deploy environment: production script: - bash ./rollout.sh $DOCKER_IMAGE when: manual Docker ΄αϮЄυΨDeploy master΁ϫЄυͭ͵Ο
 ᛔ㵕ϺЄϸίγϕ

Slide 17

Slide 17 text

Tips

Slide 18

Slide 18 text

䶅ࢧ bundle install ΅昼ͥ΀͚Ҙ • ೰ਧ΄ path ΨκϰϐτϲͽͣΡ • bundle install --path vendor/bundle ΄ςЀϤϸ: cache: key: “${CI_PROJECT_PATH}" untracked: true paths: - vendor/bundle

Slide 19

Slide 19 text

build 奾ຎ΄ϢήαϸΨכਂ • artifacts 戔ਧͽᇙਧ ϢήαϸΚϢζϸύΨ
 Ϡϸϖ΁奄՞ͧͼכਂͽͣΡ pdf: script: xelatex mycvtex artifacts: paths: - mycvpdf

Slide 20

Slide 20 text

ψκϲί΀厏ह䄜හ΅Ҙ • ϤϺυδμϕ Master/Owner(䰱ᴴ) Ͷͧ͢ίμψφ ͽ ͣΡ Secret Variables ; ͚͜戔ਧ͘͢ΠΔͯ

Slide 21

Slide 21 text

docker compose΄ਧ嬝Ψֵ͚͵͚ • Docker-in-DockerͽΚ΢Δͯ(托ͭͥ΅΀͚ͽͯw) image: docker:latest services: - docker:dind build: stage: build script: - docker build -t mydockerimage . - docker run mydockerimage /scripttoruntests https://docs.gitlab.com/ce/ci/docker/using_docker_build.html

Slide 22

Slide 22 text

ϺЄθϸͽ Runner Ψ㵕ͭ͡͵͚ • ϺЄθϸ΁ runner ΨύγЀϺЄϖͭͼ䋚ᤈ $ wget https://gitlab-ci-multi-runner- downloads.s3.amazonaws.com/master/binaries/ gitlab-ci-multi-runner-darwin-amd64 $ chmod +x gitlab-ci-multi-runner-darwin-amd64 $ gitlab-ci-multi-runner-darwin-amd64 exec test https://gitlab.com/gitlab-org/gitlab-ci-multi-runner/blob/master/docs/ install/bleeding-edge.md

Slide 23

Slide 23 text

.gitlab-ci.yaml΄LintϑЄϸΘ͘Ρ • 䨗͚͵ YAML Ϣήαϸ΄෈ဩ͢ྋ͚ͭ͡Ψ ώδϐμͯΡϑЄϸ

Slide 24

Slide 24 text

GitLab.com • μ϶γϖ厏हͽ൉׀ͫ΢ͼ͚ΡGitLab
 (https://about.gitlab.com/) • public, private ϷϪυϕϷΘ僻ාͽ൉׀ • GitLab CI ΄ Runner Θ Digital Ocean ͢僻ාͽ ൉׀

Slide 25

Slide 25 text

Mac ͽGitLab手ͭͼΕΡ • Docker for Mac ف΢ͼ̵զӥ΄πϫЀϖΨ䋚ᤈ ͯΡͶͧ $ wget https://raw.githubusercontent.com/sameersbn/ docker-gitlab/master/docker-compose.yml # http://qiita.com/kkanazaw/items/ 160469245fb270b1bdfd mountض΄pathΨץྋ $ docker-compose up

Slide 26

Slide 26 text

Happy Hacking!

Slide 27

Slide 27 text

݇ᘍ揾ා • GitLab CI΄奧Օ • https://about.gitlab.com/gitlab-ci/ • https://about.gitlab.com/2016/10/17/gitlab-ci-oohlala/ • https://tech.drecom.co.jp/easy-ci-development-using-gitlab-ci/ • Rails ͽ΄䌙فಋ殼 • https://www.stefanwienert.de/blog/2015/11/07/gitlab-ci-with-docker- starting-guide/ • Jenkins;΄晅͚ • http://qiita.com/namutaka/items/5114e9d9faf953bef6a4 • Heroku Ύ΄ Docker αϮЄυ΄ push ಋ殼 • https://blog.codeship.com/deploying-docker-rails-app/