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

GitLab CI x Docker のススメ

morizyun
November 03, 2016

GitLab CI x Docker のススメ

2016/11/1 Roppongi.rb での LTの資料です〜

morizyun

November 03, 2016
Tweet

More Decks by morizyun

Other Decks in Programming

Transcript

  1. ͽΘ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
  2. 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Θ 厏ह䄜හ(ኮᶎ͡Ο戔ਧݢᚆ) ϓφϕ΄ಋ殼Ψ懿ᬿ
  3. 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΁ϫЄυͭ͵Ο
 ᛔ㵕ϺЄϸίγϕ
  4. 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΁ϫЄυͭ͵Ο
 ᛔ㵕ϺЄϸίγϕ
  5. 䶅ࢧ bundle install ΅昼ͥ΀͚Ҙ • ೰ਧ΄ path ΨκϰϐτϲͽͣΡ • bundle

    install --path vendor/bundle ΄ςЀϤϸ: cache: key: “${CI_PROJECT_PATH}" untracked: true paths: - vendor/bundle
  6. 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
  7. ϺЄθϸͽ 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
  8. 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
  9. ݇ᘍ揾ා • 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/