ååã®ç¶ãã
ãããã¤ã®ã¨ã©ã¼å¦çï¼æ¤ç¥ï¼ã«ã¤ãã¦
ä»»æã®ã³ãã³ããå®è¡åºæ¥ããã
stretcher ã«ã¯ãããã¤ããã»ã¹ãæåããéã失æããéã«ä»»æã®ã³ãã³ããå®è¡ãããã¨ãåºæ¥ãããã ã
以ä¸ã¯ README ããã®æç²ã
commands: pre: - echo 'staring deploy' post: - echo 'deploy done' success: - echo 'deploy success' failure: - echo 'deploy failed!!' - cat >> /path/to/failure.log
ä»»æã®ã³ãã³ããå®è¡åºæ¥ãã¨ãããã¨ã¯ãä¸è¨ã®ä¾ã®ããã«ãã¡ã¤ã«ã¸ã®ãã°ã®åºåã Slack çã¸ã®éç¥ã fluentd 㸠JSON ã¡ãã»ã¼ã¸ã転éããããããã¨ãåºæ¥ããã§ãããã対象ã®å°æ°ãå¤ããªã㨠Slack çã®éç¥ãå端ãªãæ°ã«ãªã£ã¦ãã¾ããªã©ã®èª²é¡ãç¡ãããã§ããªãã
æå or 失æ
æåã¨å¤±æã¯ã©ã®ããã«å¤å®ããã¦ããã®ãã¯ã½ã¼ã¹ã³ã¼ããè¦ãã°...ã¨æã£ãããæ®å¿µãªããã½ã¼ã¹ã³ã¼ããè¦ãè½åãç¡ãã®ã§å®éã«è©¦ãã¦ã¿ãã
以ä¸ã®ããã« post
ã§å®è¡ããã³ãã³ãã exit 1
ã ãã«ãããããã§ã¹ããæ¸ãã¦ãããã¤ãå®è¡ãã¦ã¿ãã
src: http://consul_deploy:8000/app.tar.gz checksum: 4b4fedd8ef18df2b42134fa81bbc75bc dest: /tmp/service commands: pre: - echo 'staring deploy' >> /tmp/stretcher.log post: - exit 1 success: - echo 'deploy success' >> /tmp/stretcher.log failure: - echo 'deploy failed!!' >> /tmp/stretcher.log
å¼ãç¶ããpost
ã§å®è¡ããã³ãã³ãã 0
ã«å¤ãã¦ãããã¤ãå®è¡ãã¦ã¿ãã
src: http://consul_deploy:8000/app.tar.gz checksum: 4b4fedd8ef18df2b42134fa81bbc75bc dest: /tmp/service commands: pre: - echo 'staring deploy' >> /tmp/stretcher.log post: - exit 0 success: - echo 'deploy success' >> /tmp/stretcher.log failure: - echo 'deploy failed!!' >> /tmp/stretcher.log
ãããã¤å ã§ã¯ä»¥ä¸ã®ãããªãã°ãè¨é²ãããã
$ cat /tmp/stretcher.log staring deploy deploy failed!! staring deploy deploy success
ã©ããã post
ã§å®ç¾©ããã¦ããã³ãã³ãã®çµäºã³ã¼ãã 0
以å¤ã®å ´åã«ã¯ failure
ã«ã¦å®ç¾©ããã¦ããã³ãã³ããå®è¡ãããããã ãï¼â» pre
ã§ã³ãã³ããå®ç¾©ããã¦ããå ´åã«ãåãããã ãï¼
Consul ã使ã£ãã¨ã©ã¼å¦çå®è£ æ¡
ã¨ãããã¨ã§ãConsul ãå©ç¨ããã¨ã©ã¼ã®å¤å®ã«ã¤ãã¦å¤ã£ãï¼ã¤ããï¼ã¨ããã§ããããã¤æã®ã¨ã©ã¼å¦çã«ã¤ãã¦èãã¦ã¿ããå°ãã¨ã©ã¼å¦çã¨ããã¨ç¯å²ãåºãã®ã§ä»åã¯ã¨ã©ã¼æ¤ç¥æ¹æ³ã試ãã¦ã¿ãã
æ¡ï¼1ï¼KVS + consul-kv-dashboard ãå©ç¨ãã
ã¤ã¡ã¼ã¸
試ã
consul-kv-dashboard ã«ã¤ãã¦ã¯ä»¥ä¸ã®è¨äºã«ã¦ã
consul-kv-dashboard ãå©ç¨ã㦠KVS ã®æ å ±ãåå¾ããå ´åã«ã¯ç»é²ãããã¼ã¯ä»¥ä¸ã®ããã«å®ç¾©ããå¿ è¦ãããã...
/v1/kv/{namespace}/{category}/{node}(/{key})?flags={flags}
éãè¨ãã¨ãä¸è¨ã®ãã¼ã«å¾ãã°ç°¡åã« consul-kv-dashboard ãå©ç¨ãããã¨ãåºæ¥ãã®ã§ã以ä¸ã®ãããªã·ã§ã«ã¹ã¯ãªãããç¨æãã¦...
#!/bin/sh datetime=`date +%s` result_str=$1 result_code=$2 datetime_code=`expr ${datetime} \* 1000 + ${result_code}` node_name=`curl -s localhost:8500/v1/agent/self | python -c "exec(\"import json,sys\\nj=json.load(sys.stdin)\\nprint j['Member']['Name']\")"` curl -X PUT -d "{\"result\": \"${result_str}\", \"timestamp\": \"${datetime}\"}" "localhost:8500/v1/kv/dashboard/deploy/${node_name}/result?flags=${datetime_code}"
result.sh ã¨ãããã¡ã¤ã«åã§ä¿åãã¦å®è¡æ¨©éãä»ä¸ãã¦ãããã¤ããã±ã¼ã¸ã«å«ãã¦ããã
æ´ã«ãããã§ã¹ãã® command
ã® success
㨠failure
ã以ä¸ã®ããã«è¨å®ããã
src: http://consul_deploy:8000/app.tar.gz checksum: 4b4fedd8ef18df2b42134fa81bbc75bc dest: /tmp/service commands: pre: - echo 'staring deploy' >> /tmp/stretcher.log post: - sed -i "s/$/`hostname -s`/g" /tmp/service/app/html/index.html - pkill python; pushd /tmp/service/app/html; /tmp/service/app/start.sh > /dev/null 2>&1 success: - echo 'deploy success' >> /tmp/stretcher.log - /tmp/service/app/result.sh success 0 failure: - echo 'deploy failed!!' >> /tmp/stretcher.log - /tmp/service/app/result.sh failure 2
å®éã«ãããã¤ãã¦ã¿ãã
/usr/local/bin/consul event -node="consul_0" -name deploy_demo http://consul_deploy:8000/deploy.yml
以ä¸ã®ããã«çµæãåæ ããã¦ããã
æå³çã«å¤±æããã¦ã¿ãï¼exit 1
ãã¦ã¿ãï¼ã
ç´ æ´ããã²ã
ã¡ãªãã¡
- è¤æ°ã®ãã¼ãã®çµæãä¸ã¤ã®ç»é¢ã§ãªã¢ã«ã¿ã¤ã ã«ç¢ºèªãããã¨ãåºæ¥ãï¼ã¡ãªï¼
- è¤éãªéçºçãä¸è¦ã§ãããã§ã¹ããä¿®æ£ããã ãã§å°å ¥ãããã¨ãåºæ¥ãï¼ã¡ãªï¼
- Consul ã¯ã©ã¹ã¿å ã®ãã¼ãã®ä½ããã«ã¤ã³ã¹ãã¼ã«ãã¦ããã ãã§è¯ãï¼ã¡ãªï¼
- ç¹ã«ãã¡ãªããã¯æããªãï¼å¼·ãã¦ããã° consul-kv-dashboard ã®ããã»ã¹ç®¡çãå¿ è¦ã«ããï¼ï¼ãã¡ï¼
æ¡ï¼2ï¼KVS + Consul watch + ã¹ã¯ãªãããå©ç¨ãã
ã¤ã¡ã¼ã¸
試ã
ãã¡ãã®ãããªã¹ã¯ãªããããã³ãã©ã¨ã㦠consul watch
ãä»»æã®ãã¼ãï¼ãããã¤ã¤ãã³ããéããã¼ãåã¯å°ç¨ã®ãã¼ãï¼ã«ã¦èµ·åãããå°ãconsul watch
ã® type
㯠keyprefix
ãæå®ãããã¨ã§ãdeploy/
ãã¼ãå«ãå
¨ã¦ã®ãã¼ã®å¤åãæ¤ç¥ãã¦ãã³ãã©ãèµ·åãããã¨ãåºæ¥ãã
consul watch -type keyprefix -prefix deploy/ /path/to/result_hook.py &
ã¾ããresult.sh ã以ä¸ã®ããã«ä¿®æ£ããã
#!/bin/sh datetime=`date +%s` result_str=$1 datetime_code=`expr ${datetime} \* 1000 + ${result_code}` node_name=`curl -s localhost:8500/v1/agent/self | python -c "exec(\"import json,sys\\nj=json.load(sys.stdin)\\nprint j['Member']['Name']\")"` curl -X PUT -d "{\"result\": \"${result_str}\", \"timestamp\": \"${datetime}\"}" "localhost:8500/v1/kv/deploy/${node_name}/result?flags=${datetime}"
æ´ã«ãããã§ã¹ãã以ä¸ã®ããã«å°ãä¿®æ£ã
src: http://consul_deploy:8000/app.tar.gz checksum: 4b4fedd8ef18df2b42134fa81bbc75bc dest: /tmp/service commands: pre: - echo 'staring deploy' >> /tmp/stretcher.log post: - sed -i "s/$/`hostname -s`/g" /tmp/service/app/html/index.html - pkill python; pushd /tmp/service/app/html; /tmp/service/app/start.sh > /dev/null 2>&1 success: - echo 'deploy success' >> /tmp/stretcher.log - /tmp/service/app/result.sh success failure: - echo 'deploy failed!!' >> /tmp/stretcher.log - /tmp/service/app/result.sh failure
å®éã«ãããã¤ãã¦ã¿ãã
# ãããã¤ã¤ãã³ãçºè¡ $ /usr/local/bin/consul event -node="consul_0" -name deploy_demo http://consul_deploy:8000/deploy.yml Event ID: 6d29dafa-763a-8f80-3436-80239b5d5e20 # 以ä¸ã®ããã«çµæãåºåããã 2015-07-08 08:21:56 4991 consul_01 {"result": "failure", "timestamp": "1436343716"} 2015-07-08 08:21:56 4989 consul_02 {"result": "failure", "timestamp": "1436343716"} 2015-07-08 08:21:56 4990 consul_03 {"result": "failure", "timestamp": "1436343716"}
ãããã¤æåã®å ´åã§ã...
# ãããã¤ã¤ãã³ãçºè¡ $ /usr/local/bin/consul event -node="consul_0" -name deploy_demo http://consul_deploy:8000/deploy.yml Event ID: 2f62c232-ebdf-feec-6562-8875011da110 # 以ä¸ã®ããã«çµæãåºåããã 2015-07-08 08:24:08 4996 consul_01 {"result": "success", "timestamp": "1436343848"} 2015-07-08 08:24:08 4995 consul_02 {"result": "success", "timestamp": "1436343848"} 2015-07-08 08:24:08 4994 consul_03 {"result": "success", "timestamp": "1436343848"}
ä¸å¿ããã°ã£ã½ããã®ã表示ãããããã¡ããããã°åºå以å¤ã«éç¥çããã³ãã©ã¹ã¯ãªããã«æãå ãããã¨ã§å¯¾å¿ãããã¨ãåºæ¥ãã
ã¡ãªãã¡
- Consul ã®æ©è½ + ãã³ãã©ã¹ã¯ãªããã ãã§å®çµåºæ¥ãï¼ã¡ãªï¼
- ãã³ãã©ã¹ã¯ãªããã®åºæ¥æ¬¡ç¬¬ï¼ã¡ããã¨ä½ãè¾¼ããã°ãããªãã«...ï¼ï¼ã¡ãªï¼
consul watch
ã®æåãã¡ããã¨ææ¡ãã¦ããªãã¨ãã©ã¤ï¼ãã¡ï¼- ç»é¢ã§ã®ç¢ºèªãåºæ¥ãªãï¼ãã¡ï¼
ã¨ãããã¨ã§...
stretcher ã§ãããã¤ãè¡ã£ãéã®ã¨ã©ã¼å¦çï¼ã¨ã©ã¼æ¤ç¥ï¼ã«ã¤ãã¦ã¯ consul-kv-dashboard ãå©ç¨ããã¨è¯ãã¨æãããã