Skip to content

Commit

Permalink
fix(aws/batch): Add config for increasing docker system volume size v…
Browse files Browse the repository at this point in the history
…ia launch template (#686)

* add launch template to increase default EBS size.
* add block device mapping to launch template config
  • Loading branch information
tjholm authored Oct 18, 2024
1 parent 76ea627 commit 7fbcbe5
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
25 changes: 19 additions & 6 deletions cloud/aws/common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,22 @@ type AwsImports struct {
Buckets map[string]string
}

type EcsLaunchTemplate struct {
BlockDeviceMappings []struct {
DeviceName string `mapstructure:"device-name,omitempty"`
Ebs struct {
DeleteOnTermination string `mapstructure:"delete-on-termination,omitempty"`
VolumeSize int `mapstructure:"volume-size,omitempty"`
VolumeType string `mapstructure:"volume-type,omitempty"`
} `mapstructure:"ebs,omitempty"`
} `mapstructure:"block-device-mappings,omitempty"`
}

type BatchComputeEnvConfig struct {
MinCpus int `mapstructure:"min-cpus"`
MaxCpus int `mapstructure:"max-cpus"`
InstanceTypes []string `mapstructure:"instance-types"`
MinCpus int `mapstructure:"min-cpus"`
MaxCpus int `mapstructure:"max-cpus"`
InstanceTypes []string `mapstructure:"instance-types"`
LaunchTemplate *EcsLaunchTemplate `mapstructure:"launch-template,omitempty"`
}

type AwsConfig struct {
Expand Down Expand Up @@ -72,9 +84,10 @@ var defaultLambdaConfig = &AwsLambdaConfig{
}

var defaultBatchComputeEnvConfig = &BatchComputeEnvConfig{
MinCpus: 0,
MaxCpus: 32,
InstanceTypes: []string{"optimal"},
MinCpus: 0,
MaxCpus: 32,
InstanceTypes: []string{"optimal"},
LaunchTemplate: nil,
}

var defaultAwsConfigItem = AwsConfigItem{
Expand Down
25 changes: 25 additions & 0 deletions cloud/aws/deploy/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,31 @@ func (a *NitricAwsPulumiProvider) batch(ctx *pulumi.Context) error {
InstanceRole: instanceProfile.Arn,
}

if a.AwsConfig.BatchComputeEnvConfig.LaunchTemplate != nil {
blockDevicemappings := awsec2.LaunchTemplateBlockDeviceMappingArray{}
for _, bd := range a.AwsConfig.BatchComputeEnvConfig.LaunchTemplate.BlockDeviceMappings {
blockDevicemappings = append(blockDevicemappings, &awsec2.LaunchTemplateBlockDeviceMappingArgs{
DeviceName: pulumi.String(bd.DeviceName),
Ebs: &awsec2.LaunchTemplateBlockDeviceMappingEbsArgs{
DeleteOnTermination: pulumi.String(bd.Ebs.DeleteOnTermination),
VolumeSize: pulumi.Int(bd.Ebs.VolumeSize),
VolumeType: pulumi.String(bd.Ebs.VolumeType),
},
})
}

launchTemplate, err := awsec2.NewLaunchTemplate(ctx, "batch-launch-template", &awsec2.LaunchTemplateArgs{
BlockDeviceMappings: blockDevicemappings,
})
if err != nil {
return err
}

computeResourceOptions.LaunchTemplate = &batch.ComputeEnvironmentComputeResourcesLaunchTemplateArgs{
LaunchTemplateName: launchTemplate.Name,
}
}

a.ComputeEnvironment, err = batch.NewComputeEnvironment(ctx, "compute-environment", &batch.ComputeEnvironmentArgs{
ComputeEnvironmentName: pulumi.Sprintf("%s-compute-environment", a.StackId),
ComputeResources: computeResourceOptions,
Expand Down

0 comments on commit 7fbcbe5

Please sign in to comment.