Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions clients/ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/ecs"
ecsTypes "github.com/aws/aws-sdk-go-v2/service/ecs/types"
"github.com/joomcode/errorx"
)

const sleepTime = 5 * time.Second
Expand Down Expand Up @@ -44,7 +43,7 @@ func (c *ecsClient) GetService(ctx context.Context, clusterName string, serviceN
},
)
if err != nil {
return nil, errorx.Decorate(err, "unable to describe services")
return nil, fmt.Errorf("unable to describe services: %w", err)
}
if len(describeResult.Services) == 0 {
return nil, fmt.Errorf("service %s not found in cluster %s", serviceName, clusterName)
Expand All @@ -65,7 +64,7 @@ func (c *ecsClient) DoesServiceLookGood(ctx context.Context, service *ecsTypes.S
ServiceName: service.ServiceName,
})
if err != nil {
return false, errorx.Decorate(err, "unable to list tasks")
return false, fmt.Errorf("unable to list tasks: %w", err)
}
if len(runningTasks.TaskArns) == 0 {
return service.DesiredCount == 0, nil
Expand All @@ -75,7 +74,7 @@ func (c *ecsClient) DoesServiceLookGood(ctx context.Context, service *ecsTypes.S
Tasks: runningTasks.TaskArns,
})
if err != nil {
return false, errorx.Decorate(err, "unable to describe tasks")
return false, fmt.Errorf("unable to describe tasks: %w", err)
}
matchCount := 0
for _, task := range runningTaskDetails.Tasks {
Expand All @@ -89,7 +88,7 @@ func (c *ecsClient) DoesServiceLookGood(ctx context.Context, service *ecsTypes.S
func (c *ecsClient) WaitForServiceToLookGood(ctx context.Context, service *ecsTypes.Service, timeout time.Duration) error {
refreshService, err := c.GetService(ctx, *service.ClusterArn, *service.ServiceName)
if err != nil {
return errorx.Decorate(err, "unable to get service")
return fmt.Errorf("unable to get service: %w", err)
}

alreadyLookingGood := false
Expand All @@ -111,11 +110,11 @@ func (c *ecsClient) WaitForServiceToLookGood(ctx context.Context, service *ecsTy
return nil
}
if err != nil {
return errorx.Decorate(err, "unable to check if service looks good")
return fmt.Errorf("unable to check if service looks good: %w", err)
}
refreshService, err = c.GetService(ctx, *service.ClusterArn, *service.ServiceName)
if err != nil {
return errorx.Decorate(err, "unable to get service")
return fmt.Errorf("unable to get service: %w", err)
}
var newErrors []string
if newErrors, checkedUntil, err = c.getRecentErrorMessages(refreshService, checkedUntil); err != nil {
Expand Down Expand Up @@ -178,7 +177,7 @@ func (c *ecsClient) GetTaskDefinition(ctx context.Context, service *ecsTypes.Ser
Include: []ecsTypes.TaskDefinitionField{ecsTypes.TaskDefinitionFieldTags},
})
if err != nil {
return nil, errorx.Decorate(err, "unable to describe task definition")
return nil, fmt.Errorf("unable to describe task definition: %w", err)
}
return output, nil
}
Expand Down Expand Up @@ -212,7 +211,7 @@ func (c *ecsClient) CopiedTaskDefinition(output *ecs.DescribeTaskDefinitionOutpu
func (c *ecsClient) RegisterTaskDefinition(ctx context.Context, input *ecs.RegisterTaskDefinitionInput) (*ecsTypes.TaskDefinition, error) {
output, err := c.client.RegisterTaskDefinition(ctx, input)
if err != nil {
return nil, errorx.Decorate(err, "unable to register task definition")
return nil, fmt.Errorf("unable to register task definition: %w", err)
}
return output.TaskDefinition, nil
}
Expand All @@ -224,7 +223,7 @@ func (c *ecsClient) UpdateTaskDefinition(ctx context.Context, service *ecsTypes.
TaskDefinition: task.TaskDefinitionArn,
})
if err != nil {
return nil, errorx.Decorate(err, "unable to update service")
return nil, fmt.Errorf("unable to update service: %w", err)
}
return output.Service, nil
}
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ require (
github.com/aws/aws-sdk-go-v2/config v1.27.21
github.com/aws/aws-sdk-go-v2/service/ecs v1.43.1
github.com/fatih/color v1.9.0
github.com/joomcode/errorx v1.1.1
github.com/stretchr/testify v1.9.0
go.uber.org/mock v0.5.0
gopkg.in/yaml.v3 v3.0.1
Expand Down
3 changes: 0 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9Y
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/joomcode/errorx v1.1.1 h1:/LFG/qSk1gUTuZjs+qlyOJEpcVjD9DXgBNFhdZkQrjY=
github.com/joomcode/errorx v1.1.1/go.mod h1:eQzdtdlNyN7etw6YCS4W4+lu442waxZYw5yvz0ULrRo=
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
Expand All @@ -45,7 +43,6 @@ github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOA
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/urfave/cli/v3 v3.0.0-beta1 h1:6DTaaUarcM0wX7qj5Hcvs+5Dm3dyUTBbEwIWAjcw9Zg=
Expand Down
14 changes: 7 additions & 7 deletions services/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package services
import (
"context"
"errors"
"fmt"
"log"
"time"

"github.com/adroll/ecs-ship/clients"
"github.com/adroll/ecs-ship/models"
"github.com/fatih/color"
"github.com/joomcode/errorx"
)

// DeployInput represents the input for the DeployerService
Expand Down Expand Up @@ -47,20 +47,20 @@ func (s *deployerService) Deploy(ctx context.Context, input *DeployInput) error
log.Printf("updating service:\n cluster: %s\n service: %s\n", input.Cluster, input.Service)
service, err := s.client.GetService(ctx, input.Cluster, input.Service)
if err != nil {
return errorx.Decorate(err, "unable to get service")
return fmt.Errorf("unable to get service: %w", err)
}

looksGood, err := s.client.DoesServiceLookGood(ctx, service)
if err != nil {
return errorx.Decorate(err, "unable to check if service looks good")
return fmt.Errorf("unable to check if service looks good: %w", err)
}
if looksGood {
log.Println(color.GreenString("the service looks good to begin with"))
}

output, err := s.client.GetTaskDefinition(ctx, service)
if err != nil {
return errorx.Decorate(err, "unable to get task definition")
return fmt.Errorf("unable to get task definition: %w", err)
}

oldTaskDefinitionInput := s.client.CopiedTaskDefinition(output)
Expand All @@ -86,12 +86,12 @@ func (s *deployerService) Deploy(ctx context.Context, input *DeployInput) error

newTaskDefinition, err := s.client.RegisterTaskDefinition(ctx, newTaskDefinitionInput)
if err != nil {
return errorx.Decorate(err, "unable to register new task definition")
return fmt.Errorf("unable to register new task definition: %w", err)
}

newService, err := s.client.UpdateTaskDefinition(ctx, service, newTaskDefinition)
if err != nil {
return errorx.Decorate(err, "unable to update service")
return fmt.Errorf("unable to update service: %w", err)
}

if input.NoWait {
Expand All @@ -104,7 +104,7 @@ func (s *deployerService) Deploy(ctx context.Context, input *DeployInput) error
err = s.client.WaitForServiceToLookGood(ctx, newService, input.Timeout)

if err != nil {
return errorx.Decorate(err, "service did not reflect changes")
return fmt.Errorf("service did not reflect changes: %w", err)
}

log.Println(color.GreenString("service has been updated successfully!"))
Expand Down
12 changes: 6 additions & 6 deletions services/deployer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func Test_Deployer_Deploy_UnableToGetService(t *testing.T) {

err := deployer.Deploy(context.Background(), input)
assert.Error(t, err)
assert.Equal(t, "unable to get service, cause: assert.AnError general error for testing", err.Error())
assert.Equal(t, "unable to get service: assert.AnError general error for testing", err.Error())
}

func Test_Deployer_Deploy_UnableToCheckIfServiceLooksGood(t *testing.T) {
Expand All @@ -58,7 +58,7 @@ func Test_Deployer_Deploy_UnableToCheckIfServiceLooksGood(t *testing.T) {

err := deployer.Deploy(context.Background(), input)
assert.Error(t, err)
assert.Equal(t, "unable to check if service looks good, cause: assert.AnError general error for testing", err.Error())
assert.Equal(t, "unable to check if service looks good: assert.AnError general error for testing", err.Error())
}

func Test_Deployer_Deploy_UnableToGetTaskDefinition(t *testing.T) {
Expand All @@ -85,7 +85,7 @@ func Test_Deployer_Deploy_UnableToGetTaskDefinition(t *testing.T) {

err := deployer.Deploy(context.Background(), input)
assert.Error(t, err)
assert.Equal(t, "unable to get task definition, cause: assert.AnError general error for testing", err.Error())
assert.Equal(t, "unable to get task definition: assert.AnError general error for testing", err.Error())
}

func Test_Deployer_EmptyChanges(t *testing.T) {
Expand Down Expand Up @@ -174,7 +174,7 @@ func Test_Deployer_UnableToRegisterTaskDefinition(t *testing.T) {

err := deployer.Deploy(context.Background(), input)
assert.Error(t, err)
assert.Equal(t, "unable to register new task definition, cause: assert.AnError general error for testing", err.Error())
assert.Equal(t, "unable to register new task definition: assert.AnError general error for testing", err.Error())
}

func Test_Deployer_UnableToUpdateTaskDefinition(t *testing.T) {
Expand Down Expand Up @@ -208,7 +208,7 @@ func Test_Deployer_UnableToUpdateTaskDefinition(t *testing.T) {

err := deployer.Deploy(context.Background(), input)
assert.Error(t, err)
assert.Equal(t, "unable to update service, cause: assert.AnError general error for testing", err.Error())
assert.Equal(t, "unable to update service: assert.AnError general error for testing", err.Error())
}

func Test_Deployer_SuccessButNoWait(t *testing.T) {
Expand Down Expand Up @@ -284,7 +284,7 @@ func Test_Deployer_ServiceDoesntReflectTheChanges(t *testing.T) {

err := deployer.Deploy(context.Background(), input)
assert.Error(t, err)
assert.Equal(t, "service did not reflect changes, cause: assert.AnError general error for testing", err.Error())
assert.Equal(t, "service did not reflect changes: assert.AnError general error for testing", err.Error())
}

func Test_Deployer_ServiceReflectsChanges(t *testing.T) {
Expand Down