Skip to content
4 changes: 4 additions & 0 deletions lib/argument-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"]
Expand Down
17 changes: 16 additions & 1 deletion lib/aws-semaphore-agent-stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -497,7 +498,11 @@ class AwsSemaphoreAgentStack extends Stack {
instancesDistribution.spotAllocationStrategy = spotAllocationStrategy;
}

autoScalingGroupProps.mixedInstancesPolicy = {
if (onDemandAllocationStrategy != "") {
instancesDistribution.onDemandAllocationStrategy = onDemandAllocationStrategy;
}

const mixedInstancesPolicy = {
instancesDistribution: instancesDistribution,
launchTemplate: {
launchTemplateSpecification: {
Expand All @@ -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");
Expand Down Expand Up @@ -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")) {
Expand Down