Skip to content

Commit d06ab5e

Browse files
authored
Merge branch 'master' into MaxInstanceLifetime
2 parents 62c209b + c0371d6 commit d06ab5e

File tree

9 files changed

+91
-9
lines changed

9 files changed

+91
-9
lines changed

goss.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ service:
4444
enabled: true
4545
running: true
4646

47+
lifecycled:
48+
enabled: true
49+
running: true
50+
4751
sshd:
4852
enabled: true
4953
running: true
@@ -89,6 +93,9 @@ process:
8993
buildkite-agent:
9094
running: true
9195

96+
lifecycled:
97+
running: true
98+
9299
sshd:
93100
running: true
94101

packer/linux/buildkite-ami.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@
4545
"type": "shell",
4646
"script": "scripts/install-cloudwatch-agent.sh"
4747
},
48+
{
49+
"type": "shell",
50+
"script": "scripts/install-lifecycled.sh"
51+
},
4852
{
4953
"type": "shell",
5054
"script": "scripts/install-docker.sh"

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

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,25 +134,31 @@ if [[ "${BUILDKITE_AGENT_ENABLE_GIT_MIRRORS_EXPERIMENT}" == "true" ]] ; then
134134
BUILDKITE_AGENT_EXPERIMENTS+=",git-mirrors"
135135
fi
136136

137+
BUILDKITE_AGENT_GIT_MIRRORS_PATH="/var/lib/buildkite-agent/git-mirrors"
138+
mkdir -p "${BUILDKITE_AGENT_GIT_MIRRORS_PATH}"
139+
137140
if [ "${BUILDKITE_ENABLE_INSTANCE_STORAGE:-false}" == "true" ]
138141
then
139-
BUILDKITE_AGENT_GIT_MIRRORS_PATH="/mnt/ephemeral/git-mirrors"
142+
EPHEMERAL_GIT_MIRRORS_PATH="/mnt/ephemeral/git-mirrors"
143+
mkdir -p "${EPHEMERAL_GIT_MIRRORS_PATH}"
140144

141-
mkdir -p "${BUILDKITE_AGENT_GIT_MIRRORS_PATH}"
142-
chown buildkite-agent: "${BUILDKITE_AGENT_GIT_MIRRORS_PATH}"
143-
else
144-
BUILDKITE_AGENT_GIT_MIRRORS_PATH="/var/lib/buildkite-agent/git-mirrors"
145+
mount -o bind "${EPHEMERAL_GIT_MIRRORS_PATH}" "${BUILDKITE_AGENT_GIT_MIRRORS_PATH}"
146+
echo "${EPHEMERAL_GIT_MIRRORS_PATH} ${BUILDKITE_AGENT_GIT_MIRRORS_PATH} none defaults,bind 0 0" >>/etc/fstab
145147
fi
148+
149+
chown buildkite-agent: "${BUILDKITE_AGENT_GIT_MIRRORS_PATH}"
146150
fi
147151

148152
BUILDKITE_AGENT_BUILD_PATH="/var/lib/buildkite-agent/builds"
153+
mkdir -p "${BUILDKITE_AGENT_BUILD_PATH}"
149154
if [ "${BUILDKITE_ENABLE_INSTANCE_STORAGE:-false}" == "true" ]
150155
then
151-
BUILDKITE_AGENT_BUILD_PATH="/mnt/ephemeral/builds"
152-
153-
mkdir -p "${BUILDKITE_AGENT_BUILD_PATH}"
154-
chown buildkite-agent: "${BUILDKITE_AGENT_BUILD_PATH}"
156+
EPHEMERAL_BUILD_PATH="/mnt/ephemeral/builds"
157+
mkdir -p "${EPHEMERAL_BUILD_PATH}"
158+
mount -o bind "${EPHEMERAL_BUILD_PATH}" "${BUILDKITE_AGENT_BUILD_PATH}"
159+
echo "${EPHEMERAL_BUILD_PATH} ${BUILDKITE_AGENT_BUILD_PATH} none defaults,bind 0 0" >>/etc/fstab
155160
fi
161+
chown buildkite-agent: "${BUILDKITE_AGENT_BUILD_PATH}"
156162

157163
BUILDKITE_AGENT_TOKEN="$(aws ssm get-parameter --name "${BUILDKITE_AGENT_TOKEN_PATH}" --with-decryption --query Parameter.Value --output text)"
158164

@@ -197,6 +203,15 @@ if [[ -n "${BUILDKITE_ELASTIC_BOOTSTRAP_SCRIPT}" ]] ; then
197203
rm /tmp/elastic_bootstrap
198204
fi
199205

206+
cat << EOF > /etc/lifecycled
207+
AWS_REGION=${AWS_REGION}
208+
LIFECYCLED_HANDLER=/usr/local/bin/stop-agent-gracefully
209+
LIFECYCLED_CLOUDWATCH_GROUP=/buildkite/lifecycled
210+
EOF
211+
212+
systemctl enable lifecycled.service
213+
systemctl start lifecycled
214+
200215
# wait for docker to start
201216
next_wait_time=0
202217
until docker ps || [ $next_wait_time -eq 5 ]; do
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
set -eu -o pipefail
3+
4+
LIFECYCLED_VERSION=v3.2.0
5+
6+
MACHINE=$(uname -m)
7+
8+
case "${MACHINE}" in
9+
x86_64) ARCH=amd64;;
10+
aarch64) ARCH=arm64;;
11+
*) ARCH=unknown;;
12+
esac
13+
14+
echo "Installing lifecycled ${LIFECYCLED_VERSION}..."
15+
16+
sudo touch /etc/lifecycled
17+
sudo curl -Lf -o /usr/bin/lifecycled \
18+
https://github.com/buildkite/lifecycled/releases/download/${LIFECYCLED_VERSION}/lifecycled-linux-${ARCH}
19+
sudo chmod +x /usr/bin/lifecycled
20+
sudo curl -Lf -o /etc/systemd/system/lifecycled.service \
21+
https://raw.githubusercontent.com/buildkite/lifecycled/${LIFECYCLED_VERSION}/init/systemd/lifecycled.unit
22+

