Skip to content

Commit

Permalink
Merge pull request #2 from takuyanagai0213/add-cd-pipeline-ecs
Browse files Browse the repository at this point in the history
デプロイ用の設定を追加
  • Loading branch information
takuyanagai0213 authored Aug 7, 2021
2 parents bd9978c + ed3688c commit 2e46445
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions .github/workflow/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Deploy to Amazon ECS

on:
release:
types: [ created ]

env:
AWS_REGION: MY_AWS_REGION # これをお好みの AWS リージョンに設定する (us-west-1 など)
ECR_REPOSITORY: MY_ECR_REPOSITORY # これを Amazon ECR リポジトリ名に設定する
ECS_SERVICE: MY_ECS_SERVICE # これを Amazon ECS サービス名に設定する
ECS_CLUSTER: MY_ECS_CLUSTER # これを Amazon ECS クラスタ名に設定する
ECS_TASK_DEFINITION: MY_ECS_TASK_DEFINITION # これを Amazon ECS タスク定義へのパスに設定する
# ファイル (.aws/task-definition.json など)
CONTAINER_NAME: MY_CONTAINER_NAME # これをタスク定義の containerDefinitions セクションで
# コンテナの名前に設定する

defaults:
run:
shell: bash

jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
permissions:
packages: write
contents: read

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: ${{ env.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
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ github.sha }}
run: |
# Docker コンテナを作成し
# ECR にプッシュして
# ECS にデプロイできるようにする。
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: ${{ env.ECS_TASK_DEFINITION }}
container-name: ${{ env.CONTAINER_NAME }}
image: ${{ steps.build-image.outputs.image }}

- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ env.ECS_SERVICE }}
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: true

0 comments on commit 2e46445

Please sign in to comment.