mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
feat(elbv2) alb proxy codedeploy ecs (#677)
* feat(elbv2,codedeploy): real ALB Vert.x proxy and ECS blue/green deployment ELB v2 Phase 2: replace the mock ALB with a real Vert.x HTTP reverse proxy. ElbV2DataPlane compiles listener rules into an atomic rule chain and proxies requests to target group members. ElbV2HealthChecker runs periodic health checks against registered targets. shiftListenerForward atomically rewrites the default forward rule (simple or weighted) for CodeDeploy traffic shifts. CodeDeploy Phase 3: implement full ECS blue/green deployment. CreateDeployment drives the complete lifecycle — green task set creation, BeforeInstall / AfterInstall / BeforeAllowTraffic hooks, ALB listener traffic shift (AllAtOnce, Canary, or Linear), AfterAllowTraffic hook, green task set promoted to PRIMARY, blue task set deleted. Compute platform is resolved from the Application when the deployment group doesn't carry it, matching real AWS SDK behavior. * fix: refactor to use arnUtils
This commit is contained in:
1 parent
57a8d58ed4
commit
91ed829ea0
11 files changed
+2087
-21
No files matched your search
+116
-6
@@ -1,6 +1,6 @@
|
||||
# CodeDeploy
|
||||
|
||||
Floci implements the CodeDeploy API — stored-state management for applications, deployment groups, and configs, plus real Lambda deployment execution with traffic shifting and lifecycle hooks.
|
||||
Floci implements the CodeDeploy API — stored-state management for applications, deployment groups, and configs, plus real Lambda and ECS deployment execution with traffic shifting and lifecycle hooks.
|
||||
|
||||
**Protocol:** JSON 1.1 — `POST /` with `X-Amz-Target: CodeDeploy_20141006.<Action>`
|
||||
|
||||
@@ -28,7 +28,7 @@ Floci implements the CodeDeploy API — stored-state management for applications
|
||||
|
||||
| Operation | Notes |
|
||||
|---|---|
|
||||
| `CreateDeploymentGroup` | Stores group config; deployment config defaults to `CodeDeployDefault.OneAtATime` |
|
||||
| `CreateDeploymentGroup` | Stores group config; supports `ecsServices` and `loadBalancerInfo` for ECS blue/green; deployment config defaults to `CodeDeployDefault.OneAtATime` |
|
||||
| `GetDeploymentGroup` | Returns group metadata |
|
||||
| `UpdateDeploymentGroup` | Partial update; supports rename via `newDeploymentGroupName` |
|
||||
| `DeleteDeploymentGroup` | Returns `hooksNotCleanedUp: []` |
|
||||
@@ -48,7 +48,7 @@ Floci implements the CodeDeploy API — stored-state management for applications
|
||||
|
||||
| Operation | Notes |
|
||||
|---|---|
|
||||
| `CreateDeployment` | Starts a real Lambda deployment: shifts alias `RoutingConfig` weights for canary/linear strategies; invokes lifecycle hooks |
|
||||
| `CreateDeployment` | Starts a real Lambda or ECS blue/green deployment; shifts traffic via alias weights (Lambda) or ELB listener rules (ECS); invokes lifecycle hooks |
|
||||
| `GetDeployment` | Returns current deployment state; poll `status` until `Succeeded`, `Failed`, or `Stopped` |
|
||||
| `StopDeployment` | Signals an in-progress deployment to stop; transitions to `Stopped` |
|
||||
| `ContinueDeployment` | Accepted (no-op for fully automated deployments) |
|
||||
@@ -100,6 +100,82 @@ The following 17 configurations are always available (matching real AWS):
|
||||
- `CodeDeployDefault.ECSLinear10PercentEvery1Minutes`
|
||||
- `CodeDeployDefault.ECSLinear10PercentEvery3Minutes`
|
||||
|
||||
## ECS Deployment Model (Blue/Green)
|
||||
|
||||
For `computePlatform: ECS`, `CreateDeployment` performs a full blue/green traffic shift against a real ECS service and ELB v2 listener:
|
||||
|
||||
1. Parses the AppSpec (JSON, `revisionType: AppSpecContent`) to extract the target task definition, container name, and port
|
||||
2. Creates a **green task set** on the ECS service (via `CreateTaskSet`) pointing to the new task definition
|
||||
3. Runs lifecycle hook Lambdas in order: `BeforeInstall` → (install) → `AfterInstall` → `BeforeAllowTraffic` → (traffic shift) → `AfterAllowTraffic`
|
||||
4. **Traffic shift** — atomically updates the ELB v2 listener's default forward rule:
|
||||
- `ECSAllAtOnce`: immediately shifts 100% of traffic to the green target group
|
||||
- `ECSCanary*`: shifts the canary percentage first, waits a short interval (capped at 5 s in emulator), then shifts to 100%
|
||||
- `ECSLinear*`: shifts traffic in equal increments (capped at 2 s per step in emulator)
|
||||
5. Promotes the green task set to **PRIMARY** on the ECS service and deletes the original blue task set
|
||||
6. Marks the deployment `Succeeded`; if any lifecycle hook reports `Failed`, the deployment is marked `Failed`
|
||||
|
||||
**Compute platform resolution**: `computePlatform` is set on the Application at creation time. The deployment group inherits it — you do not pass `computePlatform` to `CreateDeploymentGroup`.
|
||||
|
||||
### ECS AppSpec Format
|
||||
|
||||
```json
|
||||
{
|
||||
"version": 0.0,
|
||||
"Resources": [{
|
||||
"TargetService": {
|
||||
"Type": "AWS::ECS::Service",
|
||||
"Properties": {
|
||||
"TaskDefinition": "my-task:2",
|
||||
"LoadBalancerInfo": {
|
||||
"ContainerName": "app",
|
||||
"ContainerPort": 80
|
||||
}
|
||||
}
|
||||
}
|
||||
}],
|
||||
"Hooks": [
|
||||
{ "BeforeInstall": "my-before-install-hook" },
|
||||
{ "AfterInstall": "my-after-install-hook" },
|
||||
{ "BeforeAllowTraffic": "my-before-traffic-hook" },
|
||||
{ "AfterAllowTraffic": "my-after-traffic-hook" }
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
All hook fields are optional.
|
||||
|
||||
### ECS Deployment Group Configuration
|
||||
|
||||
```json
|
||||
{
|
||||
"applicationName": "my-ecs-app",
|
||||
"deploymentGroupName": "my-ecs-group",
|
||||
"deploymentConfigName": "CodeDeployDefault.ECSAllAtOnce",
|
||||
"serviceRoleArn": "arn:aws:iam::000000000000:role/codedeploy-role",
|
||||
"deploymentStyle": {
|
||||
"deploymentType": "BLUE_GREEN",
|
||||
"deploymentOption": "WITH_TRAFFIC_CONTROL"
|
||||
},
|
||||
"ecsServices": [{
|
||||
"clusterName": "my-cluster",
|
||||
"serviceName": "my-service"
|
||||
}],
|
||||
"loadBalancerInfo": {
|
||||
"targetGroupPairInfoList": [{
|
||||
"targetGroups": [
|
||||
{ "name": "my-blue-tg" },
|
||||
{ "name": "my-green-tg" }
|
||||
],
|
||||
"prodTrafficRoute": {
|
||||
"listenerArns": ["arn:aws:elasticloadbalancing:..."]
|
||||
}
|
||||
}]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The ECS service must be created with `deploymentController.type: EXTERNAL`.
|
||||
|
||||
## Lambda Deployment Model
|
||||
|
||||
For `computePlatform: Lambda`, `CreateDeployment` performs real traffic shifting:
|
||||
@@ -122,8 +198,10 @@ floci:
|
||||
|
||||
## CLI Examples
|
||||
|
||||
### Lambda
|
||||
|
||||
```bash
|
||||
# Create an application
|
||||
# Create a Lambda application
|
||||
aws --endpoint-url http://localhost:4566 deploy create-application \
|
||||
--application-name my-app \
|
||||
--compute-platform Lambda
|
||||
@@ -136,15 +214,47 @@ aws --endpoint-url http://localhost:4566 deploy create-deployment-group \
|
||||
--service-role-arn arn:aws:iam::000000000000:role/codedeploy-role \
|
||||
--deployment-style deploymentType=BLUE_GREEN,deploymentOption=WITH_TRAFFIC_CONTROL
|
||||
|
||||
# Start a deployment
|
||||
# Start a Lambda deployment
|
||||
aws --endpoint-url http://localhost:4566 deploy create-deployment \
|
||||
--application-name my-app \
|
||||
--deployment-group-name my-group \
|
||||
--revision revisionType=AppSpecContent,appSpecContent={content='{"version":0.0,"Resources":[{"myFunction":{"Type":"AWS::Lambda::Function","Properties":{"Name":"my-function","Alias":"live","CurrentVersion":"1","TargetVersion":"2"}}}]}'}
|
||||
--revision 'revisionType=AppSpecContent,appSpecContent={content="{\"version\":0.0,\"Resources\":[{\"myFunction\":{\"Type\":\"AWS::Lambda::Function\",\"Properties\":{\"Name\":\"my-function\",\"Alias\":\"live\",\"CurrentVersion\":\"1\",\"TargetVersion\":\"2\"}}}]}"}'
|
||||
```
|
||||
|
||||
### ECS Blue/Green
|
||||
|
||||
```bash
|
||||
# Create an ECS application
|
||||
aws --endpoint-url http://localhost:4566 deploy create-application \
|
||||
--application-name my-ecs-app \
|
||||
--compute-platform ECS
|
||||
|
||||
# Create a deployment group (listener ARN from ELB v2)
|
||||
aws --endpoint-url http://localhost:4566 deploy create-deployment-group \
|
||||
--application-name my-ecs-app \
|
||||
--deployment-group-name my-ecs-group \
|
||||
--deployment-config-name CodeDeployDefault.ECSAllAtOnce \
|
||||
--service-role-arn arn:aws:iam::000000000000:role/codedeploy-role \
|
||||
--ecs-services clusterName=my-cluster,serviceName=my-service \
|
||||
--load-balancer-info 'targetGroupPairInfoList=[{targetGroups=[{name=blue-tg},{name=green-tg}],prodTrafficRoute={listenerArns=[<listener-arn>]}}]'
|
||||
|
||||
# Start an ECS blue/green deployment
|
||||
aws --endpoint-url http://localhost:4566 deploy create-deployment \
|
||||
--application-name my-ecs-app \
|
||||
--deployment-group-name my-ecs-group \
|
||||
--revision 'revisionType=AppSpecContent,appSpecContent={content="{\"version\":0.0,\"Resources\":[{\"TargetService\":{\"Type\":\"AWS::ECS::Service\",\"Properties\":{\"TaskDefinition\":\"my-task:2\",\"LoadBalancerInfo\":{\"ContainerName\":\"app\",\"ContainerPort\":80}}}}]}"}'
|
||||
|
||||
# Poll deployment status
|
||||
aws --endpoint-url http://localhost:4566 deploy get-deployment --deployment-id <id>
|
||||
|
||||
# List deployment targets
|
||||
aws --endpoint-url http://localhost:4566 deploy list-deployment-targets --deployment-id <id>
|
||||
|
||||
# Get target details
|
||||
aws --endpoint-url http://localhost:4566 deploy batch-get-deployment-targets \
|
||||
--deployment-id <id> \
|
||||
--target-ids <target-id>
|
||||
|
||||
# List built-in deployment configs
|
||||
aws --endpoint-url http://localhost:4566 deploy list-deployment-configs
|
||||
```
|
||||
Reference in new issue
Block a user