Skip to content

Commit 99fede9

Browse files
authored
[ECS-Plugin] Implement ECS_ SYNC stage (#6559)
* feat: implement load, parse task definition and service from file Signed-off-by: Hoang Ngo <adlehoang118@gmail.com> * feat: implement pool of wrapper ecs client Signed-off-by: Hoang Ngo <adlehoang118@gmail.com> * feat: implement ECS_SYNC stage (basic flow) Signed-off-by: Hoang Ngo <adlehoang118@gmail.com> * handle flag `recreate` in sync stage when recreate is enable, stop the current running tasks (i.e. set desired #tasks of service to 0), then rollout new taskset and set the number of desired #tasks back to original value Signed-off-by: Hoang Ngo <adlehoang118@gmail.com> * handle maintain desired tags for ecs service Signed-off-by: Hoang Ngo <adlehoang118@gmail.com> * add pipecd managed tags for ecs service Signed-off-by: Hoang Ngo <adlehoang118@gmail.com> * chore: add expected behavior of configuration Signed-off-by: Hoang Ngo <adlehoang118@gmail.com> * chore: move tags to nearest used place Signed-off-by: Hoang Ngo <adlehoang118@gmail.com> * add unit test for sync function Signed-off-by: Hoang Ngo <adlehoang118@gmail.com> * chore: move add pipecd-related tags to load service function Signed-off-by: Hoang Ngo <adlehoang118@gmail.com> --------- Signed-off-by: Hoang Ngo <adlehoang118@gmail.com>
1 parent ef72cb0 commit 99fede9

File tree

18 files changed

+2158
-5
lines changed

18 files changed

+2158
-5
lines changed

pkg/app/pipedv1/plugin/ecs/config/application.go

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,83 @@ package config
1616

1717
// ECSApplicationSpec defines the application specification for ECS plugin.
1818
type ECSApplicationSpec struct {
19-
Input ECSDeploymentInput `json:"input"`
19+
Input ECSDeploymentInput `json:"input"`
20+
QuickSyncOptions ECSSyncStageOptions `json:"quickSync"`
2021
}
2122

2223
// ECSDeploymentInput defines the input for ECS deployment.
2324
type ECSDeploymentInput struct {
25+
// TaskDefinitionFile is the name of task definition file placing in application directory
26+
// e.g., "taskdef.json" or "ecs/taskdef.yaml"
27+
// Default: taskdef.json
28+
TaskDefinitionFile string `json:"taskDefinitionFile,omitempty" default:"taskdef.json"`
29+
30+
// ServiceDefinitionFile is the name of service definition file placing in application directory
31+
// e.g., "servicedef.json" or "ecs/servicedef.yaml"
32+
// Default: servicedef.json
33+
ServiceDefinitionFile string `json:"serviceDefinitionFile,omitempty" default:"servicedef.json"`
34+
35+
// RunStandaloneTask indicates whether to run the task as a standalone task without creating/updating an ECS service.
36+
// If true, the plugin will run the task directly without managing it through an ECS service.
37+
// This is useful for running one-off tasks or jobs that do not require long-term management.
38+
// Default: false
39+
RunStandaloneTask bool `json:"runStandaloneTask,omitempty" default:"false"`
40+
41+
// ClusterARN identifies the ECS cluster where the task and service will be deployed.
42+
ClusterARN string `json:"clusterArn,omitempty"`
43+
44+
// LaunchType specifies the launch type on which to run your task.
45+
// Valid values: "EC2", "FARGATE"
46+
// Default: "FARGATE"
47+
LaunchType string `json:"launchType,omitempty" default:"FARGATE"`
48+
49+
// AccessType specifies how the ECS service is accessed.
50+
// Valid values: "ELB", "SERVICE_DISCOVERY"
51+
// Default: "ELB"
52+
AccessType string `json:"accessType,omitempty" default:"ELB"`
53+
54+
// AwsVpcConfiguration contains the VPC configuration for running ECS tasks.
55+
AwsVpcConfiguration ECSVpcConfiguration `json:"awsvpcConfiguration"`
56+
57+
// TargetGroups contains the load balancer target groups for the ECS service.
58+
TargetGroups ECSTargetGroups `json:"targetGroups"`
59+
}
60+
61+
// ECSVpcConfiguration contains the VPC configuration for running ECS tasks.
62+
type ECSVpcConfiguration struct {
63+
// Subnets is a list of VPC subnet IDs where tasks will be launched.
64+
// Limit: 16 subnets per VPC configuration (https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/service/ecs@v1.46.2/types#AwsVpcConfiguration).
65+
// This field is required.
66+
Subnets []string `json:"subnets"`
67+
68+
// AssignPublicIP indicates whether to assign a public IP address to the task's ENI
69+
// Valid values: "ENABLED","DISABLED"
70+
AssignPublicIP string `json:"assignPublicIp,omitempty"`
71+
72+
// SecurityGroups is a list of security group IDs associated with the task's ENI
73+
// If not specified, the default security group for the VPC will be used.
74+
// Limit: 5 security groups per VPC configuration (https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/service/ecs@v1.46.2/types#AwsVpcConfiguration).
75+
// All security groups must be from the same VPC.
76+
SecurityGroups []string `json:"securityGroups,omitempty"`
77+
}
78+
79+
// ECSTargetGroups represents the load balancer target groups.
80+
type ECSTargetGroups struct {
81+
// Primary is the target group for the primary service.
82+
Primary *ECSTargetGroup `json:"primary,omitempty"`
83+
84+
// Canary is the target group for the canary service (optional).
85+
Canary *ECSTargetGroup `json:"canary,omitempty"`
86+
}
87+
88+
// ECSTargetGroup represents a single load balancer target group
89+
type ECSTargetGroup struct {
90+
// TargetGroupARN is the ARN of the target group
91+
TargetGroupARN string `json:"targetGroupArn,omitempty"`
92+
93+
// ContainerName is the name of the container to associate with the target group
94+
ContainerName string `json:"containerName,omitempty"`
95+
96+
// ContainerPort is the port on the container to associate with the target group
97+
ContainerPort int32 `json:"containerPort,omitempty"`
2498
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2026 The PipeCD Authors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package config
16+
17+
// ECSSyncStageOptions contains options for the ECS sync stage.
18+
type ECSSyncStageOptions struct {
19+
// Recreate indicates whether to recreate the service.
20+
// Enable this will ensure stop all running tasks before creating new task set.
21+
Recreate bool `json:"recreate,omitempty"`
22+
}

pkg/app/pipedv1/plugin/ecs/deployment/plugin.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ func (p *ECSPlugin) ExecuteStage(
6464
input *sdk.ExecuteStageInput[ecsconfig.ECSApplicationSpec],
6565
) (*sdk.ExecuteStageResponse, error) {
6666
switch input.Request.StageName {
67+
case StageECSSync:
68+
return &sdk.ExecuteStageResponse{
69+
Status: p.executeECSSyncStage(ctx, input, deployTargets[0]),
70+
}, nil
6771
default:
6872
return nil, ErrUnsupportedStage
6973
}

0 commit comments

Comments
 (0)