Skip to content

Commit

Permalink
[ECS] workload ECS for NPM tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nplanel committed Feb 15, 2024
1 parent a2d0c9b commit 6a6dd83
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions components/datadog/apps/npm-tools/ecs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package npmtools

import (
"fmt"

"github.com/DataDog/test-infra-definitions/common/config"
"github.com/DataDog/test-infra-definitions/resources/aws"

"github.com/pulumi/pulumi-awsx/sdk/go/awsx/awsx"
"github.com/pulumi/pulumi-awsx/sdk/go/awsx/ecs"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

type EcsComponent struct {
pulumi.ResourceState
}

func EcsAppDefinition(e aws.Environment, clusterArn pulumi.StringInput, testURL string, opts ...pulumi.ResourceOption) (*EcsComponent, error) {
namer := e.Namer.WithPrefix("npm-tools")
opts = append(opts, e.WithProviders(config.ProviderAWS, config.ProviderAWSX))

ecsComponent := &EcsComponent{}
if err := e.Ctx.RegisterComponentResource("dd:apps", namer.ResourceName("grp"), ecsComponent, opts...); err != nil {
return nil, err
}

opts = append(opts, pulumi.Parent(ecsComponent))

if _, err := ecs.NewEC2Service(e.Ctx, namer.ResourceName("curl-dig"), &ecs.EC2ServiceArgs{
Name: e.CommonNamer.DisplayName(255, pulumi.String("curl-dig")),
Cluster: clusterArn,
DesiredCount: pulumi.IntPtr(1),
EnableExecuteCommand: pulumi.BoolPtr(true),
TaskDefinitionArgs: &ecs.EC2ServiceTaskDefinitionArgs{
Containers: map[string]ecs.TaskDefinitionContainerDefinitionArgs{
"curl-dig": {
Name: pulumi.String("curl-dig"),
Image: pulumi.String("ghcr.io/datadog/apps-npm-tools:main"),
Command: pulumi.StringArray{
pulumi.String("sh"),
pulumi.String("-c"),
pulumi.String(fmt.Sprintf("while [ 1 ] ; do curl %s ; dig @8.8.8.8 www.google.ch ; sleep 20 ; done", testURL)),
},
Cpu: pulumi.IntPtr(200),
Memory: pulumi.IntPtr(64),
},
},
ExecutionRole: &awsx.DefaultRoleWithPolicyArgs{
RoleArn: pulumi.StringPtr(e.ECSTaskExecutionRole()),
},
TaskRole: &awsx.DefaultRoleWithPolicyArgs{
RoleArn: pulumi.StringPtr(e.ECSTaskRole()),
},
NetworkMode: pulumi.StringPtr("none"),
Family: e.CommonNamer.DisplayName(255, pulumi.String("curl-dig-ec2")),
},
}, opts...); err != nil {
return nil, err
}

return ecsComponent, nil
}

0 comments on commit 6a6dd83

Please sign in to comment.