Skip to content

Commit

Permalink
Merge pull request #3 from AdRoll/update-aws-sdk-version
Browse files Browse the repository at this point in the history
update aws sdk version
  • Loading branch information
odarbelaeze authored Sep 20, 2024
2 parents bb616fb + e7c23d3 commit 4c3d273
Show file tree
Hide file tree
Showing 14 changed files with 310 additions and 236 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v5
with:
go-version: 1.15
go-version: 1.22

- name: Build
run: go build -v ./...
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/ship-latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ jobs:
steps:
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
uses: docker/setup-qemu-action@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v3
-
name: Login to DockerHub
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Build and push
id: docker_build
uses: docker/build-push-action@v2
uses: docker/build-push-action@v6
with:
push: true
tags: |
Expand All @@ -36,13 +36,13 @@ jobs:
runs-on: ubuntu-latest
steps:
-
uses: actions/checkout@v2
uses: actions/checkout@v4

-
name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v5
with:
go-version: 1.15
go-version: 1.22

-
name: Test
Expand Down
18 changes: 9 additions & 9 deletions .github/workflows/ship-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,26 @@ jobs:
steps:
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
uses: docker/setup-qemu-action@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v3
-
name: Login to DockerHub
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Build and push
id: docker_build
uses: docker/build-push-action@v2
uses: docker/build-push-action@v6
with:
push: true
tags: |
nextroll/ecs-ship:v1
nextroll/ecs-ship:v1.0
nextroll/ecs-ship:v1.0.0
nextroll/ecs-ship:v1.2
nextroll/ecs-ship:v1.2.0
-
name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
Expand All @@ -38,13 +38,13 @@ jobs:
runs-on: ubuntu-latest
steps:
-
uses: actions/checkout@v2
uses: actions/checkout@v4

-
name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v5
with:
go-version: 1.15
go-version: 1.22

-
name: Test
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.15 AS builder
FROM golang:1.22 AS builder
COPY ./ /src/github.com/adroll/ecs-ship/
RUN cd /src/github.com/adroll/ecs-ship/ \
&& go test ./... \
Expand Down
38 changes: 18 additions & 20 deletions action/ecs-deploy.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
package action

import (
"context"
"errors"
"log"
"time"

"github.com/adroll/ecs-ship/ecs"
ecssdk "github.com/aws/aws-sdk-go/service/ecs"
ecssdk "github.com/aws/aws-sdk-go-v2/service/ecs"
"github.com/aws/aws-sdk-go-v2/service/ecs/types"
"github.com/fatih/color"
)

// ECSDeployClient defines a simple interface for our required ecs stuffs
type ECSDeployClient interface {
GetService(clusterName string, serviceName string) (*ecssdk.Service, error)
LooksGood(service *ecssdk.Service) (bool, error)
CopyTaskDefinition(service *ecssdk.Service) (*ecssdk.RegisterTaskDefinitionInput, *ecssdk.TaskDefinition, error)
WaitUntilGood(service *ecssdk.Service, timeout *time.Duration) error
RegisterTaskDefinition(input *ecssdk.RegisterTaskDefinitionInput) (*ecssdk.TaskDefinition, error)
UpdateTaskDefinition(service *ecssdk.Service, task *ecssdk.TaskDefinition) (*ecssdk.Service, error)
GetService(ctx context.Context, clusterName string, serviceName string) (*types.Service, error)
LooksGood(ctx context.Context, service *types.Service) (bool, error)
WaitUntilGood(ctx context.Context, service *types.Service, timeout *time.Duration) error
CopyTaskDefinition(ctx context.Context, service *types.Service) (*ecssdk.RegisterTaskDefinitionInput, *types.TaskDefinition, error)
RegisterTaskDefinition(ctx context.Context, input *ecssdk.RegisterTaskDefinitionInput) (*types.TaskDefinition, error)
UpdateTaskDefinition(ctx context.Context, service *types.Service, task *types.TaskDefinition) (*types.Service, error)
}

