Amazon ECS/Fargate
Use Codefresh to deploy Docker containers to ECS/Fargate
Codefresh can deploy to any ECS or Fargate cluster created in Amazon.
Prerequisites
- Configure an ECS (or Fargate) Cluster with at least one running instance.
- Configure an ECS Service and Task Definition with a reference to the image that you are going to build and push. See the official amazon docs for more details.
- Connect your ECR to Codefresh so that it can be used by name in Codefresh pipelines.
- Verify you have AWS Credentials (
AWS_ACCESS_KEY_ID
,AWS_SECRET_ACCESS_KEY
), with the following privileges:
JSON
Create a CI/CD pipeline for ECS/Fargate
Here is the complete pipeline:
codefresh.yml
This pipeline does the following:
- Clones the source code with a Git clone step
- Uses a build step to create a Docker image
- Uses a push step to push the docker image to ECR. The registry was previously connected to Codefresh with the
ecr
identifier. - Runs
codefreshplugins/cf-deploy-ecs
to perform the actual deployment
The pipeline needs environment variables that hold all the required parameters.
Note that the --image-name
and --image-tag
pair should comprise the full name of the image that was pushed to the registry (including the registry name) in order to be correctly referred by the corresponding Task Definition.
Deployment Flow
The codefreshplugins/cf-deploy-ecs
step performs the following:
- Gets the ECS service by specified
aws-region
,ecs-cluster
, andservice-names
. - Creates a new revision from the current task definition of the service. If
--image-name
and--image-tag
are provided, it replaces the image tag. - Runs the
update-service
command with the new task definition revision. - Waits for the deployment to complete.
- Deployment is successfully completed if
runningCount == desiredCount
for PRIMARY deployment - seeaws ecs describe-services
- The
cfecs-update
command exits with a timeout error if after –timeout (default = 900s)runningCount
does not equaldesiredCount
- The
cfecs-update
exits with an error if –max-failed (default = 2) or more ECS tasks were stopped with error for the task definition that you are deploying. ECS continuously retries failed tasks.
- Deployment is successfully completed if
You can also find the same step in the form of a Codefresh plugin.
Related articles
CD pipeline examples
Codefresh YAML for pipeline definitions
Steps in pipelines
Creating pipelines
External registries