Skip to content

Commit e1d8d6b

Browse files
committed
Fix OCI build
1 parent ec0941d commit e1d8d6b

File tree

4 files changed

+35
-21
lines changed

4 files changed

+35
-21
lines changed

scripts/packer/oci-image-cuda.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@
2727
"type": "shell",
2828
"inline": ["cloud-init status --long --wait"]
2929
},
30-
{
31-
"type": "shell",
32-
"script": "provisioners/wait-for-dpkg-lock.sh"
33-
},
3430
{
3531
"type": "shell",
3632
"scripts": [

scripts/packer/oci-image.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@
2626
"type": "shell",
2727
"inline": ["cloud-init status --long --wait"]
2828
},
29-
{
30-
"type": "shell",
31-
"script": "provisioners/wait-for-dpkg-lock.sh"
32-
},
3329
{
3430
"type": "shell",
3531
"scripts": [

scripts/packer/provisioners/kernel/apt-upgrade.sh

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,39 @@
55

66
set -e
77

8-
sudo apt-get update
8+
#
9+
# Run apt-get update, but retry in case the lock is held by another process.
10+
#
11+
# A better way of handling apt races is the `-o DPkg::Lock::Timeout=X` option,
12+
# but it does not work with `apt-get update`.
13+
#
14+
# This function was added specifically for the `oci` backend, where our build
15+
# process conflicts with OCI's instance agent.
16+
#
17+
apt_update_with_retry() {
18+
local MAX_RETRIES=10
19+
local RETRY_DELAY=3
20+
local COUNT=0
21+
local LOGFILE=$(mktemp)
22+
23+
while [ $COUNT -lt $MAX_RETRIES ]; do
24+
set +e
25+
sudo apt-get update 2>&1 | tee "$LOGFILE"
26+
local EXIT_CODE=${PIPESTATUS[0]}
27+
set -e
28+
29+
if grep -q "Could not get lock" "$LOGFILE"; then
30+
echo "apt lock file is held by another process. Retrying in $RETRY_DELAY seconds..."
31+
COUNT=$((COUNT + 1))
32+
sleep $RETRY_DELAY
33+
else
34+
return $EXIT_CODE
35+
fi
36+
done
37+
38+
echo "apt-get update failed due to lock being held after $MAX_RETRIES attempts."
39+
return 1
40+
}
41+
42+
apt_update_with_retry
943
sudo DEBIAN_FRONTEND=noninteractive apt-get -o DPkg::Lock::Timeout=60 dist-upgrade -y -q

scripts/packer/provisioners/wait-for-dpkg-lock.sh

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)