// ECSDeployTaskConfig defines a simple interface of how we want a config thing to do
Expand All @@ -26,7 +28,7 @@ type ECSDeployTaskConfig interface {
}

// ECSDeploy deploy an ecs service
func ECSDeploy(clusterName string, serviceName string, client ECSDeployClient, timeout time.Duration, config ECSDeployTaskConfig, dryRun bool, noWait bool) error {
func ECSDeploy(ctx context.Context, clusterName string, serviceName string, client ECSDeployClient, timeout time.Duration, config ECSDeployTaskConfig, dryRun bool, noWait bool) error {
if len(clusterName) == 0 {
return errors.New("cluster was not provided")
}
Expand All @@ -40,14 +42,14 @@ func ECSDeploy(clusterName string, serviceName string, client ECSDeployClient, t
return errors.New("config was not provided")
}

service, err := client.GetService(clusterName, serviceName)
service, err := client.GetService(ctx, clusterName, serviceName)
if err != nil {
return err
}

log.Printf("Updating service:\n Cluster: %s\n Service: %s\n", clusterName, serviceName)

good, err := client.LooksGood(service)
good, err := client.LooksGood(ctx, service)
if err != nil {
return err
}
Expand All @@ -57,7 +59,7 @@ func ECSDeploy(clusterName string, serviceName string, client ECSDeployClient, t
log.Println(color.YellowString("The service doesn't look good to begin with"))
}

copyTask, oldTaskDefinition, err := client.CopyTaskDefinition(service)
copyTask, oldTaskDefinition, err := client.CopyTaskDefinition(ctx, service)
if err != nil {
return err
}
Expand All @@ -68,10 +70,6 @@ func ECSDeploy(clusterName string, serviceName string, client ECSDeployClient, t
return nil
}

if err := newTask.Validate(); err != nil {
return err
}

log.Println("These are the changes:")
log.Println(diff)

Expand All @@ -80,14 +78,14 @@ func ECSDeploy(clusterName string, serviceName string, client ECSDeployClient, t
return nil
}

newTaskDefinition, err := client.RegisterTaskDefinition(newTask)
newTaskDefinition, err := client.RegisterTaskDefinition(ctx, newTask)
if err != nil {
return err
}

log.Printf("Changing task definition\n Old: %s\n New: %s\n", *service.TaskDefinition, *newTaskDefinition.TaskDefinitionArn)

newService, err := client.UpdateTaskDefinition(service, newTaskDefinition)
newService, err := client.UpdateTaskDefinition(ctx, service, newTaskDefinition)
if err != nil {
return err
}
Expand All @@ -98,16 +96,16 @@ func ECSDeploy(clusterName string, serviceName string, client ECSDeployClient, t
}

log.Println("Waiting for the service to reflect the new changes...")
if originalErr := client.WaitUntilGood(newService, &timeout); originalErr != nil {
if originalErr := client.WaitUntilGood(ctx, newService, &timeout); originalErr != nil {
log.Println(color.RedString("There was an error updating the service :", originalErr.Error()))
log.Println(color.YellowString("we are trying to roll back changes..."))
rolledBackService, err := client.UpdateTaskDefinition(service, oldTaskDefinition)
rolledBackService, err := client.UpdateTaskDefinition(ctx, service, oldTaskDefinition)
if err != nil {
log.Println(color.RedString("You're unlucky we also failed to roll back the service with error:", err.Error()))
return originalErr
}
log.Println("Waiting for rollback service to reflect the new changes...")
if err = client.WaitUntilGood(rolledBackService, &timeout); good && err != nil {
if err = client.WaitUntilGood(ctx, rolledBackService, &timeout); good && err != nil {
log.Println(color.RedString("stopped waiting with error:", err.Error()))
return originalErr
}
Expand Down
Loading

0 comments on commit 4c3d273

Please sign in to comment.