Skip to content
Merged
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
3 changes: 3 additions & 0 deletions lib/argument-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ class ArgumentStore {
"SEMAPHORE_AGENT_OVERPROVISION_FACTOR": "0",
"SEMAPHORE_AGENT_USE_IPV6": "false",
"SEMAPHORE_AGENT_ALLOW_PUBLIC_SUBNET": "false",
"SEMAPHORE_AGENT_ON_DEMAND_BASE_CAPACITY": "0",
"SEMAPHORE_AGENT_ON_DEMAND_PERCENTAGE_ABOVE_BASE": "100",
"SEMAPHORE_AGENT_SPOT_ALLOCATION_STRATEGY": "",
}

static validOverprovisionStrategies = ["none", "number", "percentage"]
Expand Down
33 changes: 27 additions & 6 deletions lib/aws-semaphore-agent-stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,11 +470,11 @@ class AwsSemaphoreAgentStack extends Stack {

createAutoScalingGroup(launchTemplate) {
const cfnLaunchTemplate = launchTemplate.node.defaultChild
let autoScalingGroup = new CfnAutoScalingGroup(this, 'autoScalingGroup', {
launchTemplate: {
launchTemplateId: cfnLaunchTemplate.ref,
version: cfnLaunchTemplate.attrLatestVersionNumber
},
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");

let autoScalingGroupProps = {
minSize: this.argumentStore.get("SEMAPHORE_AGENT_ASG_MIN_SIZE"),
maxSize: this.argumentStore.get("SEMAPHORE_AGENT_ASG_MAX_SIZE"),
cooldown: "60",
Expand All @@ -485,7 +485,28 @@ class AwsSemaphoreAgentStack extends Stack {
propagateAtLaunch: true
}
],
});
};

const instancesDistribution = {
onDemandBaseCapacity: onDemandBaseCapacity,
onDemandPercentageAboveBaseCapacity: onDemandPercentageAboveBase
};

if (spotAllocationStrategy != "") {
instancesDistribution.spotAllocationStrategy = spotAllocationStrategy;
}

autoScalingGroupProps.mixedInstancesPolicy = {
instancesDistribution: instancesDistribution,
launchTemplate: {
launchTemplateSpecification: {
launchTemplateId: cfnLaunchTemplate.ref,
version: cfnLaunchTemplate.attrLatestVersionNumber
}
}
};

let autoScalingGroup = new CfnAutoScalingGroup(this, 'autoScalingGroup', autoScalingGroupProps);

const maxInstanceLifetime = this.argumentStore.getAsNumber("SEMAPHORE_AGENT_ASG_MAX_INSTANCE_LIFETIME");
if (maxInstanceLifetime !== 0) {
Expand Down