ããã«ã¡ã¯ããªã¼ãã¨ã³ã¸ãã¢ã® @dachi_023 ã§ããä»åã¯GitHub Actionsã¨ecspressoã§ãããã¤ããã¼ã®æ§ç¯ãããã®ã§ããã«ã¤ãã¦æ¸ãã¦ããã¾ããå ã«è¨ã£ã¦ããã¨ç°¡åã«ã»ããã¢ããã§ãããè¨å®ãã·ã³ãã«ãªã®ã§ããªãããããã§ãã
ããã¾ã§ã®ãããã¤
ã³ãããã§ã¯ECSç°å¢ã¸ã®ãããã¤ã« silinternational/ecs-deploy ãæ¡ç¨ãã¦ãã¾ããCodeBuildãããã¯Travis CIä¸ããecs-deployãå©ç¨ãã¦ECSç°å¢ã«ã¢ããªã±ã¼ã·ã§ã³ããããã¤ããæ§æã§ãã
CI/CDãã¼ã«ã®ä¹ãæãæ¤è¨
ããã¾ã§ãã£ã¨Travis CIãå©ç¨ãã¦ãã¾ãããããã æéä½ç³»ã®å¤æ´ ããã£ãããCodeBuildã§ãããã¤ã®æ¹å ãããããã¢ããªéçºã§ã¯Bitriseãå©ç¨ ãå§ããããããªã©Travis CIãé¸æããçç±ãæ¸ã£ã¦ãã¾ãããããã¨ããããã¤èµ·ç¹ãè¤æ°ãããã¨ã§åCI/CDãµã¼ãã¹ã®æåç解ããã¡ã³ãæã®é¢åããçã¿åºãã¦ãã¾ã£ã¦ãããããªã¨ä»ãã®è¨äºãæ¸ããªããæãã¾ããã
ããã§ä»åã¯GitHub Actionsãè¯ãã®ã§ã¯ãã¨ããå¤æããã¾ãããecspressoãå°å ¥ãããªãã¸ããªã§ã¯ä¹ãæãå ã®æ¤è¨¼ã¨ãã¦GitHub Actionsã使ã£ã¦CIãå®è¡ãã¦ãããã©ãããããªã1ã¤ã®CI/CDãµã¼ãã¹ã§ãããã¨æã£ãããã§ããããã¾ã§Travis CIã§å®è¡ãã¦ããå¦çã¯ãã¹ã¦ç§»è¡å¯è½ã§ãããCodeBuildã§è¡ã£ã¦ããå家åºã®åç·ã«ä¾åããªãæåãããã¤ãå¼ãç¶ãè¡ããã¨ãã§ãã¾ãã
ãã¨ã¯GitHubã®å種ã¤ãã³ãã«é£åãããããHTTPãªã¯ã¨ã¹ãã§èµ·åãããããã®ãç°¡åãªã®ãè¯ãã§ããæ©è½é¢ä»¥å¤ã ã¨è«æ±ãGitHubã«ã¾ã¨ããããã¨ããã®ãè¯ãã®ã§ã¯ãªãã§ãããããï¼ã³ã¼ã管çãGitHubã§ãã¦ããåæï¼
ECSè¨å®ãã³ã¼ãåããã
ã¢ããªã±ã¼ã·ã§ã³ãECSç°å¢ã«ãããã¤ããã¨ããç¨éã ããªãecs-deployã§ååã§ãããããããµã¼ãã¹å®ç¾©ãã¿ã¹ã¯å®ç¾©ã管çããä»çµã¿ããªãããã¢ããªã±ã¼ã·ã§ã³å´ã®é½åã§ã¿ã¹ã¯å®ç¾©ãæ´æ°ãããå ´åãªã©ã«ECSã³ã³ã½ã¼ã«ããæ´æ°ãããããã¤ã³ãã©ãã¼ã ã¸ä¾é ¼ããã¨ããæé ãå¿ è¦ã§ãããã³ã¼ã管çãã¦ããªãããPull Requestã使ã£ãã¬ãã¥ã¼ãè¡ããã¨ãã§ããªãã¨ããæ¬ ç¹ãããã¾ãã
ãããã®èª²é¡ã解決ãããããecs-deployãããã¦ecspressoã使ã£ã¦ã¿ããã¨ã«ãã¾ããã
ecspresso
ecspressoã¯ECSã®ãµã¼ãã¹å®ç¾©ã»ã¿ã¹ã¯å®ç¾©ãæ´æ°å¯è½ã§ããã®è¨å®å 容ã¯JSONã§ç®¡çã§ãã¾ãããªã®ã§ãªãã¸ããªå ã§ç®¡çãã¦å¤æ´ããéã«ã¯Pull Requestãéãã¦ã¬ãã¥ã¼ãããã¨ãå¯è½ã§ããecspressoããã£ã¦ããããã¨ãããã®ææ³ã«ã¤ãã¦ã®è§£èª¬ã¯ä»¥ä¸ã®è¨äºãé常ã«åãããããã£ãã§ãã
ecspresso advent calendar 2020 day 21 - ãããã¨ããããªããã¨
ãããã¤ã¾ã§ã®æé
ããããå ã¯æ¢åã®ECSç°å¢ã«å¯¾ãã¦ecspressoãå©ç¨ãè¨å®ãã¡ã¤ã«ã®ä½æããããã¤ããã¼ã®æ§ç¯ãããããã®æé ã«ãªãã¾ãã
ecspressoã®ã¤ã³ã¹ãã¼ã«
Homebrewçµç±ã§ã¤ã³ã¹ãã¼ã«å¯è½ã§ãã
$ brew install kayac/tap/ecspresso
å®ç¾©ãã¡ã¤ã«ãä½æ
以ä¸ã³ãã³ããå®è¡ãã¦è¨å®ãã¡ã¤ã«ãä½æãã¾ãã
$ ecspresso init \ --region my-ecs-region \ --cluster my-ecs-cluster \ --service my-ecs-service \ --config config.yaml
å®è¡ããã¨3ã¤ãã¡ã¤ã«ãä½æãããã®ã§ããããã³ããããã¦ããã¾ããè¤æ°ç°å¢ã¸ã®ãããã¤ãæ³å®ãããå ´å㯠ecspresso/{env}/
ã®ãããªå½¢ã§ãã£ã¬ã¯ããªãä½æãã¦æ ¼ç´ãã¦ããã¨ç®¡çããããã§ãã
config.yaml
: ecspressoã®è¨å®ãã¡ã¤ã«ecs-service-def.json
: ãµã¼ãã¹å®ç¾©ecs-task-def.json
: ã¿ã¹ã¯å®ç¾©
Workflowã®ä½æ
ãããã¤ããã¼ãªã©ã¯åéçºãã¼ã ã«ãã£ã¦æé ãç°ãªãã®ã§ããã¾ã§åèç¨åº¦ã«ã§ãããç§ã®ããéçºãã¼ã ã§ã¯ä»¥ä¸ã®ãããªè¨å®ã«ãªã£ã¦ãã¾ãã
# .github/workflows/push-main.yml # main ãã©ã³ãã«ãã¼ã¸ãããã development ç°å¢ã¸ãããã¤ãã name: Push main branch on: push: branches: - main jobs: deploy: runs-on: ubuntu-latest env: IMAGE_TAG: latest steps: - name: Checkout uses: actions/checkout@v2 - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v1 with: aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} aws-region: my-aws-region - name: Login to Amazon ECR id: login-ecr uses: aws-actions/amazon-ecr-login@v1 - name: Build, tag, and push image to Amazon ECR env: DOCKER_BUILDKIT: 1 ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} ECR_REPOSITORY: my-repository run: | docker build . -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG - uses: kayac/ecspresso@v0 with: version: v1.1.3 - name: Deploy to Amazon ECS run: | ecspresso deploy --config .ecspresso/development/config.yaml
- ææ°ã³ã¼ãã®ãã§ãã¯ã¢ã¦ã
- ECRã¸ã®ãã°ã¤ã³
- ã¤ã¡ã¼ã¸ã®ãã«ãã»ããã·ã¥
- ecspressoãå©ç¨ãã¦ECSã¿ã¹ã¯å®ç¾©ã®æ´æ°ã»ãããã¤
ã¨ããé ã§å®è¡ããã¦ããã¾ããå®è¡ãããå¦çã®ã»ã¨ãã©ã¯æ¢åã®GitHub Actionãå©ç¨ã»çµã¿åãããã ããªã®ã§é常ã«ç°¡åã§ãããã·ã³ãã«ãªã®ã§ã¡ã³ãã楽ã«ãªãã¾ãã
ãã便å©ã«ããããã«
ããã¾ã§ã§ãããã¤ã«å¿ è¦ãªæä½éãè¨å®ãã¦ãã¾ãããããããã¯å¿ è¦ãªããã£ã¦ã¿ã¦ããã¨ãããã®ã«ãªãã¾ãã
Slackã¸ã®ãããã¤çµæã®éç¥
Slackéç¥ç¨ã®GitHub Actionãå ¥ãã¾ãããã£ã¨èª¿ã¹ãã ãã§ã3ã4åããã®ã§ããä»å㯠8398a7/action-slack ã使ããã¨ã«ãã¾ããã以ä¸ã®è¨å®ãã¸ã§ãã®ä¸çªæå¾ã«å ¥ãã¾ãã
# .github/workflows/push-main.yml - name: Notify slack of deployment result uses: 8398a7/action-slack@v3 with: status: ${{ job.status }} # ãã®ã¸ãã¯ããã¥ã¡ã³ããèªã¿ãªããã好ã¿ã§è¨å®ãã¦ãã ãã fields: repo,commit,ref,workflow,message,took # 誰ããããã¤ä½æ¥ããã¦ããã®ããåããããã« GitHub ã¦ã¼ã¶ã¼åãè¨å®ãã¦ãã¾ã author_name: ${{ github.actor }} text: | Deployment has ${{ (job.status == 'success' && 'succeeded') || (job.status == 'failure' && 'failed') || 'cancelled' }} to my-app. env: SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} if: always()
ã¿ã¹ã¯å®ç¾©ã®å¤æ´ããªããã°å¦çãã¹ããããã
ã¿ã¹ã¯å®ç¾©ã«diffãåºã¦ãªãã£ããã¿ã¹ã¯å®ç¾©ã®æ´æ°å¦çãã¹ãããããããªãã¾ãããecspressoã®ããã¥ã¡ã³ããèªãã§ããã --skip-task-definition
--force-new-deployment
ã¨ãã2ã¤ã®ãªãã·ã§ã³ãè¦ã¤ããã®ã§ãããdiffããªããã°ä»ããããã«ãã¾ã*1ãå·®åãã§ãã¯ã¯ dorny/paths-filter ã¨ããGitHub Actionã使ã£ã¦ãã¾ãã
# .github/workflows/push-main.yml - name: Check if file has changed uses: dorny/paths-filter@v2 id: changes with: filters: .github/file-filters.yml # ã ä¸ç¥ ã - name: Deploy to Amazon ECS run: | ecspresso deploy --config .ecspresso/development/config.yaml ${{ (steps.changes.outputs.task-def == 'false' && '--skip-task-definition --force-new-deployment') || '' }}
# .github/file-filters.yml task-def: - .ecspresso/development/ecs-task-def.json
ãããã«
ECS Scheduled Taskã®ç®¡çãecscheduleã§GitOpsåãã¾ãã ãªã©ãæ¨é²ãã¦ããã¦ãã @laugh_k ã«ååãã¦ããããªããç¡äºãããã¤ã§ããããã«ãªãã¾ãããã¾ããECSã®ãããªã¤ã³ãã©ã¨ã³ã¸ãã¢ä»¥å¤ã触ããæ©ä¼ã®å¤ãé¨åã®ã³ã¼ãåã¯é常ã«éè¦ã ãªã¨ãããã¨ãå¦ã³ã¾ããã
åèãªã³ã¯
- ecspresso Advent Calendar 2020 - Adventar
- ecs-deployããecspressoã«ä¹ãæãã | ããããã¯ãããããå¹³å¡ãªæ¥ã
PR
ã¨ã³ã¸ãã¢åéãã¦ãã¾ãï¼
ãã®è¨äºã¯Shodo (https://shodo.ink) ã§å·çããã¾ããã
*1:ecspresso advent calendar 2020 day 4 - deploy ãèªãã¨ãããã¤æã®æåã«è©³ãããªãã¾ãã