â 人
/ â°ââ° \ ãªã«ã¡ã¤ã³ã³ã¨ã³ã¸ãã¢ã®äºååµ(@ganta0087)ã§ãã
CrowdWorksã§ã¯ããµã¼ãã¹ã®CIç°å¢ã¨ãã¦CirlceCIãå©ç¨ãã¦ãã¾ãã
ä»åãCircleCI 1.0ãã2.0ã«ç§»è¡ããã¨åæã«ãæ°æ©è½ã®ãã£ãã·ã¥ããã«æ´»ç¨ãããã¨ã§ãã³ã¹ããå¢å ããããã¨ãªãCIå®è¡æéãååã«ãããã¨ãã§ãã¾ããã
ä»åã®è¨äºã§ã¯ãCirlceCI 2.0ã®ã¡ãªããããã©ã®ãããªãã¥ã¼ãã³ã°ãè¡ã£ãã®ãããç´¹ä»ãã¾ãã
CircleCI 2.0ã«ã¤ãã¦
CircleCI 2.0ã¯ç¾å¨ãã¼ã¿çã¨ãªã£ã¦ããããCircleCI 2.0: Beta Access - CircleCIãããç³ãè¾¼ããã¨ãã§ãã¾ãã(試ãã¦ã¿ãã¨ããå人ã®ãªãã¸ããªã§ã¯ããã«å©ç¨ã§ããããã§ãã)
ç³è«ããOrganizationã®ãã¹ã¦ã®ããã¸ã§ã¯ãã§çªç¶ãã¼ã¸ã§ã³ãåãæ¿ããããã§ã¯ãªãã.circleci/config.yml
(ã¾ãã¯circle.yml
)ã«version: 2
ã¨å®ç¾©ãããã¨ã§æå¹ã«ãªããããæ¤è¨¼ç¨ã®ãã©ã³ãã ã2.0ã«ãã¦è©¦ããã¨ãã§ãã¾ãã
1.0ãã2.0ã®ä¸»ãªå¤æ´ç¹ã¯æ¬¡ã®éãã§ãã
ã«ã¹ã¿ã ãã«ãã¤ã¡ã¼ã¸
1.0ã§ã¯å¤ãã®è¨èªããã¼ã«ããããããã¤ã³ã¹ãã¼ã«ãããUbuntuã¤ã¡ã¼ã¸ãCIã®ãã«ãã¤ã¡ã¼ã¸ã¨ãã¦å©ç¨ãã¾ããããããã¤ã¡ã¼ã¸ã«å«ã¾ãã¦ããªããã®ãå©ç¨ããå ´åã¯CIã®ä¸ã§ã¤ã³ã¹ãã¼ã«ããå¿ è¦ãããã¾ããã
2.0ã§ã¯Dockerã¤ã¡ã¼ã¸ããã¼ã¹ã«ãã¦CIãå®è¡ã§ããããã«ãªãã¾ãããããã«ãããå¿ è¦ãªã©ã¤ãã©ãªãªã©ããããããã»ããã¢ããããDockerã¤ã¡ã¼ã¸ãå©ç¨ã§ããããã«ãªãã¾ãã
ãã¤ãã£ãDockerã®ãµãã¼ã
1.0ã§ãDockerãµãã¼ãã¯åå¨ãã¦ãã¾ããããããCircleCIèªèº«ããã¼ã¹ã³ã³ããã¨ãã¦LXCãå©ç¨ãã¦ãããã¨ã®å½±é¿ã§ãç¬èªããããå½ã¦ãå¤ããã¼ã¸ã§ã³ã«éå®ããã¦ãã¾ãã1
2.0ã§ã¯ä»®æ³ãã·ã³ãèµ·åãã¦ç´ç²ãªDockerãåãããããã«ãªã£ããããææ°ã®æ©è½ããã«ã«å©ç¨ã§ããããã«ãªãã¾ãããCIã®ãã¼ã¹ã¨ãã¦ãã®ä»®æ³ãã·ã³ãèµ·åãããã¨ããDockerã¤ã¡ã¼ã¸ããã¼ã¹ã«ãã¤ã¤ãéä¸ã§ãã®ä»®æ³ãã·ã³ãèµ·åãããã¨ãã§ãã¾ãã2
æè»ãªã¸ã§ãæ§æ
1.0ã§ã¯èªåçã«ããã¸ã§ã¯ãã®ç¨®å¥ãæ¨æ¸¬ãã¦ãæé©ãªã»ããã¢ããã¨ãã¹ãã®ã³ãã³ããå®è¡ããã¾ããCIã®å®è¡ã¯æ確ãªãã§ã¼ãºã«åããã¦ããããã£ãã·ã¥ããªã¹ãã¢ã»ä¿åããã¿ã¤ãã³ã°ããã³ãã³ããå®è¡ããã¿ã¤ãã³ã°ãåºå®ããã¦ãã¾ããå®è¡ã³ãã³ããã«ã¹ã¿ãã¤ãºãããå ´åã¯ãã§ã¼ãºãã¨ã«ã³ãã³ããä¸æ¸ããããããã§ã¼ãºã®åå¾ã«ã³ãã³ããå·®ãè¾¼ãã ããã¾ãã
2.0ã§ã¯ããã¸ã§ã¯ã種å¥ã®æ¨æ¸¬ã¯ãããã決ãããããã§ã¼ãºããªããªããèªåã§ã¹ããããå®ç¾©ãã¾ããã¾ãããã£ãã·ã¥ãä»»æã®ã¿ã¤ãã³ã°ã§æè»ã«è¡ããããã«ãªãã¾ããã
CircleCI 1.0ãã2.0ã¸ã®ç§»è¡
1.0æ代ã«CIãé ãã£ãè¦å
CrowdWorksã®å ´åã大ããªè¦å ã¨ãã¦Gitãªãã¸ããªã巨大ã§ãããã¨ã¨ãGemã®ã¤ã³ã¹ãã¼ã«ã«å¿ è¦ãªã©ã¤ãã©ãªãããã¹ãã«å©ç¨ããããã«ã¦ã§ã¢æ¬ä½ãªã©ããã£ãã·ã¥ã«å ¥ãã¦ããããããªã¹ãã¢ãããã®ãã¨ã¦ãé ãã£ãã§ãããããã£ãã©ã¤ãã©ãªãªã©ããã£ãã·ã¥ããããããã«ãdependenciesãã§ã¼ãºã¸å¦çãç¡çããè©°ãè¾¼ãã§ãããè¨å®ãã¡ã¤ã«ã®è¦éãã決ãã¦ãããã®ã¨ã¯è¨ãã¾ããã§ããã
ã¾ããCIã®ã³ã³ãããèµ·åããã¾ã§30ç§ãããæãããåã¹ããããå
¨ä½çã«ãã£ããã¨ãã¦ãããmkdir
ããã ããªã®ã«2ç§æãã£ãããããã¨ãããã¾ããã
ãã®ãããªã¹ãããã塵ãç©ãã£ã¦ãã»ããã¢ããã«10åãããæãã£ã¦ãã¾ã£ã¦ãã¾ããã
1.0ãã2.0ã«ç§»è¡ããéã«è¡ã£ããã¨
ãã«ãã¤ã¡ã¼ã¸ï¼ããã«ã¦ã§ã¢ã®Dockerå
CrowdWorksã§ã¯æ¢ã«ã»ããã¢ããæ¸ã¿ã®Dockerã¤ã¡ã¼ã¸ããã¼ã«ã«éçºç°å¢ã®ããã«ç¨æãã¦ãã£ãããã移è¡ãã¹ã ã¼ãºã§ããã
ããã«ãããã©ã¤ãã©ãªã®ã¤ã³ã¹ãã¼ã«ãããã«ã¦ã§ã¢ã®ã»ããã¢ããå¦çãä¸è¦ã«ãªãã¾ããã
ããã«ã¦ã§ã¢ã®ã³ã³ããã¸ã®æ¥ç¶ã¯localhostå®ã«éä¿¡ãã¾ãããã¼ãçªå·ã¯ã対象ã®ã³ã³ããã®ã¤ã¡ã¼ã¸ãä½ãããDockerfile
å
ã®EXPOSE
ã§æå®ããã¦ãããã¼ãçªå·ã§ãã注æç¹ã¨ãã¦ã¯IPv4ã§ããlistenããã¦ããªããããlocalhost
ã¨æå®ããã¨IPv6ã§æ¥ç¶ããèªåã§IPv4ã§åæ¥ç¶ãã¦ãããã¯ã©ã¤ã¢ã³ãã§ãªãå ´åã¯ã¨ã©ã¼ã«ãªã£ã¦ãã¾ãã¾ãããã®ããã127.0.0.1
ã¨æ示çã«IPã¢ãã¬ã¹ã§æå®ãã¦ããã¨ç¡é£ã§ãã
ããã«ã¦ã§ã¢ã®ã³ã³ããã®èµ·åãã§ãã¯
ã¾ããããããã¨éããªã£ããããã§ããã«ã¦ã§ã¢ã®ã³ã³ãããå©ç¨ãã段éã§ã³ã³ããã®èµ·åãéã«åããªãå ´åãããã¾ãããã®ããã以ä¸ã®ããã«ã³ã³ãããèµ·åããã¾ã§å¾ ã¤ãããªã¹ããããå ¥ãã¾ããã
- run: name: MySQLã®èµ·åãã§ã㯠command: | for i in $(seq $HEALTH_CHECK_RETRY_LIMIT) do mysql -h 127.0.0.1 -u root -e 'show databases' || (sleep $HEALTH_CHECK_RETRY_WAIT; false) && break done
HTTPãããã³ã«ã§ã¢ã¯ã»ã¹ã§ãããã®ã«ã¤ãã¦ã¯cURLã§ãã§ãã¯ã§ãã¾ãããcurl
ã³ãã³ãã®--retry
ãªãã·ã§ã³ã¯loopbackã¤ã³ã¿ã¼ãã§ã¼ã¹ã«ã¯å¹ããªããããèªåã§ã«ã¼ããæ¸ãå¿
è¦ãããã¾ãã
ã½ã¼ã¹ã³ã¼ãã®shallow clone
1.0ã§ã¯ã½ã¼ã¹ã³ã¼ãã®ãã§ãã¯ã¢ã¦ãå¦çã¯ä¸æ¸ãã§ãã¾ããã§ãããã2.0ã§ã¯çµã¿è¾¼ã¿ã®checkout
ã¹ããããå¼ã³åºããã«èªåã§ã½ã¼ã¹ã³ã¼ãã®åå¾å¦çãæ¸ããã¨ãã§ãã¾ãã
ããã©ã«ãã®checkout
ã¹ãããã¯ãclone & fetchã§ãã§ãã¯ã¢ã¦ãããããã«ãªã£ã¦ãã¾ããããã¦ãcloneæ¸ã¿ã®ãªãã¸ããªããã£ãã·ã¥ãã¦ããã2åç®ä»¥éã¯ãããç¨ããããã«ãã¾ãã3
ãããããªãã¸ããªã巨大ã ã¨ãã£ãã·ã¥ã®ãªã¹ãã¢ã«æéãæãã£ã¦ãã¾ãã¾ãã
ããã§shallow cloneã§åå¾ããããã«ããã¨ããããã£ãã·ã¥ãä¸è¦ãªã»ã©ã«éããªãã¾ããã
- run: name: GitHubã¸ã®HTTPSæ¥ç¶ã®èªè¨¼è¨å® command: echo "machine github.com login $GITHUB_TOKEN" > ~/.netrc - run: name: Gitãªãã¸ããªã®Checkout command: | repository_https_url=$(echo $CIRCLE_REPOSITORY_URL | sed -e "s|[email protected]:|https://github.com/|") git clone --depth=1 --branch $CIRCLE_BRANCH --single-branch $repository_https_url . git reset --hard $CIRCLE_SHA1 || (echo "ãã«ãå®è¡å¾ã«ãã©ã³ããæ´æ°ããã¾ãããRebuildãã¦ãã ããã" 1>&2; false)
ãã«ãã¤ã¡ã¼ã¸ã«SSHã¯ã©ã¤ã¢ã³ããã¤ã³ã¹ãã¼ã«ããªãã¦ãããã¨ããSSHãããé«éã§ãããã¨ãããHTTPSã§GitHubã«æ¥ç¶ãã¦ãã¾ããCircleCIã«ãã£ã¦ãªãã¸ããªã®URLãè¨å®ãããç°å¢å¤æ°CIRCLE_REPOSITORY_URL
ã¯ãSSHç¨ã®URLã«ãªã£ã¦ããããHTTPSã®URLã«ç½®æãã¦ãã¾ãã
ã¾ãããã©ã¤ãã¼ããªãã¸ããªã¸ã®HTTPSæ¥ç¶ã¯ãGitHubã®Personal access tokenãä¸è¨ã®ããã«~/.netrc
ã¸è¨å®ãããã¨ã§å¯è½ã§ãã
æ°ãã£ãã·ã¥æ©æ§ã®æ´»ç¨
2.0ã§è¿½å ãããæ°ãããã£ãã·ã¥æ©æ§ã¯ã¨ã¦ã便å©ã§ãã
ãã£ãã·ã¥ããã¼ãæã¤ããã«ãªããä»»æã®ã¿ã¤ãã³ã°ã§æå®ããããã¼ã®ãã£ãã·ã¥ãã»ã¼ã/ãªã¹ãã¢ã§ããããã«ãªãã¾ãããã¾ãããã£ãã·ã¥ãªã¹ãã¢æã«ãã¼ãè¤æ°æå®ã§ãã¾ãããã¼ã®ä¸è´å¤å®ãåæ¹ä¸è´ã§ãããã¨ãæ´»ç¨ãããã¨ã§ããã£ãã·ã¥ã®å¹æãæ大éæ´»ç¨ã§ããããã«ãªã£ã¦ãã¾ãã
- restore_cache: name: Restoring Cache - Bundler keys: - gems-{{ .Environment.COMMON_CACHE_KEY }}-{{ checksum "Gemfile.lock" }} - gems-{{ .Environment.COMMON_CACHE_KEY }}- - run: name: bundle installã®å®è¡ command: bundle install --path=vendor/bundle - save_cache: name: Saving Cache - Bundler key: gems-{{ .Environment.COMMON_CACHE_KEY }}-{{ checksum "Gemfile.lock" }} paths: - "/usr/src/app/vendor/bundle"
ä¸è¨ã®ä¾ã§ã¯ãã¾ãchecksum "Gemfile.lock"
ã®é¨åãå«ãã¦ãã¼ãå®å
¨ã«ä¸è´ãããã£ãã·ã¥ãåå¨ããå ´åããã®ãã£ãã·ã¥ããªã¹ãã¢ããã¾ããããã«ä¸è´ãããã£ãã·ã¥ãåå¨ããªãå ´åã¯ãkeys
ã«æå®ããã2çªç®ã®ãã¼ã«ã¤ãã¦åæ¹ä¸è´ã§ãã£ãã·ã¥ãæ¢ç´¢ããæãæ°ãããã£ãã·ã¥ããªã¹ãã¢ããã¾ããããã«ãã£ã¦ãå
¨ããã£ãã·ã¥ãåå¨ããªããã¨ããã±ã¼ã¹ãã»ã¼æé¤ãããã¨ãã§ãããããCIã®ã»ããã¢ããæéã大å¹
ã«ç縮ãããã¨ãã§ãã¾ãã
ãã£ãã·ã¥ãã¼ã®å ±éãã¬ãã£ãã¯ã¹ã®å°å ¥
ã¾ãããã£ãã·ã¥ã¯ãã¼ãã¨ã«ä¸å¤ã§ããããããã£ãã·ã¥ãåçæããããã«ãã¼ã¸ã§ã³ãã¬ãã£ãã¯ã¹ãä»ä¸ããTipsãå ¬å¼ããã¥ã¡ã³ãã«è¨è¼ããã¦ãã¾ãããããããã£ãã·ã¥ãåçæããããã«è¨å®ãã¡ã¤ã«ã®ç·¨éãå¿ è¦ã¨ããããªãã£ããããç°å¢å¤æ°ããã¼ã«ä½¿ç¨ã§ãããã¨ãå©ç¨ããCircleCIã®Webã®è¨å®ç»é¢ããç°å¢å¤æ°ãè¨å®ãã¦å©ç¨ããããã«ãã¾ããããããããã¨ã§ããã£ãã·ã¥ã§ä½ãåé¡ãèµ·ããå ´åãããã«åçæããããã¨ãã§ãã¾ãã
Gitã®ã³ãããããã·ã¥ã¨ã®çµã¿åãã
ããã«ãGitã®ã³ãããããã·ã¥ã¨çµã¿åããã¦é«éåãããã¨ãå¯è½ã§ããã³ã³ããã¼ã©ã¼ã®ãã¹ããé«éåãããããassets:precompile
ããããããå®è¡ãã¦ããã®ã§ããã次ã®ä¾ã§ã¯assets:precompile
ã®å¯¾è±¡ã«å¤æ´ãç¡ãã£ãå ´åã¯ãã£ãã·ã¥ããã®ã¾ã¾ä½¿ãããã«ãã¦ãã¾ãã
- run: name: assetsãã£ãã·ã¥ã®ãã¼ã¨ãªããã¡ã¤ã«çæ command: | ./.circleci/bin/get_git_revision "app/assets" > tmp/app-assets-revision cat tmp/app-assets-revision - restore_cache: name: Restoring Cache - assets:precompile keys: - assets-{{ .Environment.COMMON_CACHE_KEY }}-{{ checksum "tmp/app-assets-revision" }} - assets-{{ .Environment.COMMON_CACHE_KEY }}- - run: name: assets:precompile command: | current_assets_revision_file=tmp/app-assets-revision before_assets_revision_file=public/assets/app-assets-revision # assets:precompile対象ã®ãã¡ã¤ã«ãæ´æ°ããã¦ããªããã°ãã£ãã·ã¥ããã®ã¾ã¾ä½¿ã if [ ! -e $before_assets_revision_file ] || [ ! -e $before_frontend_revision_file ] || \ ! diff $before_assets_revision_file $current_assets_revision_file then bundle exec rake assets:precompile # Revisionãã¡ã¤ã«ãæ´æ° cp -f $current_assets_revision_file $before_assets_revision_file else echo "Skipped." fi - save_cache: name: Saving Cache - assets:precompile key: assets-{{ .Environment.COMMON_CACHE_KEY }}-{{ checksum "tmp/app-assets-revision" }} paths: - "/usr/src/app/tmp/cache/assets" - "/usr/src/app/public/assets"
./.circleci/bin/get_git_revision
ã§ã¯å¼æ°ã«æ¸¡ããããã¹ã®ææ°ã®ã³ãããã®ããã·ã¥ãåå¾ãã¾ããshallow cloneãã¦ããã¨ãã¹ã¦åãããã·ã¥ã«ãªã£ã¦ãã¾ããããGitHub APIã使ã£ã¦åå¾ãã¦ãã¾ããæ®éã«cloneãã¦ããå ´åã¯git
ã³ãã³ãã ãã§åå¾å¯è½ã§ãã
ãã®ããã·ã¥ããã£ãã·ã¥ã¨ä¸ç·ã«ä¿åãã¦ããããªã¹ãã¢ããããã£ãã·ã¥ã®ããã·ã¥ã¨ä¸è´ããå ´åã¯å¦çãã¹ããããã¾ãããã£ãã·ã¥ã¯ãªã¹ãã¢ãããããããã·ã¥ãä¸è´ããªãã¨ããå ´åã¯ãã£ãã·ã¥ã使ã£ã¦assets:precompileãå®è¡ãããã¨ããä»çµã¿ã«ãªã£ã¦ãã¾ãã
ãã®æ¹æ³ã使ã£ã¦ä¸è¦ãªã³ãã³ãã®å®è¡ãé¿ãããã¨ã§ãCIã®ã»ããã¢ããã«æããæéãããªãåããã¨ãã§ãã¾ããã
ã¾ã¨ã
塵ãç©ãã£ã¦10åãããã«ãªã£ã¦ããã»ããã¢ããæéã1åã«æãããã¨ãã§ãã¾ããã
以åã¯ãã«ããã¨ã®ã³ã³ããæ°ãå¢ããã¦ãã»ããã¢ããã®ãªã¼ãã¼ãããã大ããã£ãããå¹æãå°ããã£ãã®ã§ãããã»ããã¢ããæéãåæ¸ããããã¨ã«ãããã³ã³ããæ°ã®å¹æããã¹ãå®è¡ã«ç´çµããããã«ãªãã¾ãããããã§ä¸è¨ã®æ¹åã«å ããã³ã³ããæ°ãå¢ãããã¨ã§CIã®å®è¡æéãååã«ãªãã¾ããã
CIã®å®è¡æéãç縮ããããã¨ã«ããå¾ ã¡æéãæ¸ã£ããããã³ã³ããæ°ãå¢ããã¦ãåããã©ã³ã®ã¾ã¾é«ãå¹æãå¾ããã¾ããã
å½åã¯ããã¥ã¡ã³ããã»ã¨ãã©ãªãç¶æ ã ã£ãã®ã§ãããç¾å¨ã¯å å®ãã¦ãã¦ãã¾ããä¸ã§ãConfiguration Referenceã®ãã¼ã¸ã¯ç¶²ç¾ çãªã®ã§ç®ãéãã¦ã¿ãã¨ããã§ããããã¾ããä»åç´¹ä»ãããã®ä»¥å¤ã«ãDefining Multiple JobsããParallelism with CircleCI CLIã¨ãã£ãæ©è½ããããä»å¾è©¦ãã¦ã¿ãäºå®ã§ãã
ã¿ãªãããCircleCI 2.0ãæ´»ç¨ãã¦CIç°å¢ãæ¹åãã¦ã¿ã¦ãã ããã
We’re Hiring!
ã¯ã©ã¦ãã½ã¼ã·ã³ã°ã®ã¯ã©ã¦ãã¯ã¼ã¯ã¹ã§ã¯ã¨ã³ã¸ãã¢ãåéä¸ã§ã/ â°ââ° \
-
Dockerã«ã¯ç¹æ¨©ãä¿æãã¦ããªãLXCä¸ã§åä½ãããããªãã¨ããå¶ç´ãããããããåé¿ããããã«Dockerã¸ç¬èªããããå½ã¦ã¦ãããDocker 1.10ããã¢ã¸ã¥ã¼ã«ãåé¢ããããã¨ã«ããããããå½ã¦ãã®ãå³ãããªã£ããããå¤ããã¼ã¸ã§ã³ã使ãç¶ããããå¾ãªããªã£ã¦ãã¾ã£ãããã§ãã https://circleci.com/docs/2.0/migrating-from-1-2/#native-docker-support↩
-
PrivateãªDockerã¤ã¡ã¼ã¸ã使ã£ã¦CIãå®è¡ããå ´åã¯ãã®æ¹å¼ãç¨ãã¾ãã https://circleci.com/docs/2.0/private-images/↩
-
2.0ã§ã¯ãªãã¸ããªã®ãã£ãã·ã¥è¨å®ã¯æ示çã«æ¸ãå¿ è¦ãããã¾ãã↩