Skip to content

Commit f87fe41

Browse files
author
Lachlan Donald
authored
Merge pull request #575 from buildkite/remove-aws-autoscaling
Remove AWS Autoscaling in favor of buildkite-agent-scaler
2 parents 00c45ab + 0ad02af commit f87fe41

File tree

4 files changed

+42
-279
lines changed

4 files changed

+42
-279
lines changed

.buildkite/steps/launch.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@ cat << EOF > config.json
8484
{
8585
"ParameterKey": "EnableAgentGitMirrorsExperiment",
8686
"ParameterValue": "true"
87-
},
88-
{
89-
"ParameterKey": "EnableExperimentalLambdaBasedAutoscaling",
90-
"ParameterValue": "true"
9187
}
9288
]
9389
EOF

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

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -116,34 +116,32 @@ spawn=${BUILDKITE_AGENTS_PER_INSTANCE}
116116
no-color=true
117117
EOF
118118

119+
terminate_instance_on_agent_stop() {
120+
mkdir -p /etc/systemd/system/buildkite-agent.service.d/
121+
cat << EOF > /etc/systemd/system/buildkite-agent.service.d/10-power-off-stop.conf
122+
[Service]
123+
ExecStopPost=/usr/local/bin/terminate-instance
124+
ExecStopPost=/bin/sudo poweroff
125+
EOF
126+
127+
# If we modify the systemd, we need to rebuild the dependency tree
128+
systemctl daemon-reload
129+
}
130+
119131
# Add conditional config to the agent config
120132
if [[ "${BUILDKITE_TERMINATE_INSTANCE_AFTER_JOB:-false}" == "true" ]] ; then
121133
cat << EOF >> /etc/buildkite-agent/buildkite-agent.cfg
122134
disconnect-after-job=true
123135
disconnect-after-job-timeout=${BUILDKITE_TERMINATE_INSTANCE_AFTER_JOB_TIMEOUT}
124136
EOF
125-
elif [[ "${BUILDKITE_LAMBDA_AUTOSCALING}" == "true" ]] ; then
126-
cat << EOF >> /etc/buildkite-agent/buildkite-agent.cfg
127-
disconnect-after-idle-timeout=${BUILDKITE_SCALE_DOWN_PERIOD}
128-
EOF
137+
terminate_instance_on_agent_stop
129138
fi
130139

131-
# If we are using the lambda for autoscaling, always decrease capacity
132140
if [[ "${BUILDKITE_LAMBDA_AUTOSCALING}" == "true" ]] ; then
133-
BUILDKITE_TERMINATE_INSTANCE_AFTER_JOB_DECREASE_DESIRED_CAPACITY=true
134-
fi
135-
136-
if [[ "${BUILDKITE_TERMINATE_INSTANCE_AFTER_JOB}" == "true" || "${BUILDKITE_LAMBDA_AUTOSCALING}" == "true" ]] ; then
137-
mkdir -p /etc/systemd/system/buildkite-agent.service.d/
138-
139-
cat << EOF > /etc/systemd/system/buildkite-agent.service.d/10-power-off-stop.conf
140-
[Service]
141-
ExecStopPost=/usr/local/bin/terminate-instance ${BUILDKITE_TERMINATE_INSTANCE_AFTER_JOB_DECREASE_DESIRED_CAPACITY}
142-
ExecStopPost=/bin/sudo poweroff
141+
cat << EOF >> /etc/buildkite-agent/buildkite-agent.cfg
142+
disconnect-after-idle-timeout=${BUILDKITE_SCALE_IN_IDLE_PERIOD}
143143
EOF
144-
145-
# If we modify the systemd, we need to rebuild the dependency tree
146-
systemctl daemon-reload
144+
terminate_instance_on_agent_stop
147145
fi
148146

149147
chown buildkite-agent: /etc/buildkite-agent/buildkite-agent.cfg
@@ -168,7 +166,6 @@ fi
168166

169167
cat << EOF > /etc/lifecycled
170168
AWS_REGION=${AWS_REGION}
171-
LIFECYCLED_SNS_TOPIC=${BUILDKITE_LIFECYCLE_TOPIC}
172169
LIFECYCLED_HANDLER=/usr/local/bin/stop-agent-gracefully
173170
LIFECYCLED_CLOUDWATCH_GROUP=/buildkite/lifecycled
174171
EOF

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,11 @@ disconnect-after-job=true
9999
disconnect-after-job-timeout=$Env:BUILDKITE_TERMINATE_INSTANCE_AFTER_JOB_TIMEOUT
100100
"@
101101
}
102-
ElseIf ($Env:BUILDKITE_LAMBDA_AUTOSCALING -eq "true") {
103-
Add-Content -Path C:\buildkite-agent\buildkite-agent.cfg -Value @"
104-
disconnect-after-idle-timeout=${Env:BUILDKITE_SCALE_DOWN_PERIOD}
105-
"@
106-
}
107102

108-
# If we are using the lambda for autoscaling, always decrease capacity
109103
If ($Env:BUILDKITE_LAMBDA_AUTOSCALING -eq "true") {
110-
$Env:BUILDKITE_TERMINATE_INSTANCE_AFTER_JOB_DECREASE_DESIRED_CAPACITY = "true"
104+
Add-Content -Path C:\buildkite-agent\buildkite-agent.cfg -Value @"
105+
disconnect-after-idle-timeout=${Env:BUILDKITE_SCALE_IN_IDLE_PERIOD}
106+
"@
111107
}
112108

113109
If (![string]::IsNullOrEmpty($Env:BUILDKITE_ELASTIC_BOOTSTRAP_SCRIPT)) {
@@ -117,7 +113,6 @@ If (![string]::IsNullOrEmpty($Env:BUILDKITE_ELASTIC_BOOTSTRAP_SCRIPT)) {
117113
}
118114

119115
nssm set lifecycled AppEnvironmentExtra :AWS_REGION=$Env:AWS_REGION
120-
nssm set lifecycled AppEnvironmentExtra +LIFECYCLED_SNS_TOPIC=$Env:BUILDKITE_LIFECYCLE_TOPIC
121116
nssm set lifecycled AppEnvironmentExtra +LIFECYCLED_HANDLER="C:\buildkite-agent\bin\stop-agent-gracefully.ps1"
122117
Restart-Service lifecycled
123118

@@ -155,9 +150,10 @@ nssm set buildkite-agent ObjectName .\$UserName $Password
155150
nssm set buildkite-agent AppStdout C:\buildkite-agent\buildkite-agent.log
156151
nssm set buildkite-agent AppStderr C:\buildkite-agent\buildkite-agent.log
157152
nssm set buildkite-agent AppEnvironmentExtra :HOME=C:\buildkite-agent
153+
158154
If (($Env:BUILDKITE_TERMINATE_INSTANCE_AFTER_JOB -eq "true") -or ($Env:BUILDKITE_LAMBDA_AUTOSCALING -eq "true")) {
159155
nssm set buildkite-agent AppExit Default Exit
160-
nssm set buildkite-agent AppEvents Exit/Post "powershell C:\buildkite-agent\bin\terminate-instance.ps1 $Env:BUILDKITE_TERMINATE_INSTANCE_AFTER_JOB_DECREASE_DESIRED_CAPACITY"
156+
nssm set buildkite-agent AppEvents Exit/Post "powershell C:\buildkite-agent\bin\terminate-instance.ps1"
161157
}
162158
Restart-Service buildkite-agent
163159

0 commit comments

Comments
 (0)