|
| 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 deployment |
| 16 | + |
| 17 | +import ( |
| 18 | + "context" |
| 19 | + "errors" |
| 20 | + |
| 21 | + ecsconfig "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/ecs/config" |
| 22 | + sdk "github.com/pipe-cd/piped-plugin-sdk-go" |
| 23 | +) |
| 24 | + |
| 25 | +var _ sdk.DeploymentPlugin[ecsconfig.ECSPluginConfig, ecsconfig.ECSDeployTargetConfig, ecsconfig.ECSApplicationSpec] = (*ECSPlugin)(nil) |
| 26 | + |
| 27 | +var ErrUnsupportedStage = errors.New("unsupported stage") |
| 28 | + |
| 29 | +type ECSPlugin struct { |
| 30 | +} |
| 31 | + |
| 32 | +// FetchDefinedStages returns the list of stages that the plugin can execute. |
| 33 | +func (p *ECSPlugin) FetchDefinedStages() []string { |
| 34 | + return allStages |
| 35 | +} |
| 36 | + |
| 37 | +// BuildQuickSyncStages builds the stages that will be executed during the quick sync process. |
| 38 | +func (p *ECSPlugin) BuildQuickSyncStages( |
| 39 | + ctx context.Context, |
| 40 | + cfg *ecsconfig.ECSPluginConfig, |
| 41 | + input *sdk.BuildQuickSyncStagesInput, |
| 42 | +) (*sdk.BuildQuickSyncStagesResponse, error) { |
| 43 | + return &sdk.BuildQuickSyncStagesResponse{ |
| 44 | + Stages: buildQuickSyncPipeline(input.Request.Rollback), |
| 45 | + }, nil |
| 46 | +} |
| 47 | + |
| 48 | +// BuildPipelineSyncStages builds the stages that will be executed by the plugin. |
| 49 | +func (p *ECSPlugin) BuildPipelineSyncStages( |
| 50 | + _ context.Context, |
| 51 | + _ *ecsconfig.ECSPluginConfig, |
| 52 | + input *sdk.BuildPipelineSyncStagesInput, |
| 53 | +) (*sdk.BuildPipelineSyncStagesResponse, error) { |
| 54 | + return &sdk.BuildPipelineSyncStagesResponse{ |
| 55 | + Stages: buildPipelineStages(input), |
| 56 | + }, nil |
| 57 | +} |
| 58 | + |
| 59 | +// ExecuteStage executes the given stage. |
| 60 | +func (p *ECSPlugin) ExecuteStage( |
| 61 | + ctx context.Context, |
| 62 | + cfg *ecsconfig.ECSPluginConfig, |
| 63 | + deployTargets []*sdk.DeployTarget[ecsconfig.ECSDeployTargetConfig], |
| 64 | + input *sdk.ExecuteStageInput[ecsconfig.ECSApplicationSpec], |
| 65 | +) (*sdk.ExecuteStageResponse, error) { |
| 66 | + switch input.Request.StageName { |
| 67 | + default: |
| 68 | + return nil, ErrUnsupportedStage |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | +// DetermineVersions determines the versions of the resources that will be deployed. |
| 73 | +func (p *ECSPlugin) DetermineVersions( |
| 74 | + ctx context.Context, |
| 75 | + cfg *ecsconfig.ECSPluginConfig, |
| 76 | + input *sdk.DetermineVersionsInput[ecsconfig.ECSApplicationSpec], |
| 77 | +) (*sdk.DetermineVersionsResponse, error) { |
| 78 | + return &sdk.DetermineVersionsResponse{ |
| 79 | + // TODO: Implement the logic to determine the versions of the resources that will be deployed. |
| 80 | + // This is just a placeholder |
| 81 | + Versions: []sdk.ArtifactVersion{ |
| 82 | + { |
| 83 | + Version: "latest", |
| 84 | + Name: "ecs-task", |
| 85 | + URL: "", |
| 86 | + }, |
| 87 | + }, |
| 88 | + }, nil |
| 89 | +} |
| 90 | + |
| 91 | +// DetermineStrategy determines the strategy to deploy the resources. |
| 92 | +func (p *ECSPlugin) DetermineStrategy( |
| 93 | + ctx context.Context, |
| 94 | + cfg *ecsconfig.ECSPluginConfig, |
| 95 | + input *sdk.DetermineStrategyInput[ecsconfig.ECSApplicationSpec], |
| 96 | +) (*sdk.DetermineStrategyResponse, error) { |
| 97 | + // Use quick sync as the default strategy for ECS deployment. |
| 98 | + return &sdk.DetermineStrategyResponse{ |
| 99 | + Strategy: sdk.SyncStrategyQuickSync, |
| 100 | + Summary: "Use quick sync strategy for ECS deployment (work as ECS_SYNC stage)", |
| 101 | + }, nil |
| 102 | +} |
0 commit comments