Skip to content

Commit 3a530b2

Browse files
authored
Add retry for downloading install_script_agent (#7310)
1 parent 9fdc902 commit 3a530b2

5 files changed

Lines changed: 39 additions & 5 deletions

File tree

utils/build/ssi/base/base_ssi.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ FROM ${BASE_IMAGE}
44

55
WORKDIR /workdir
66

7-
COPY ./base/install_script_ssi.sh ./base/binaries/* ./
7+
COPY ./base/install_script_ssi.sh ./base/download_with_retry.sh ./base/binaries/* ./
88

99
ARG DD_API_KEY=deadbeef
1010

utils/build/ssi/base/base_ssi_installer.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ FROM ${BASE_IMAGE}
44

55
WORKDIR /workdir
66

7-
COPY ./base/install_script_ssi_installer.sh ./
7+
COPY ./base/install_script_ssi_installer.sh ./base/download_with_retry.sh ./
88

99
ARG DD_API_KEY=deadbeef
1010

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
download_with_retry() {
4+
local url="$1"
5+
local output
6+
output="$(basename "$url")"
7+
8+
local max_attempts=5
9+
local attempt
10+
for (( attempt = 1; attempt <= max_attempts; attempt++ )); do
11+
echo "[TRACE] downloading ${output} (attempt ${attempt}/${max_attempts})"
12+
if curl --fail --retry 3 -sSL -o "$output" "$url" && [ -s "$output" ]; then
13+
return 0
14+
fi
15+
rm -f "$output"
16+
done
17+
18+
echo "[ERROR] ${output} is missing or empty after ${max_attempts} attempts" >&2
19+
return 1
20+
}

utils/build/ssi/base/install_script_ssi.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,22 @@ if [ -n "${DD_INSTALLER_INJECTOR_VERSION}" ]; then
4040
export DD_INSTALLER_DEFAULT_PKG_VERSION_DATADOG_APM_INJECT="${DD_INSTALLER_INJECTOR_VERSION}"
4141
fi
4242

43+
# shellcheck source=utils/build/ssi/base/download_with_retry.sh
44+
source ./download_with_retry.sh
45+
4346
if [ -f "install_script_agent7.sh" ]; then
4447
echo "[TRACE] install_script_agent7.sh exists"
45-
DD_REPO_URL=${DD_injection_repo_url} DD_INSTALL_ONLY=true DD_APM_INSTRUMENTATION_ENABLED=host bash -c "$(cat install_script_agent7.sh)"
4648
else
47-
DD_REPO_URL=${DD_injection_repo_url} DD_INSTALL_ONLY=true DD_APM_INSTRUMENTATION_ENABLED=host bash -c "$(curl -L https://dd-agent.s3.amazonaws.com/scripts/install_script_agent7.sh)"
49+
download_with_retry https://dd-agent.s3.amazonaws.com/scripts/install_script_agent7.sh
50+
fi
51+
52+
if [ ! -s "install_script_agent7.sh" ]; then
53+
echo "[ERROR] install_script_agent7.sh is missing or empty; aborting SSI install" >&2
54+
exit 1
4855
fi
4956

57+
DD_REPO_URL=${DD_injection_repo_url} DD_INSTALL_ONLY=true DD_APM_INSTRUMENTATION_ENABLED=host bash ./install_script_agent7.sh
58+
5059
if [ -f /etc/debian_version ] || [ "$DISTRIBUTION" == "Debian" ] || [ "$DISTRIBUTION" == "Ubuntu" ]; then
5160
OS="Debian"
5261
elif [ -f /etc/redhat-release ] || [ "$DISTRIBUTION" == "RedHat" ] || [ "$DISTRIBUTION" == "CentOS" ] || [ "$DISTRIBUTION" == "Amazon" ] || [ "$DISTRIBUTION" == "Rocky" ] || [ "$DISTRIBUTION" == "AlmaLinux" ]; then
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
#!/bin/bash
22

3-
DD_INSTALL_ONLY=true DD_INSTALLER=true bash -c "$(curl -L https://dd-agent.s3.amazonaws.com/scripts/install_script_agent7.sh)"
3+
# shellcheck source=utils/build/ssi/base/download_with_retry.sh
4+
source ./download_with_retry.sh
5+
6+
download_with_retry https://dd-agent.s3.amazonaws.com/scripts/install_script_agent7.sh || exit 1
7+
8+
DD_INSTALL_ONLY=true DD_INSTALLER=true bash ./install_script_agent7.sh

0 commit comments

Comments
 (0)