mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: More robust provisionersdk agent init scripts (#1551)
Related #1544 Co-authored-by: Dean Sheather <dean@deansheather.com>
This commit is contained in:
co-authored by
Dean Sheather
parent
6f969214d3
commit
ad9bdb7bd1
+16
-6
@@ -17,18 +17,28 @@ $env:CODER_AGENT_URL = "${ACCESS_URL}"
|
||||
Start-Process -FilePath $env:TEMP\sshd.exe -ArgumentList "agent" -PassThru`
|
||||
|
||||
linuxScript = `#!/usr/bin/env sh
|
||||
set -eu pipefail
|
||||
export BINARY_LOCATION=$(mktemp -d -t tmp.coderXXXXX)/coder
|
||||
curl -fsSL ${ACCESS_URL}bin/coder-linux-${ARCH} -o $BINARY_LOCATION
|
||||
set -eux pipefail
|
||||
BINARY_LOCATION=$(mktemp -d -t tmp.coderXXXXXX)/coder
|
||||
BINARY_URL=${ACCESS_URL}bin/coder-linux-${ARCH}
|
||||
if which curl >/dev/null 2>&1; then
|
||||
curl -fsSL "${BINARY_URL}" -o "${BINARY_LOCATION}"
|
||||
elif which wget >/dev/null 2>&1; then
|
||||
wget -q "${BINARY_URL}" -O "${BINARY_LOCATION}"
|
||||
elif which busybox >/dev/null 2>&1; then
|
||||
busybox wget -q "${BINARY_URL}" -O "${BINARY_LOCATION}"
|
||||
else
|
||||
echo "error: no download tool found, please install curl, wget or busybox wget"
|
||||
exit 1
|
||||
fi
|
||||
chmod +x $BINARY_LOCATION
|
||||
export CODER_AGENT_AUTH="${AUTH_TYPE}"
|
||||
export CODER_AGENT_URL="${ACCESS_URL}"
|
||||
exec $BINARY_LOCATION agent`
|
||||
|
||||
darwinScript = `#!/usr/bin/env sh
|
||||
set -eu pipefail
|
||||
export BINARY_LOCATION=$(mktemp -d -t tmp.coderXXXXX)/coder
|
||||
curl -fsSL ${ACCESS_URL}bin/coder-darwin-${ARCH} -o $BINARY_LOCATION
|
||||
set -eux pipefail
|
||||
BINARY_LOCATION=$(mktemp -d -t tmp.coderXXXXXX)/coder
|
||||
curl -fsSL "${ACCESS_URL}bin/coder-darwin-${ARCH}" -o "${BINARY_LOCATION}"
|
||||
chmod +x $BINARY_LOCATION
|
||||
export CODER_AGENT_AUTH="${AUTH_TYPE}"
|
||||
export CODER_AGENT_URL="${ACCESS_URL}"
|
||||
|
||||
@@ -49,8 +49,11 @@ func TestAgentScript(t *testing.T) {
|
||||
output, err := exec.Command("sh", "-c", script).CombinedOutput()
|
||||
t.Log(string(output))
|
||||
require.NoError(t, err)
|
||||
// Ignore debug output from `set -x`, we're only interested in the last line.
|
||||
lines := strings.Split(strings.TrimSpace(string(output)), "\n")
|
||||
lastLine := lines[len(lines)-1]
|
||||
// Because we use the "echo" binary, we should expect the arguments provided
|
||||
// as the response to executing our script.
|
||||
require.Equal(t, "agent", strings.TrimSpace(string(output)))
|
||||
require.Equal(t, "agent", lastLine)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user