简体   繁体   中英

Create task definition revision, update docker tag and update service with .NET

As part of an automated deployment with the .NET AWS SDK, I am trying to create a new task definition revision, update the docker image tag label with my newly deployed version and then update a service to use that new revision.

I have something like this:

      var taskDefinitionResponse = await _ecsClient.RegisterTaskDefinitionAsync(new RegisterTaskDefinitionRequest
      {
        ContainerDefinitions = new List<ContainerDefinition>(new[] {new ContainerDefinition(){Image = "new image:v123"}})
      });

      await _ecsClient.UpdateServiceAsync(new UpdateServiceRequest()
      {
        TaskDefinition = taskDefinitionResponse.TaskDefinition.TaskDefinitionArn,

      });

My concern is with the above code it doesn't duplicate the existing task definition for example in AWS Console when you click "Create new revision" you have to select a task definition so that the button creates a duplicate so you can then modify it and save the new revision so would I need some code that gets an existing task definition then just change the docker image and then call the RegisterTaskDefinitionAsync with the existing definition and modified docker image?

The UI is automatically making multiple API calls and giving you the option to create new revision from previous ones. In order for you to achieve the same, you can try something like this.

First List the TaskDefinitions using the family prefix(assuming you are creating the task definitions using image name or some prefix).

Task<ListTaskDefinitionsResponse> ListTaskDefinitionsAsync(
         ListTaskDefinitionsRequest request,
         CancellationToken cancellationToken
)

Using the The ListTaskDefinitionsResponse , select the Latest Task Definition ARN and make another API call to get full Task Definition Response.

Task<DescribeTaskDefinitionResponse> DescribeTaskDefinitionAsync(
         DescribeTaskDefinitionRequest request,
         CancellationToken cancellationToken
)

Now, you have the latest TaskDefinition object where you can modify the Image Version and publish it again.

Task<RegisterTaskDefinitionResponse> RegisterTaskDefinitionAsync(
         RegisterTaskDefinitionRequest request,
         CancellationToken cancellationToken
)

AWS .NET SDK Reference - https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/ECS/TECSClient.html

Let me know your thoughts.!.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM