fix: More robust provisionersdk agent init scripts (#1551)

Related #1544

Co-authored-by: Dean Sheather <dean@deansheather.com>
This commit is contained in:
Mathias Fredriksson
2022-05-19 13:02:42 +00:00
committed by GitHub
co-authored by Dean Sheather
parent 6f969214d3
commit ad9bdb7bd1
2 changed files with 20 additions and 7 deletions
+16 -6
View File
@@ -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}"
+4 -1
View File
@@ -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)
})
}