翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。
以下は、Amazon ECS タスク定義のレンダリングアクションとビルドおよびデプロイアクションを含む、完全なワークフローの例です。このワークフローの目的は、Docker イメージをビルドして Amazon ECS クラスターにデプロイすることです。このワークフローは、連続して実行される次の構成要素で構成されます。
-
トリガー – ソースリポジトリに変更をプッシュすると、このトリガーによってワークフローが自動的に開始されます。トリガーについての詳細は、「トリガーを使用したワークフロー実行の自動的な開始」を参照してください。
-
ビルドアクション (
BuildDocker
) – トリガーされると、アクションは Dockerfile を使用して Docker イメージをビルドし、コミット ID でタグ付けして、イメージを Amazon ECR にプッシュします。ビルドアクションの詳細については、「ワークフローを使用したビルド」を参照してください。 -
Amazon ECS タスク定義のレンダリングアクション (
RenderTaskDef
) – ビルドアクションが完了すると、このアクションはソースリポジトリのルートにある既存のtaskdef.json
を、正しいコミット ID を含むimage
フィールド値で更新します。更新されたファイルが新しいファイル名 (task-definition-random-string.json
) で保存され、このファイルを含む出力アーティファクトが作成されます。レンダリングアクションはtask-definition
という変数も生成し、それを新しいタスク定義ファイルの名前に設定します。デプロイアクションでは、次のようなアーティファクトと変数が使用されます。 -
Amazon ECS へのデプロイアクション (
DeployToECS
) – Amazon ECS タスク定義のレンダリングアクションが完了すると、Amazon ECS にデプロイアクションは、レンダリングアクション (TaskDefArtifact
) によって生成された出力アーティファクトを探し、その中にあるtask-definition-random-string.json
ファイルを見つけて、Amazon ECS サービスに登録します。次に、Amazon ECS サービスは、task-definition-random-string.json
ファイルの手順に従って、Amazon ECS クラスター内で Amazon ECS タスクと関連する Docker イメージコンテナを実行します。
Name: codecatalyst-ecs-workflow
SchemaVersion: 1.0
Triggers:
- Type: PUSH
Branches:
- main
Actions:
BuildDocker:
Identifier: aws/build@v1
Environment:
Name: codecatalyst-ecs-environment
Connections:
- Name: codecatalyst-account-connection
Role: codecatalyst-ecs-build-role
Inputs:
Variables:
- Name: REPOSITORY_URI
Value: 111122223333.dkr.ecr.us-east-2.amazonaws.com/codecatalyst-ecs-image-repo
- Name: IMAGE_TAG
Value: ${WorkflowSource.CommitId}
Configuration:
Steps:
#pre_build:
- Run: echo Logging in to Amazon ECR...
- Run: aws --version
- Run: aws ecr get-login-password --region us-east-2 | docker login --username AWS --password-stdin 111122223333.dkr.ecr.us-east-2.amazonaws.com
#build:
- Run: echo Build started on `date`
- Run: echo Building the Docker image...
- Run: docker build -t $REPOSITORY_URI:latest .
- Run: docker tag $REPOSITORY_URI:latest $REPOSITORY_URI:$IMAGE_TAG
#post_build:
- Run: echo Build completed on `date`
- Run: echo Pushing the Docker images...
- Run: docker push $REPOSITORY_URI:latest
- Run: docker push $REPOSITORY_URI:$IMAGE_TAG
RenderTaskDef:
DependsOn:
- BuildDocker
Identifier: aws/ecs-render-task-definition@v1
Inputs:
Variables:
- Name: REPOSITORY_URI
Value: 111122223333.dkr.ecr.us-east-2.amazonaws.com/codecatalyst-ecs-image-repo
- Name: IMAGE_TAG
Value: ${WorkflowSource.CommitId}
Configuration:
task-definition: taskdef.json
container-definition-name: codecatalyst-ecs-container
image: $REPOSITORY_URI:$IMAGE_TAG
# The output artifact contains the updated task definition file.
# The new file is prefixed with 'task-definition'.
# The output variable is set to the name of the updated task definition file.
Outputs:
Artifacts:
- Name: TaskDefArtifact
Files:
- "task-definition*"
Variables:
- task-definition
DeployToECS:
Identifier: aws/ecs-deploy@v1
Environment:
Name: codecatalyst-ecs-environment
Connections:
- Name: codecatalyst-account-connection
Role: codecatalyst-ecs-deploy-role
#Input artifact contains the updated task definition file.
Inputs:
Sources: []
Artifacts:
- TaskDefArtifact
Configuration:
region: us-east-2
cluster: codecatalyst-ecs-cluster
service: codecatalyst-ecs-service
task-definition: ${RenderTaskDef.task-definition}