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
9 changes: 7 additions & 2 deletions src/pkg/clouds/aws/ecs/cfn/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,14 @@ func (a *AwsEcs) createStackAndWait(ctx context.Context, templateBody string) er
}

func (a *AwsEcs) SetUp(ctx context.Context, containers []types.Container) error {
template, err := createTemplate(a.stackName, containers, TemplateOverrides{VpcID: a.VpcID, Spot: a.Spot}).YAML()
tmpl, err := createTemplate(a.stackName, containers, TemplateOverrides{VpcID: a.VpcID, Spot: a.Spot})
if err != nil {
return err
return fmt.Errorf("failed to create CloudFormation template: %w", err)
}

template, err := tmpl.YAML()
if err != nil {
return fmt.Errorf("failed to marshal CloudFormation template as YAML: %w", err)
}

// Upsert
Expand Down
8 changes: 6 additions & 2 deletions src/pkg/clouds/aws/ecs/cfn/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"fmt"
"math"
"os"
"strconv"
Expand Down Expand Up @@ -58,7 +59,7 @@ type TemplateOverrides struct {

const TemplateRevision = 1 // bump this when the template changes!

func createTemplate(stack string, containers []types.Container, overrides TemplateOverrides) *cloudformation.Template {
func createTemplate(stack string, containers []types.Container, overrides TemplateOverrides) (*cloudformation.Template, error) {
prefix := stack + "-"

defaultTags := []tags.Tag{
Expand Down Expand Up @@ -182,6 +183,9 @@ func createTemplate(stack string, containers []types.Container, overrides Templa
// TODO: support pull through cache for other registries
// TODO: support private repos (with or without pull-through cache)
}
if strings.TrimSpace(image) == "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a bit random to have TrimSpace here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, a bit premature optimisation, just trying to avoid "\t", "\n" kind of situation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not do it

Suggested change
if strings.TrimSpace(image) == "" {
if image == "" {

return nil, fmt.Errorf("container %v is using invalid image: %q", task.Name, task.Image)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good to have, but I'd add another check higher up the stack with a more user-facing error message.

}
images = append(images, image)
}

Expand Down Expand Up @@ -545,5 +549,5 @@ func createTemplate(stack string, containers []types.Container, overrides Templa
Value: cloudformation.Int(TemplateRevision),
}

return template
return template, nil
}