diff --git a/lib/argument-store.js b/lib/argument-store.js index c4b3118..fbcd1db 100644 --- a/lib/argument-store.js +++ b/lib/argument-store.js @@ -15,6 +15,7 @@ class ArgumentStore { "SEMAPHORE_AGENT_ASG_DESIRED": "", "SEMAPHORE_AGENT_ASG_METRICS": "", "SEMAPHORE_AGENT_ASG_MAX_INSTANCE_LIFETIME": "0", + "SEMAPHORE_AGENT_ASG_LAUNCH_TEMPLATE_OVERRIDES_JSON": "", "SEMAPHORE_AGENT_DISCONNECT_AFTER_JOB": "true", "SEMAPHORE_AGENT_DISCONNECT_AFTER_IDLE_TIMEOUT": "300", "SEMAPHORE_AGENT_OS": "ubuntu-focal", @@ -45,7 +46,10 @@ class ArgumentStore { "SEMAPHORE_AGENT_ALLOW_PUBLIC_SUBNET": "false", "SEMAPHORE_AGENT_ON_DEMAND_BASE_CAPACITY": "0", "SEMAPHORE_AGENT_ON_DEMAND_PERCENTAGE_ABOVE_BASE": "100", + "SEMAPHORE_AGENT_ON_DEMAND_ALLOCATION_STRATEGY": "", "SEMAPHORE_AGENT_SPOT_ALLOCATION_STRATEGY": "", + "SEMAPHORE_AGENT_ASG_CAPACITY_REBALANCE": "false", + "SEMAPHORE_AGENT_ASG_NEW_INSTANCES_PROTECTED_FROM_SCALE_IN": "false" } static validOverprovisionStrategies = ["none", "number", "percentage"] diff --git a/lib/aws-semaphore-agent-stack.js b/lib/aws-semaphore-agent-stack.js index 6b0ba61..e25dc32 100644 --- a/lib/aws-semaphore-agent-stack.js +++ b/lib/aws-semaphore-agent-stack.js @@ -474,6 +474,7 @@ class AwsSemaphoreAgentStack extends Stack { const onDemandBaseCapacity = this.argumentStore.getAsNumber("SEMAPHORE_AGENT_ON_DEMAND_BASE_CAPACITY"); const onDemandPercentageAboveBase = this.argumentStore.getAsNumber("SEMAPHORE_AGENT_ON_DEMAND_PERCENTAGE_ABOVE_BASE"); const spotAllocationStrategy = this.argumentStore.get("SEMAPHORE_AGENT_SPOT_ALLOCATION_STRATEGY"); + const onDemandAllocationStrategy = this.argumentStore.get("SEMAPHORE_AGENT_ON_DEMAND_ALLOCATION_STRATEGY"); let autoScalingGroupProps = { minSize: this.argumentStore.get("SEMAPHORE_AGENT_ASG_MIN_SIZE"), @@ -497,7 +498,11 @@ class AwsSemaphoreAgentStack extends Stack { instancesDistribution.spotAllocationStrategy = spotAllocationStrategy; } - autoScalingGroupProps.mixedInstancesPolicy = { + if (onDemandAllocationStrategy != "") { + instancesDistribution.onDemandAllocationStrategy = onDemandAllocationStrategy; + } + + const mixedInstancesPolicy = { instancesDistribution: instancesDistribution, launchTemplate: { launchTemplateSpecification: { @@ -507,6 +512,13 @@ class AwsSemaphoreAgentStack extends Stack { } }; + if (!this.argumentStore.isEmpty("SEMAPHORE_AGENT_ASG_LAUNCH_TEMPLATE_OVERRIDES_JSON")) { + const launchTemplateOverrides = JSON.parse(this.argumentStore.get("SEMAPHORE_AGENT_ASG_LAUNCH_TEMPLATE_OVERRIDES_JSON")); + mixedInstancesPolicy.launchTemplate.overrides = [launchTemplateOverrides]; + } + + autoScalingGroupProps.mixedInstancesPolicy = mixedInstancesPolicy; + let autoScalingGroup = new CfnAutoScalingGroup(this, 'autoScalingGroup', autoScalingGroupProps); const maxInstanceLifetime = this.argumentStore.getAsNumber("SEMAPHORE_AGENT_ASG_MAX_INSTANCE_LIFETIME"); @@ -534,6 +546,9 @@ class AwsSemaphoreAgentStack extends Stack { ] } + autoScalingGroup.capacityRebalance = this.argumentStore.getAsBool("SEMAPHORE_AGENT_ASG_CAPACITY_REBALANCE"); + autoScalingGroup.newInstancesProtectedFromScaleIn = this.argumentStore.getAsBool("SEMAPHORE_AGENT_ASG_NEW_INSTANCES_PROTECTED_FROM_SCALE_IN"); + if (!this.argumentStore.isEmpty("SEMAPHORE_AGENT_AZS")) { autoScalingGroup.availabilityZones = this.argumentStore.getAsList("SEMAPHORE_AGENT_AZS"); } else if (this.argumentStore.isEmpty("SEMAPHORE_AGENT_VPC_ID")) {