Skip to content

Commit 01aa09b

Browse files
committed
Make the boothook conditional on warm pool
1 parent 1671a30 commit 01aa09b

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

packer/linux/conf/bin/bk-install-elastic-stack.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,12 @@ fi
215215

216216
systemctl enable "buildkite-agent"
217217

218+
# If warm pool is enabled, don't start the agent until the ASG BootHook
219+
if [ "${BUILDKITE_USE_WARM_POOL:-false}" == "false" ]
220+
then
221+
systemctl start "buildkite-agent"
222+
fi
223+
218224
# let the stack know that this host has been initialized successfully
219225
/opt/aws/bin/cfn-signal \
220226
--region "$AWS_REGION" \

packer/windows/conf/bin/bk-install-elastic-stack.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,11 @@ If ($lastexitcode -ne 0) { Exit $lastexitcode }
210210
nssm set buildkite-agent AppRestartDelay 5000
211211
If ($lastexitcode -ne 0) { Exit $lastexitcode }
212212

213+
# If warm pool is enabled, don't start the agent until the ASG BootHook
214+
If ($null -eq $Env:BUILDKITE_USE_WARM_POOL -or $Env:BUILDKITE_USE_WARM_POOL -eq "false") {
215+
Restart-Service buildkite-agent
216+
}
217+
213218
# renable debug tracing
214219
Set-PSDebug -Trace 2
215220

templates/aws-stack.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -991,11 +991,13 @@ Resources:
991991
$Env:ECR_PLUGIN_ENABLED="${EnableECRPlugin}"
992992
$Env:DOCKER_LOGIN_PLUGIN_ENABLED="${EnableDockerLoginPlugin}"
993993
$Env:AWS_REGION="${AWS::Region}"
994+
$Env:BUILDKITE_WARM_POOL="${WarmPool}"
994995
powershell -file C:\buildkite-agent\bin\bk-install-elastic-stack.ps1 >> C:\buildkite-agent\elastic-stack.log
995996
</powershell>
996997
- {
997998
LocalSecretsBucket: !If [ CreateSecretsBucket, !Ref ManagedSecretsBucket, !Ref SecretsBucket ],
998999
AgentTokenPath: !If [ UseCustomerManagedParameterPath, !Ref BuildkiteAgentTokenParameterStorePath, !Ref BuildkiteAgentTokenParameter ],
1000+
WarmPool: !If [ UseWarmPool, "true", "false" ],
9991001
}
10001002
- !Sub
10011003
- |
@@ -1038,11 +1040,13 @@ Resources:
10381040
DOCKER_LOGIN_PLUGIN_ENABLED="${EnableDockerLoginPlugin}" \
10391041
DOCKER_EXPERIMENTAL="${EnableDockerExperimental}" \
10401042
AWS_REGION="${AWS::Region}" \
1043+
BUILDKITE_WARM_POOL="${WarmPool}" \
10411044
/usr/local/bin/bk-install-elastic-stack.sh
10421045
--==BOUNDARY==--
10431046
- {
10441047
LocalSecretsBucket: !If [ CreateSecretsBucket, !Ref ManagedSecretsBucket, !Ref SecretsBucket ],
10451048
AgentTokenPath: !If [ UseCustomerManagedParameterPath, !Ref BuildkiteAgentTokenParameterStorePath, !Ref BuildkiteAgentTokenParameter ],
1049+
WarmPool: !If [ UseWarmPool, "true", "false" ],
10461050
}
10471051

10481052
AgentAutoScaleGroup:
@@ -1099,7 +1103,7 @@ Resources:
10991103
AutoScalingReplacingUpdate:
11001104
WillReplace: true
11011105

1102-
AsgWarmPool:
1106+
WarmPool:
11031107
Type: AWS::AutoScaling::WarmPool
11041108
Condition: UseWarmPool
11051109
Properties:
@@ -1163,7 +1167,7 @@ Resources:
11631167
- Effect: Allow
11641168
Action: ssm:StartAutomationExecution
11651169
Resource:
1166-
- !Sub arn:${AWS::Partition}:ssm:${AWS::Region}:${AWS::AccountId}:automation-definition/${BootHookAutomation}:$DEFAULT
1170+
- !If [ UseWarmPool, !Sub arn:${AWS::Partition}:ssm:${AWS::Region}:${AWS::AccountId}:automation-definition/${BootHookAutomation}:$DEFAULT, !Ref "AWS::NoValue" ]
11671171
- !Sub arn:${AWS::Partition}:ssm:${AWS::Region}:${AWS::AccountId}:automation-definition/${ShutdownHookAutomation}:$DEFAULT
11681172
- !Sub arn:${AWS::Partition}:ssm:${AWS::Region}:${AWS::AccountId}:automation-definition/${SpotInteruptionAutomation}:$DEFAULT
11691173
- Effect: Allow
@@ -1210,6 +1214,7 @@ Resources:
12101214

12111215
BootHook:
12121216
Type: AWS::AutoScaling::LifecycleHook
1217+
Condition: UseWarmPool
12131218
Properties:
12141219
AutoScalingGroupName: !Ref AgentAutoScaleGroup
12151220
LifecycleHookName: BootHook
@@ -1220,6 +1225,7 @@ Resources:
12201225

12211226
BootHookRule:
12221227
Type: AWS::Events::Rule
1228+
Condition: UseWarmPool
12231229
Properties:
12241230
Description: !Sub Run the boot time AWS SSM Automation for ${BootHook}
12251231
EventPattern:
@@ -1241,6 +1247,7 @@ Resources:
12411247

12421248
BootHookAutomation:
12431249
Type: AWS::SSM::Document
1250+
Condition: UseWarmPool
12441251
Properties:
12451252
DocumentType: Automation
12461253
Content:

0 commit comments

Comments
 (0)