ããã«ã¡ã¯ãã³ãããã®éçºé¨ãã©ãããã©ã¼ã ã°ã«ã¼ãã§ã¤ã³ãã©ã¨ã³ã¸ãã¢ããã¦ãã @sasashuuu ã§ããæ¬æ¥ã¯ç§ã®æå±ãããã¼ã ãæè¿èå³ã»é¢å¿ãæã£ã¦åãçµãã§ãããã©ãããã©ã¼ã ã¨ã³ã¸ãã¢ãªã³ã°ã®è©±é¡ã«ã¤ãã¦åãä¸ãããã¨æãã¾ããå¼ç¤¾ã§è¡ã£ã¦ããã«ããªã¢ãªãªã¼ã¹ã®éç¨æ¹åã®è©±ã«ãªãã¾ãã
ã¯ããã«
ã¯ããã«æ¬è¨äºã®ä¸å¿ã¨ãªããã©ãããã©ã¼ã ã¨ã³ã¸ãã¢ãªã³ã°ã¨ã«ããªã¢ãªãªã¼ã¹ã®æ¦è¦ã«ã¤ãã¦ç°¡åã«è§¦ãã¦ããã¾ãã
ãã©ãããã©ã¼ã ã¨ã³ã¸ãã¢ãªã³ã°ã¨ã¯ã誤解ãæããã«ç«¯çã«è¨ãã°ã¢ããªã±ã¼ã·ã§ã³éçºè ã®ããã®ãã©ãããã©ã¼ã ã®éçºã¨æä¾ãè¡ãã¢ããã¼ãã®ãã¨ã§ãGartner 社㮠ãã©ãããã©ã¼ã ã»ã¨ã³ã¸ãã¢ãªã³ã°ã¨ã¯ä½ãï¼ ã®è¨äºã§ã¯ä¸è¨ã®ããã«è§£èª¬ããã¦ãã¾ãã
ããã©ãããã©ã¼ã ã»ã¨ã³ã¸ãã¢ãªã³ã°ãã¨ã¯ãã¢ããªã±ã¼ã·ã§ã³ã®ããªããªã¨ãã¸ãã¹ä¾¡å¤ã®åµåºãå éãããããã®ããã¯ããã¸ã«å¯¾ããæ°ããã¢ããã¼ãã§ãã
- ãã©ãããã©ã¼ã ã»ã¨ã³ã¸ãã¢ãªã³ã°ã¯ãåå©ç¨å¯è½ãªãã¼ã«ã¨ã»ã«ããµã¼ãã¹æ©è½ãå®è£ ããã¤ã³ãã©ã¹ãã©ã¯ãã£ã»ãªãã¬ã¼ã·ã§ã³ãèªååãããã¨ã§ãéçºè ã®ã¨ã¯ã¹ããªã¨ã³ã¹ã¨çç£æ§ãåä¸ããã
- æ°ããªãã¯ããã¸ã®ã¢ããã¼ãã§ãããã©ãããã©ã¼ã ã»ã¨ã³ã¸ãã¢ãªã³ã°ã¯ãã¢ããªã±ã¼ã·ã§ã³ã®åå©ç¨å¯è½ã§æ§æå¯è½ãªã³ã³ãã¼ãã³ãã¨ãµã¼ãã¹ãæ´»ç¨ãã
- ã¦ã¼ã¶ã¼ã«ã¨ã£ã¦ã¯ãæ¨æºåããããã¼ã«ã¨ã³ã³ãã¼ãã³ããããã¦èªååãããããã»ã¹ãå©ç¨ã§ããã¨ããã¡ãªããããã
ã«ããªã¢ãªãªã¼ã¹ã¨ã¯ãã¢ããªã±ã¼ã·ã§ã³ãã¦ã¼ã¶ã¼å ¨ä½ã«å ¬éããã®ã§ã¯ãªããé 信対象è ãä¸é¨ã«çµã£ãå½¢ã§å ¬éããææ³ã®1ã¤ã§ãã
ãªãä»ãã©ãããã©ã¼ã ã¨ã³ã¸ãã¢ãªã³ã°ãªã®ã
å¼ç¤¾ã§ã¯ä¼ç¤¾è¨ç«ã¨ãµã¼ãã¹ã®å ¬éãã10å¨å¹´ã®ç¯ç®ãè¿ãããããã¯ãã®æé·ãèããä¸ã§ãéè¦ãªå±é¢ãè¿ãã¦ãã¾ãã ãã®ãããªä¸ããããã¯ãéçºã®åç·ã§åã社å ã®ã¨ã³ã¸ãã¢ã®ããã«ããã¯ã«ãªã£ã¦ããé¨åã解æ¶ããéçºä½é¨ãä¸ãããã¨ã§ãéçºåã®åä¸ãå³ãããã¨èãããã®é åã«åãå ¥ãã¦ããããã¨èãã¦ãã¾ãããã®åãçµã¿ã®ä¸ç°ã¨ãã¦ãéçºä½é¨ãä¸ããè¦å ã®1ã¤ã§ãã£ãå¼ç¤¾ã®ã«ããªã¢ãªãªã¼ã¹ã®éç¨èª²é¡ã«åãåãã¾ããã
åæã¨ãªãç°å¢
ä»åã®äºä¾ã§ã¯ä¸»ã«ä¸è¨ã®æè¡ã¹ã¿ãã¯ãªã©ããæ§æãããå 容ãã¡ã¤ã³ã¨ãªã£ã¦ããã¾ãã
- ã¤ã³ãã©ç°å¢
- AWS
- Docker
- ã¢ããªã±ã¼ã·ã§ã³ç°å¢
- PHP
- CakePHP
- CI/CD
- GitHub Actions
æ¹åã®å ¨ä½å
ãã£ããã¨æ¹åå 容ã®ã¤ã¡ã¼ã¸ãæ´ãã§ããã ãããã«ãæ¹ååã®ç¶æ ã¨æ¹åå¾ã®ç¶æ ãå³ã§è¡¨ãããã®ãç´¹ä»ãã¾ãã詳細ã¯è¿½ã£ã¦è§£èª¬ãã¦ããã¾ãã
èæ¯ã»èª²é¡æ
å¼ç¤¾ã§ãã©ã³ã¿ã¤ã ããã¬ã¼ã ã¯ã¼ã¯ã®ãã¼ã¸ã§ã³ã¢ããä½æ¥ãªã©ãã¢ããªã±ã¼ã·ã§ã³ã«ããã¦å½±é¿åº¦ã®å¤§ãããªãªã¼ã¹ã«é¢ãã¦ã¯ãã«ããªã¢ãªãªã¼ã¹ãç¨ãã¦ãªãªã¼ã¹ä½æ¥ãè¡ãªã£ã¦ãã¾ããããããéç¨é¢ã§æ±ãã課é¡æãããã¾ããã
å ã è¡ãªã£ã¦ããã«ããªã¢ãªãªã¼ã¹ã®æµãã¯ä¸è¨ã®ãããªãã®ã§ãã
ä¸è¨ã®ããã¼ã«ã¯ãããã課é¡æãããã¾ããã
ãã¼ã ãè·¨ãã 調æ´ã³ã¹ããåæ æ¼ãã®ãªã¹ã¯
æåã«ã¢ããªã±ã¼ã·ã§ã³ã¨ã³ã¸ãã¢ããã¤ã³ãã©ã¨ã³ã¸ãã¢ã¸ã«ããªã¢ãªãªã¼ã¹ã®å¯¾å¿ä¾é ¼ãæ¥ã¾ããäºãã«ã¹ã±ã¸ã¥ã¼ã«ãªã©ã調æ´ãããªãªã¼ã¹ã®æ¥æãªã©ã決ãã¦ãã¾ãããããã¼ã ãè·¨ãã 調æ´ã³ã¹ããªã©ãããã£ã¦ãã¾ããã
ããã«ãã¢ããªã±ã¼ã·ã§ã³ã¨ã³ã¸ãã¢ããã³ã¼ãããªã¼ãº ã®ç¢ºèªãé£çµ¡ãåãã¦ããã¤ã³ãã©ã¨ã³ã¸ãã¢ãæå㧠ECR ç¨ã® Docker ã¤ã¡ã¼ã¸ã build ãã push ãã¦ããã®ã§ã調æ´ã³ã¹ãã®çºçãåæ æ¼ãçºçã®ãªã¹ã¯ãªã©ãããã¾ããã
ä½æ¥æã®äººçãªã½ã¼ã¹ãã³ãã¥ãã±ã¼ã·ã§ã³ã³ã¹ã
ãªãªã¼ã¹å½æ¥ã¯ãåºæ¬çã«ä¸è¨ã®ãããªä½æ¥ãã¤ã³ãã©ã¨ã³ã¸ãã¢ãè¡ããã¢ããªã±ã¼ã·ã§ã³ã¨ã³ã¸ãã¢ãã¢ããªã±ã¼ã·ã§ã³ã®ç¶æ³ãç£è¦ãã¤ã¤ãã©ãã£ãã¯å²åã®å¤æ´ã«é¢ããææ決å®ãè¡ããã¤ã³ãã©ã¨ã³ã¸ãã¢ããã©ãã£ãã¯å²åã調æ´ãã¦ããã¨ãããããªé£æºãåã£ã¦ãã¾ããããªãªã¼ã¹ä½æ¥ã§ã¯ã¢ããªã±ã¼ã·ã§ã³ã¨ã³ã¸ãã¢ã¨ã¤ã³ãã©ã¨ã³ã¸ãã¢æ°åãåæçã«éã¾ãä½æ¥ãè¡ãªã£ã¦ãã¾ããããä½æ¥å 容ã«å¯¾ãã人çãªã½ã¼ã¹ãã³ãã¥ãã±ã¼ã·ã§ã³ã³ã¹ããå°ãªããªãå°è±¡ã§ãããã¾ããªãªã¼ã¹ä½æ¥èªä½ã®ãªãã¬ã¼ã·ã§ã³ã«é¢ãã¦ã¯ãé«åº¦ãªã¤ã³ãã©æè¡ãæ±ãããããã®ã§ã¯ãªãã権éããããã°æé ã«æ²¿ã£ã¦ã¤ã³ãã©ã¨ã³ã¸ãã¢ä»¥å¤ãè¡ãããããªå 容ã§ããã
æ¹åã«ããããããããå¹æ
æ¹åå¾ã¯ä¸è¨ã®ããã«ãªãã¾ãããæ¹ååã®ããã¼ãå度併ãã¦ä¸¦ã¹ã¦ããã¾ãã
before
after
ä¸è¨ã®ãããªéç¨ã«æ¹åãããã¨ã§æ±ãã¦ãã課é¡æãªã©ã解æ¶ããã¾ããã
æåä½æ¥ã®èªååãå³ãä½æ¥ãã¤ã³ãã©ã¨ã³ã¸ãã¢ããæé¢ã
GitHub Actions ã®ã¯ã¼ã¯ããã¼ãå®è¡ããã¨ã«ããªã¢ãªãªã¼ã¹ç¨ Docker ã¤ã¡ã¼ã¸ã® ECR ã¸ã® push ãã ECS ã®ã¿ã¹ã¯å®ç¾©ããã³ãµã¼ãã¹ã®æ´æ°ãä¸è²«ãã¦è¡ãªã£ã¦ããããããã«ããªã¢ç°å¢ã®ç«ã¡ä¸ãã«ã¤ã³ãã©ã¨ã³ã¸ãã¢ãå¹²æ¸ãããã¨ãªããã¢ããªã±ã¼ã·ã§ã³ã¨ã³ã¸ãã¢ã«ç¬åã§ãã£ã¦ããããããã«ãªãã¾ããã Manually running a workflow ã«è¨è¼ã®ããã«ããã©ã³ãæå®ããã¯ã¼ã¯ããã¼ãæåå®è¡ã§ããããã«ãããã¨ã§ãã¢ããªã±ã¼ã·ã§ã³ã¨ã³ã¸ãã¢ã®ä»»æã®ã¿ã¤ãã³ã°ã§ã«ããªã¢ç°å¢ãç«ã¡ä¸ããããããã«ãã¾ããã ã¯ã¼ã¯ããã¼ã§ã¯ ECR ç¨ã®ã¤ã¡ã¼ã¸ã® build ~ push ãèªååããä»ããããã¤ãã¼ã«ã« kayac/ecspresso ã使ç¨ãããã¨ã§ãã«ããªã¢ç°å¢ã¸ã®ãããã¤ãç°¡ç´ åãã¾ããã
ã¾ããGNU Make ã¨ã·ã§ã«ã¹ã¯ãªããã§å®è£ ããã¿ã¹ã¯ã©ã³ãã¼ãå°å ¥ãã¾ããã ã«ããªã¢ç°å¢ã¸ã®ãã©ãã£ãã¯ã ALB ã®å éã«ã¼ãã£ã³ã°ã§èª¿æ´ãããã¼ã«ã¨ãªã£ã¦ãããå®è£ å 容㯠AWS CLI ã®ã³ãã³ãã make ã³ãã³ãã®ã¤ã³ã¿ã¼ãã§ã¼ã¹ã§å®è¡ããã¨ãããã®ã§ãã
ãã¡ãã¯ã¤ã¡ã¼ã¸ãã¤ãã«ãããããããªãã®ã§ããµã³ãã«ã³ã¼ãã®ä¸é¨ãè¼ãã¦ããã¾ãã
Makefile
.PHONY: {ã«ããªã¢ãªãªã¼ã¹å¯¾è±¡ã®ãããã¯ãå}_modify_weighted_routing {ã«ããªã¢ãªãªã¼ã¹å¯¾è±¡ã®ãããã¯ãå}_modify_weighted_routing: bash utils/modify_weighted_routing.sh {ã«ããªã¢ãªãªã¼ã¹å¯¾è±¡ã®ãããã¯ãå}
modify_weighted_routing.sh
#!/bin/bash set -eu # ã«ããªã¢ãªãªã¼ã¹å¯¾è±¡ã®ãããã¯ãå TARGET_PRODUCT_NAME=$1 # ã«ããªã¢ã»æ¬çªç°å¢ã®å éã«ã¼ãã£ã³ã°å²å(%) CANARY_PERCENTAGE=1 PRD_PERCENTAGE=99 # HTTPã»HTTPSã®ãªã¹ãã¼ã®arn HTTP_LISTNER_ARN= HTTPS_LISTNER_ARN= # ã«ããªã¢ã»æ¬çªç°å¢ã®ã¿ã¼ã²ããã°ã«ã¼ãã®arn CANARY_TARGET_GROUP_ARN= PRD_TARGET_GROUP_ARN= # ã¡ã¤ã³é¢æ° function main () { echo "${TARGET_PRODUCT_NAME}ã®å éã«ã¼ãã£ã³ã°å²åå¤æ´éå§ã" # 対象ãããã¯ãåºæã®è¨å®æ å ±èªã¿è¾¼ã¿ source ./env/${TARGET_PRODUCT_NAME} # å éã«ã¼ãã£ã³ã°å²åã®ã»ãã set_weight_percentage # ãªã¹ãã¼ã®ããã©ã«ãã¢ã¯ã·ã§ã³å¤æ´ modify_default_actions $HTTP_LISTNER_ARN $HTTPS_LISTNER_ARN echo "å éã«ã¼ãã£ã³ã°å¤æ´å®äºã" ./utils/describe_weighted_routing.sh $TARGET_PRODUCT_NAME } # å éã«ã¼ãã£ã³ã°å²å(%)ã®ã»ãã function set_weight_percentage () { read -p "ã«ããªã¢ç°å¢ã¸deployããå²å(%)ãå ¥åãã¦ãã ãã: " P if [[ ! $P =~ ^([0-9]|1[0-9]|2[0-9]|30)$ ]]; then echo "åè§æ°å0ãã30ã®éã§è¨å®ãã¦ãã ããã" set_weight_percentage fi TMP_PERCENTAGE=$P read -p "${TMP_PERCENTAGE}%ã§æå ¥ãã¾ããããããã§ããï¼(y/N): " YN if [[ $YN = y ]]; then CANARY_PERCENTAGE=$TMP_PERCENTAGE PRD_PERCENTAGE=$(( 100 - $CANARY_PERCENTAGE)) else set_weight_percentage fi } # ãªã¹ãã¼ã®ããã©ã«ãã¢ã¯ã·ã§ã³å¤æ´ function modify_default_actions () { # å¼æ°ï¼ãªã¹ãã¼ï¼ã®æ°ã ãå¤æ´ãããã for i in $@ do # aws cliå©ç¨æã®--cli-input-jsonæå®ã®ããã®ãã©ã¡ã¼ã¿ãå¥ãã¡ã¤ã«ã§ä½æ cat << EOF > utils/parameter.json { "DefaultActions": [ { "Type": "forward", "ForwardConfig": { "TargetGroups": [ { "TargetGroupArn": "${PRD_TARGET_GROUP_ARN}", "Weight": ${PRD_PERCENTAGE} }, { "TargetGroupArn": "${CANARY_TARGET_GROUP_ARN}", "Weight": ${CANARY_PERCENTAGE} } ] } } ] } EOF aws elbv2 modify-listener --listener-arn $i --cli-input-json file://utils/parameter.json trap "rm utils/parameter.json" 0 1 2 3 15 done } # å ¨ä½å¦çã®å®è¡ main
ã³ãã³ãå®è¡ä¾
% make {ã«ããªã¢ãªãªã¼ã¹å¯¾è±¡ã®ãããã¯ãå}_modify_weighted_routing bash utils/modify_weighted_routing.sh {ã«ããªã¢ãªãªã¼ã¹å¯¾è±¡ã®ãããã¯ãå} {ã«ããªã¢ãªãªã¼ã¹å¯¾è±¡ã®ãããã¯ãå}ã®å éã«ã¼ãã£ã³ã°å¤æ´éå§ã ã«ããªã¢ç°å¢ã¸deployããå²å(%)ãå ¥åãã¦ãã ãã:
ãã¤ã¦ã¤ã³ãã©ã¨ã³ã¸ãã¢ã AWS ã³ã³ã½ã¼ã«ããæåã§èª¿æ´ãã¦ããã«ããªã¢ãªãªã¼ã¹ã®å²åã調æ´ããä½æ¥ãã¿ã¹ã¯ã©ã³ãã¼ã«è½ã¨ãè¾¼ã¿ã¾ãããããã«ãããã«ããªã¢ç°å¢ã¸ã®ãã©ãã£ãã¯ã®èª¿æ´ä½æ¥ãã¢ããªã±ã¼ã·ã§ã³ã¨ã³ã¸ãã¢ã§æ軽ã«ã§ããããã«ãªãã¾ããã
ä½æ¥æã®äººçãªã½ã¼ã¹ãã³ãã¥ãã±ã¼ã·ã§ã³ã³ã¹ãåæ¸
ãªãªã¼ã¹ä½æ¥æã«ã¢ããªã±ã¼ã·ã§ã³ã¨ã³ã¸ãã¢ã¨ã¤ã³ãã©ã¨ã³ã¸ãã¢ãåæçã«éã¾ã£ã¦è¡ãªã£ã¦ããããæ¹ãæ¹åãããã¨ãã§ããã¢ããªã±ã¼ã·ã§ã³ã¨ã³ã¸ãã¢ä¸»å°ã®ãã¨ã«ããªã¢ãªãªã¼ã¹ã®å é調æ´ã®å¤æã¨èª¿æ´ä½æ¥ãä¸è²«ãã¦è¡ããããã«ãªãã¾ãããããã«ãããä½æ¥ã«ããã人çãªã½ã¼ã¹ãã³ãã¥ãã±ã¼ã·ã§ã³ã³ã¹ããåæ¸ãããã¨ãã§ãã¾ãããã¢ããªã±ã¼ã·ã§ã³ã¨ã³ã¸ãã¢ä¸»å°ã§ä½æ¥ãé²ãã¦ãããã¤ã¤ãä½ãåé¡ããã£ãéã«ã¤ã³ãã©ã¨ã³ã¸ãã¢ããã©ãã¼ã«å ¥ãã¨ããå¹ççãªéç¨ãè¡ããä½å¶ãã¤ãããã¨ãã§ãã¾ããã
éçºä½é¨ã®åä¸
å è¿°ãã¦ããæ¹åå¹æã«ããããã¼ã ãè·¨ãã 調æ´ã³ã¹ãã人çãªã½ã¼ã¹ãåæ¸ããã¢ããªã±ã¼ã·ã§ã³ã¨ã³ã¸ãã¢ãã«ããªã¢ãªãªã¼ã¹ãè¡ããã¼ãã«ãä¸ãããã¨ã§éçºä½é¨ã®åä¸ããããããã¨æãã¦ãã¾ãã
ãããã«
ã³ãããã§ã¯ç¾å¨ããã©ãããã©ã¼ã ã°ã«ã¼ãã¨å¼ã°ãããã©ãããã©ã¼ã ã¨ã³ã¸ãã¢ãªã³ã°ä¿é²ãããã¨ããã¤ã³ãã©ã¨ã³ã¸ãã¢ã®ãã¼ã ãåå¨ãã¦ãããã¢ããªã±ã¼ã·ã§ã³ã®å®å®ç¨¼åãé害対å¿ã¯ãã¡ããã®ãã¨ããã©ãããã©ã¼ã ã¨ã³ã¸ãã¢ãªã³ã°ã«ã注åãã¦ãããã¨ããåããçãã§ãã社å ã®ã¨ã³ã¸ãã¢ã®éçºä½é¨ãåä¸ãã¹ãæ¥ã 奮éä¸ã§ãã®ã§ããèå³ã®ããæ¹ã¯ä»å¾ã®ç§ãã¡ã®åããªã©ã«ããã²æ³¨ç®ãã¦ããããã¨å¬ããã§ãã