2016/11/1 Roppongi.rb での LTの資料です〜
GitLab CI x Docker΄φφϮJapanese: @zyunnosukeEnglish: @morizyuneRoppongirb #2
View Slide
͠ڹ抑ΞҘ• morizyun(ϯϷυϲЀ);͚͜ݷڹͽϚϐϕͽ΅ၚ㵕ͭͼ͚Δͯ• ̿ᯌ;ဴ;Ruby;Rails;̀ͼϣϺνΨ䨗͚ͼ͚Δͯ
֟抨ͽͯ͢...• ͷΕͩ΄ϤϹωЀ΅ md2key ͽ֢ΠΔͭ͵̶@k0kubun ͫΩ̵͘Π͢;͚ͪͬ͜ΔͯѺ
About GitLab• GitHubμϺЄЀ̶̶̶̵͞GitHubͽ͚͚ͮΙΩ• ͳ΄᭗Πͽͯ͢…• Ӯ΄Ӿ΅ᐒٖϚϐϕϼЄμ΄ϊЄφᓕቘΨ(ry• Community EditionΟ僻ාͽςЄϝفΟΡ• ͿΩͿΩෛ䱛ᚆ᭄͢ے=> GitLab CI + Dockerڥ
䱛ᚆ奧Օ: Issue Management• θЀϝЀ୵ୗ΄όφμᓕቘ (GitHub΄ProjectΞ͡ϷϷЄφ͡͵)
䱛ᚆ奧Օ: Snippet• Gist ϶αμφϘϧϐϕϑЄϸ
䱛ᚆ奧Օ: GitLab CI (氂)• GitLab ΄䱛ᚆ΄Ӟ᮱;ͭͼCI΄䱛ᚆ͘͢Ρ(GitLab 8.x͡Ο)
䱛ᚆ奧Օ: GitLab CI (氂)• GitLab ΄Ӿͽ CI / CD ͢ͽͣΡ
ͿΩίЄκϓμώϰҘ• GitLab ;΅㳨 Runner Ψ㳨αЀφϕЄϸ• Docker Container Ψ墋㶨㵕͡ͱΡ
ͿΩίЄκϓμώϰҘ• GitLab ;΅㳨 Runner Ψ㳨αЀφϕЄϸ• Docker Container Ψ墋㶨㵕͡ͱΡMac ͽiOS΄ϠϸϖΘݢᚆ
ͽΘ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 runnerDockerπϫЀϖΨͺ͡͞ΡΞͯ͜ΡDocker CI RunnerΨαЀφϕЄϸGitLab ςЄϝ;TokenΨਧͯΡͶͧhttps://gitlab.com/gitlab-org/gitlab-ci-multi-runner
ͩͩͽ΅ֺ;ͭͼ...(1) git push(2) ϓφϕ䋚ᤈ(4) Deploy(3) Build
Run RSpec• Travis CI;͡΄Ξ͜ .gitlab-ci.yaml ͽ戔ਧimage: ruby:2.3services:- "postgres:latest"- "redis:latest"variables:RAILS_ENV: teststages:- testrspec:stage: testscript:- 'bundle install --path vendor/bundle’- 'bundle exec rake db:create'- 'bundle exec rake db:migrate'- 'bundle exec rspec --format=documentation spec'πϫЀϖΨ䋚ᤈͯΡDocker αϮЄυPostgresͿϓφϕͽֵ͜DockerΘ厏ह䄜හ(ኮᶎ͡Ο戔ਧݢᚆ)ϓφϕ΄ಋ殼Ψ懿ᬿ
Build Docker image• Docker αϮЄυΨ֢Ρֺ(.gitlab-ci.yaml)stages:- buildbuild_docker_image_for_test:stage: buildimage: docker:1.10gitscript:- docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"- docker build -t $DOCKER_IMAGE .- docker push $DOCKER_IMAGEonly: masterDocker ΄αϮЄυΨbuildmasterϫЄυͭ͵Ο ᛔ㵕ϺЄϸίγϕ
Deploy docker imagestages:- builddeploy_to_production:tags: [docker]stage: deployenvironment: productionscript:- bash ./rollout.sh $DOCKER_IMAGEwhen: manualDocker ΄αϮЄυΨDeploymasterϫЄυͭ͵Ο ᛔ㵕ϺЄϸίγϕ
Tips
䶅ࢧ bundle install ΅昼͚ͥҘ• ਧ΄ path ΨκϰϐτϲͽͣΡ• bundle install --path vendor/bundle ΄ςЀϤϸ:cache:key: “${CI_PROJECT_PATH}"untracked: truepaths:- vendor/bundle
build 奾ຎ΄ϢήαϸΨכਂ• artifacts 戔ਧͽᇙਧ ϢήαϸΚϢζϸύΨ Ϡϸϖ奄՞ͧͼכਂͽͣΡpdf:script: xelatex mycvtexartifacts:paths:- mycvpdf
ψκϲί厏ह䄜හ΅Ҙ• ϤϺυδμϕ Master/Owner(䰱ᴴ) Ͷͧ͢ίμψφͽ ͣΡ Secret Variables ; ͚͜戔ਧ͘͢ΠΔͯ
docker compose΄ਧ嬝Ψֵ͚͵͚• Docker-in-DockerͽΚΔͯ(托ͭͥ΅͚ͽͯw)image: docker:latestservices:- docker:dindbuild:stage: buildscript:- docker build -t mydockerimage .- docker run mydockerimage /scripttoruntestshttps://docs.gitlab.com/ce/ci/docker/using_docker_build.html
ϺЄθϸͽ 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 testhttps://gitlab.com/gitlab-org/gitlab-ci-multi-runner/blob/master/docs/install/bleeding-edge.md
.gitlab-ci.yaml΄LintϑЄϸΘ͘Ρ• 䨗͚͵ YAML Ϣήαϸ΄ဩ͢ྋ͚ͭ͡ΨώδϐμͯΡϑЄϸ
GitLab.com• μ϶γϖ厏हͽ׀ͫͼ͚ΡGitLab (https://about.gitlab.com/)• public, private ϷϪυϕϷΘ僻ාͽ׀• GitLab CI ΄ Runner Θ Digital Ocean ͢僻ාͽ׀
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
Happy Hacking!
݇ᘍ揾ා• 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/