packer/windows/buildkite-ami.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444
"type": "powershell",
4545
"script": "scripts/install-cloudwatch-agent.ps1"
4646
},
47+
{
48+
"type": "powershell",
49+
"script": "scripts/install-lifecycled.ps1"
50+
},
4751
{
4852
"type": "powershell",
4953
"script": "scripts/install-docker.ps1"

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ disconnect-after-job=${Env:BUILDKITE_TERMINATE_INSTANCE_AFTER_JOB}
140140
"@
141141
$OFS=" "
142142

143+
nssm set lifecycled AppEnvironmentExtra :AWS_REGION=$Env:AWS_REGION
144+
nssm set lifecycled AppEnvironmentExtra +LIFECYCLED_HANDLER="C:\buildkite-agent\bin\stop-agent-gracefully.ps1"
145+
Restart-Service lifecycled
146+
143147
# wait for docker to start
144148
$next_wait_time=0
145149
do {

packer/windows/conf/cloudwatch-agent/amazon-cloudwatch-agent.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
"file_path": "C:\\buildkite-agent\\buildkite-agent.log",
2323
"log_group_name": "/buildkite/buildkite-agent",
2424
"timestamp_format": "%Y-%m-%dT%H:%M:%S.%f"
25+
},
26+
{
27+
"file_path": "C:\\lifecycled\\lifecycled.log",
28+
"log_group_name": "/buildkite/lifecycled",
29+
"timestamp_format": "%Y-%m-%dT%H:%M:%S.%f"
2530
}
2631
]
2732
},
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Stop script execution when a non-terminating error occurs
2+
$ErrorActionPreference = "Stop"
3+
4+
$lifecycled_version = "v3.2.0"
5+
6+
Write-Output "Installing lifecycled ${lifecycled_version}..."
7+
8+
New-Item -ItemType directory -Path C:\lifecycled\bin
9+
10+
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
11+
Invoke-WebRequest -OutFile C:\lifecycled\bin\lifecycled.exe https://github.com/buildkite/lifecycled/releases/download/${lifecycled_version}/lifecycled-windows-amd64.exe
12+
13+
Write-Output "Configure lifecycled to run on startup..."
14+
nssm install lifecycled C:\lifecycled\bin\lifecycled.exe
15+
If ($lastexitcode -ne 0) { Exit $lastexitcode }
16+
nssm set lifecycled AppStdout C:\lifecycled\lifecycled.log
17+
If ($lastexitcode -ne 0) { Exit $lastexitcode }
18+
nssm set lifecycled AppStderr C:\lifecycled\lifecycled.log
19+
If ($lastexitcode -ne 0) { Exit $lastexitcode }

templates/aws-stack.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,8 @@ Resources:
10541054
- OldestLaunchConfiguration
10551055
- ClosestToNextInstanceHour
10561056
MaxInstanceLifetime: !If [UseMaxInstanceLifetime, !Ref MaxInstanceLifetime, !Ref "AWS::NoValue"]
1057+
NewInstancesProtectedFromScaleIn: true
1058+
10571059
CreationPolicy:
10581060
ResourceSignal:
10591061
Timeout: !If [ UseDefaultInstanceCreationTimeout, !If [ UseWindowsAgents, PT10M, PT5M ], !Ref InstanceCreationTimeout ]

0 commit comments

Comments
 (0)