æ¦è¦
CircleCI2.0ã«Workflowsã¨ããæ©è½ãå°å ¥ããã¾ããã
ä»ã®ãã«ããã¼ã«ã§æ¢ã«ãã£ãããã«ããã¤ãã©ã¤ã³ã¨èããã°ããããããã¨æãã¾ãã ãããå°å ¥ããã¨ä½ãå¬ãããã¨ããã¨ã
- ãã«ãã®å®è¡ãã§ã¼ãºãè¤æ°ã«åãããã¨ã§ãã©ãã§Failããããªã©ãè¦è¦çã«æ´ã¿ããã
- 並åã«jobãå®è¡ããããã¨ã§é常ã®åæçãªãã«ãããã¼ãããå¹çè¯ãåãã
- å ·ä½çã«ã¯bundle installã¨ãnpm installã¨ãã並åã«åãã¦ãå ±æãã£ã¬ã¯ããªã«çµæãå ¥ãããã§ãã
- è²ã 並åã«jobãåãããã¨ããããå¾ ã¡åãã¦æçµçãªçµæãåæçã«åãåããã¨ãã§ãã
- branchãè¨èªã®ãã¼ã¸ã§ã³ã«ãã£ã¦å¥ã ã§ãã¹ããåãããæãªã©ã«å¥åãã¤ä¸¦åã«ãã«ããè¡ãã
- å¤é¨APIã«ã¤ãªãã«ããæã«failããå ´åãªã©ã§ã¯ã
Rerun from failed
ãã§ããã®ã§ãã±ã¼ã¹ã«ãã£ã¦ã¯å ¨å·¥ç¨ããªããå¿ è¦ããªããªã
ãªã©ã®ã¡ãªãããããã¾ãã
æ©éèªåã®ããã¾ã§ã®circle.ymlã®è¨å®ãå¤ãã¦è©¦ãã¦ã¿ã¾ãããå ã«ããè¨å®ãè¼ã£ã¦ããã®ã¯ãã®è¨äºã§ãã
ä»åã¯circleciå ¬å¼ã®ãªãã¸ããªã®è¨å®ãåèã«ä½ãç´ãã¦ã¿ãã®ã§ãå²ã¨ããã¡ã¯ãã¹ã¿ã³ãã¼ããªæ¸ãæ¹ã«ãã£ã¦ããã¯ãã§ãã æ¸ãæ¹ã®é¢ã§ã®å¤æ´ç¹ã¨ãã¦ã¯ã
- referencesã使ã£ã¦å®æ°ãã¾ã¨ãã¦ããã¨ãã
- primary imageã«docker clientã®ã¤ã³ã¹ãã¼ã«ã³ãã³ããçµã¿è¾¼ãã ã®ã§ããããyamlããé¤å»ããã¨ãã
ã§ãã
å ·ä½çãªè¨å®
version: 2.0
references:
container_config: &container_config
docker:
- image: timakin/golang-and-ruby-image
working_directory: ~/ansible_build
workspace_root: &workspace_root
/tmp/workspace
attach_workspace: &attach_workspace
attach_workspace:
at: *workspace_root
load_code: &load_code
run:
name: load code from workspace
command: |
# Move all files and dotfiles to current directory
mv /tmp/workspace/sample-ansible/* /tmp/workspace/sample-ansible/.[!.]* .
docker_container_cache_key: &docker_container_cache_key
key: docker-image-{{ .Branch }}-{{ checksum "Dockerfile" }}
jobs:
checkout_code:
<<: *container_config
steps:
- checkout
- run:
command: |
mkdir -p /tmp/workspace/sample-ansible
mv * .[!.]* /tmp/workspace/sample-ansible/
- persist_to_workspace:
root: *workspace_root
paths:
- sample-ansible
spec:
<<: *container_config
steps:
- *attach_workspace
- *load_code
- setup_remote_docker
- restore_cache:
<<: *docker_container_cache_key
name: Restore a docker image tarball cache
paths:
- /image_cache/ansible_test_image.tar
- run:
name: Build Docker image
command: |
if [[ -e /image_cache/ansible_test_image.tar ]]; then
cat /image_cache/ansible_test_image.tar | docker import - timakin/ansible_test_image
docker load --input /image_cache/ansible_test_image.tar
else
docker build -t timakin/ansible_test_image .
if [[ ! -e /image_cache ]]; then
mkdir /image_cache -m 755
fi
docker save -o /image_cache/ansible_test_image.tar timakin/ansible_test_image
fi
- save_cache:
<<: *docker_container_cache_key
name: Save a docker image tarball cache
paths:
- /image_cache/ansible_test_image.tar
- run:
name: Attach provisioning settings to the container for ansible-test
command: |
ANSIBLE_TEST_CONTAINER_ID=$(docker run -dit timakin/ansible_test_image /bin/bash)
docker cp ansible/ $ANSIBLE_TEST_CONTAINER_ID:/ansible
docker exec $ANSIBLE_TEST_CONTAINER_ID /bin/sh -c 'ansible-playbook /ansible/ci.yml -s -i /ansible/inventory_localhost -c local -v && cd /ansible/spec && /home/root/.rbenv/bin/rbenv exec bundle install && /home/root/.rbenv/bin/rbenv exec bundle exec rake spec'
workflows:
version: 2
build_and_test:
jobs:
- checkout_code
- spec:
requires:
- checkout_code
é·ãã®ã§ç«¯æã£ã¦æ¸ãã¨ãjobs
ã§åå¥ã®ããã¼ãå®ç¾©ãã¦ãworkflows
ã§ãããã©ããªä¾åé¢ä¿ã§ãã©ããªé çªã§è¡ãããå®ç¾©ãã¦ãã¾ãã
å ·ä½çã«ä½ããã¦ãããã¨ããã¨ããµã³ãã«ã¨ãã¦2ã¤ã®ã¸ã§ããå®è¡ãã¦ãã¾ãã¦ã以ä¸ããã®å 容ã§ãã
checkout_code job
- ã½ã¼ã¹ãcheckoutãã¦ãã
spec job
- ansibleã®ãã¹ãç¨ã®docker containerãç«ã¦ã
- serverspecãã¹ãã®å®è¡
workflowsã§ç¹å¾´çãªç¹
ããã¤ãworkflowsãå©ç¨ããã«ããã£ã¦è¨å®ãå¤æ´ãã¾ããããsyntax以å¤ã«ä¸è¨ã®ç¹ãéè¦ã«ãªã£ã¦ãã¾ãã
ããããã®ã¸ã§ãã§å¿ è¦ãªç°å¢ã®ã»ããã¢ãã
<<: *container_config
ã¨ããæ¸ãæ¹ã§ãã«ãç¨ã®primary imageãèªã¿è¾¼ãã§ãã¾ãã
ä»åã¯ä¸åã®imageã使ã£ã¦ããã®ã§ãå ¨ã¦ã®ã¸ã§ãã§ä¸è¨ã®ã³ã³ããè¨å®ãèªã¿è¾¼ãã°ããã§ããã
ããè¨èªã®ãã¼ã¸ã§ã³ãã¨ã«ãã«ãç¨ã®primary imageãå¤ããæãªã©ã¯ãä¸è¨è¨å®ãåå¥ã«è¡ãå¿ è¦ãããã¾ãã
ã¸ã§ãéã§ã®ææç©å ±æ
persist_to_workspace
ã¨ãããªãã·ã§ã³ã§ãcheckout_codeã¸ã§ãã§checkoutãã¦ããã³ã¼ãããspecã¸ã§ãã«å
±æãã¦ãã¾ãã
ããããªãã¨ãåã¸ã§ãå é¨ã®ç°å¢ã¯åºå¥ããã¦ããã£ããããã¼ã®æµããå®ç¾©ãã¦ãæå³ããªãã®ã§æ³¨æãã¾ãããã
ä¾åããã±ã¼ã¸ã®ã¤ã³ã¹ãã¼ã«ãªã©ã並åã§è¡ãå ´åã¯ãä¸è¨ã®ãªãã·ã§ã³çµç±ã§ä¸ã¤ã®ãã£ã¬ã¯ããªã«ã¾ã¨ããå¾ãdeployãªãteståããªãããã°ãããã¨ãããã¨ã«ãªãã¾ãã
ãã«ãã®ä¾åé¢ä¿ã»é åºã®å®ç¾©
以ä¸ã®è¨å®ããä»åã®workflowsã®å°å
¥ã«ããã¡ã¤ã³ã®å·®åã§ãã build_and_test
ã®ã¨ããã¯ãbuild_and_test_and_deploy
ãªã好ãã«è¨å®ãã¦ãã ããã
requires
ã¨ãããªãã·ã§ã³ã§ããã®ã¸ã§ãã«ã¯ã©ããªä¾åé¢ä¿ãããããè¨è¼ãã¦ãã¾ãã ãããããè¨å®ããªããã°ããã®ã¸ã§ãã«ä¾åãã次ã®ã¸ã§ãã¾ã§ã¯ãç¹ã«å¶éãªã並åã§ãã«ããè¡ããã¾ãã
ã¾ããfilters
ã¨ãããªãã·ã§ã³ã§ãã«ãç¨ãã©ã³ããæå®ãããã§ãã¾ãã
注æç¹ã¨ãã¦ãrequiresã®ãªãã·ã§ã³ããspecã¨ããæååããåè§ã¹ãã¼ã¹4ã¤åããã¦è¨å ¥ããªãã¨ããã«ããããããå§ã¾ããªãã¦ã¨ã©ã¼ãåºãªããªã©ã®ãã°ãèµ·ãã¾ããç¹å®ã«æéãããã£ã¦ä½åãæ¶è²»ããã¾ããã
workflows:
version: 2
build_and_test:
jobs:
- checkout_code
- spec:
requires:
- checkout_code
ã¾ã¨ã
ä¸è¨ã®éããå°ãè¨å®ãå¤ããã ãã§workflowsã®æ©æµãå¾ããã¨ãã§ãã¾ãã
ä»åã®ä¾ã¯2ã¹ããããããªãã®ã¨ãå¥ã«ä¸¦åã«åããã®ã§ããªãã£ãã®ã§ãããããã³ãã¨ã³ããããã¯ã¨ã³ãã®ä¸¡æ¹ã§ä¾åããã±ã¼ã¸ãå¤ããä¸ã»å¤§è¦æ¨¡ãªAPIã®ãã«ã & ãããã¤ã«ã¯éå®ãããã§ãã