Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ad9bdb7

Browse files
fix: More robust provisionersdk agent init scripts (#1551)
Related #1544 Co-authored-by: Dean Sheather <[email protected]>
1 parent 6f96921 commit ad9bdb7

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

provisionersdk/agent.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,28 @@ $env:CODER_AGENT_URL = "${ACCESS_URL}"
1717
Start-Process -FilePath $env:TEMP\sshd.exe -ArgumentList "agent" -PassThru`
1818

1919
linuxScript = `#!/usr/bin/env sh
20-
set -eu pipefail
21-
export BINARY_LOCATION=$(mktemp -d -t tmp.coderXXXXX)/coder
22-
curl -fsSL ${ACCESS_URL}bin/coder-linux-${ARCH} -o $BINARY_LOCATION
20+
set -eux pipefail
21+
BINARY_LOCATION=$(mktemp -d -t tmp.coderXXXXXX)/coder
22+
BINARY_URL=${ACCESS_URL}bin/coder-linux-${ARCH}
23+
if which curl >/dev/null 2>&1; then
24+
curl -fsSL "${BINARY_URL}" -o "${BINARY_LOCATION}"
25+
elif which wget >/dev/null 2>&1; then
26+
wget -q "${BINARY_URL}" -O "${BINARY_LOCATION}"
27+
elif which busybox >/dev/null 2>&1; then
28+
busybox wget -q "${BINARY_URL}" -O "${BINARY_LOCATION}"
29+
else
30+
echo "error: no download tool found, please install curl, wget or busybox wget"
31+
exit 1
32+
fi
2333
chmod +x $BINARY_LOCATION
2434
export CODER_AGENT_AUTH="${AUTH_TYPE}"
2535
export CODER_AGENT_URL="${ACCESS_URL}"
2636
exec $BINARY_LOCATION agent`
2737

2838
darwinScript = `#!/usr/bin/env sh
29-
set -eu pipefail
30-
export BINARY_LOCATION=$(mktemp -d -t tmp.coderXXXXX)/coder
31-
curl -fsSL ${ACCESS_URL}bin/coder-darwin-${ARCH} -o $BINARY_LOCATION
39+
set -eux pipefail
40+
BINARY_LOCATION=$(mktemp -d -t tmp.coderXXXXXX)/coder
41+
curl -fsSL "${ACCESS_URL}bin/coder-darwin-${ARCH}" -o "${BINARY_LOCATION}"
3242
chmod +x $BINARY_LOCATION
3343
export CODER_AGENT_AUTH="${AUTH_TYPE}"
3444
export CODER_AGENT_URL="${ACCESS_URL}"

provisionersdk/agent_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,11 @@ func TestAgentScript(t *testing.T) {
4949
output, err := exec.Command("sh", "-c", script).CombinedOutput()
5050
t.Log(string(output))
5151
require.NoError(t, err)
52+
// Ignore debug output from `set -x`, we're only interested in the last line.
53+
lines := strings.Split(strings.TrimSpace(string(output)), "\n")
54+
lastLine := lines[len(lines)-1]
5255
// Because we use the "echo" binary, we should expect the arguments provided
5356
// as the response to executing our script.
54-
require.Equal(t, "agent", strings.TrimSpace(string(output)))
57+
require.Equal(t, "agent", lastLine)
5558
})
5659
}

0 commit comments

Comments
 (0)