Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8a59178

Browse files
authored
provisionersdk: extract and embed agent bootstrap scripts (#2886)
This commit extracts the existing hard-coded agent scripts to their own files and embeds them using go:embed.We can more easily use e.g. shellcheck to validate our agent scripts.
1 parent8d8c1a1 commit8a59178

File tree

4 files changed

+48
-41
lines changed

4 files changed

+48
-41
lines changed

‎provisionersdk/agent.go

Lines changed: 9 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,20 @@
11
package provisionersdk
22

33
import (
4+
_"embed"
45
"fmt"
56
"strings"
67
)
78

89
var (
9-
// On Windows, VS Code Remote requires a parent process of the
10-
// executing shell to be named "sshd", otherwise it fails. See:
11-
// https://github.com/microsoft/vscode-remote-release/issues/5699
12-
windowsScript=`$ProgressPreference = "SilentlyContinue"
13-
Invoke-WebRequest -Uri ${ACCESS_URL}bin/coder-windows-${ARCH}.exe -OutFile $env:TEMP\sshd.exe
14-
Set-MpPreference -DisableRealtimeMonitoring $true -ExclusionPath $env:TEMP\sshd.exe
15-
$env:CODER_AGENT_AUTH = "${AUTH_TYPE}"
16-
$env:CODER_AGENT_URL = "${ACCESS_URL}"
17-
Start-Process -FilePath $env:TEMP\sshd.exe -ArgumentList "agent" -PassThru`
18-
19-
linuxScript=`#!/usr/bin/env sh
20-
set -eux pipefail
21-
BINARY_DIR=$(mktemp -d -t coder.XXXXXX)
22-
BINARY_NAME=coder
23-
BINARY_URL=${ACCESS_URL}bin/coder-linux-${ARCH}
24-
cd $BINARY_DIR
25-
if command -v curl >/dev/null 2>&1; then
26-
curl -fsSL --compressed "${BINARY_URL}" -o "${BINARY_NAME}"
27-
elif command -v wget >/dev/null 2>&1; then
28-
wget -q "${BINARY_URL}" -O "${BINARY_NAME}"
29-
elif command -v busybox >/dev/null 2>&1; then
30-
busybox wget -q "${BINARY_URL}" -O "${BINARY_NAME}"
31-
else
32-
echo "error: no download tool found, please install curl, wget or busybox wget"
33-
exit 1
34-
fi
35-
chmod +x $BINARY_NAME
36-
export CODER_AGENT_AUTH="${AUTH_TYPE}"
37-
export CODER_AGENT_URL="${ACCESS_URL}"
38-
exec ./$BINARY_NAME agent`
39-
40-
darwinScript=`#!/usr/bin/env sh
41-
set -eux pipefail
42-
BINARY_DIR=$(mktemp -d -t coder.XXXXXX)
43-
BINARY_NAME=coder
44-
cd $BINARY_DIR
45-
curl -fsSL --compressed "${ACCESS_URL}bin/coder-darwin-${ARCH}" -o "${BINARY_NAME}"
46-
chmod +x $BINARY_NAME
47-
export CODER_AGENT_AUTH="${AUTH_TYPE}"
48-
export CODER_AGENT_URL="${ACCESS_URL}"
49-
exec ./$BINARY_NAME agent`
10+
// These used to be hard-coded, but after growing significantly more complex
11+
// it made sense to put them in their own files (e.g. for linting).
12+
//go:embed scripts/bootstrap_windows.ps1
13+
windowsScriptstring
14+
//go:embed scripts/bootstrap_linux.sh
15+
linuxScriptstring
16+
//go:embed scripts/bootstrap_darwin.sh
17+
darwinScriptstring
5018

5119
// A mapping of operating-system ($GOOS) to architecture ($GOARCH)
5220
// to agent install and run script. ${DOWNLOAD_URL} is replaced
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env sh
2+
set -eux pipefail
3+
BINARY_DIR=$(mktemp -d -t coder.XXXXXX)
4+
BINARY_NAME=coder
5+
cd"$BINARY_DIR"
6+
curl -fsSL --compressed"${ACCESS_URL}bin/coder-darwin-${ARCH}" -o"${BINARY_NAME}"
7+
chmod +x$BINARY_NAME
8+
export CODER_AGENT_AUTH="${AUTH_TYPE}"
9+
export CODER_AGENT_URL="${ACCESS_URL}"
10+
exec ./$BINARY_NAME agent
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env sh
2+
set -eux pipefail
3+
BINARY_DIR=$(mktemp -d -t coder.XXXXXX)
4+
BINARY_NAME=coder
5+
BINARY_URL=${ACCESS_URL}bin/coder-linux-${ARCH}
6+
cd"$BINARY_DIR"
7+
ifcommand -v curl>/dev/null2>&1;then
8+
curl -fsSL --compressed"${BINARY_URL}" -o"${BINARY_NAME}"
9+
elifcommand -v wget>/dev/null2>&1;then
10+
wget -q"${BINARY_URL}" -O"${BINARY_NAME}"
11+
elifcommand -v busybox>/dev/null2>&1;then
12+
busybox wget -q"${BINARY_URL}" -O"${BINARY_NAME}"
13+
else
14+
echo"error: no download tool found, please install curl, wget or busybox wget"
15+
exit 1
16+
fi
17+
chmod +x$BINARY_NAME
18+
export CODER_AGENT_AUTH="${AUTH_TYPE}"
19+
export CODER_AGENT_URL="${ACCESS_URL}"
20+
exec ./$BINARY_NAME agent
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# On Windows, VS Code Remote requires a parent process of the
2+
# executing shell to be named "sshd", otherwise it fails. See:
3+
# https://github.com/microsoft/vscode-remote-release/issues/5699
4+
$ProgressPreference="SilentlyContinue"
5+
Invoke-WebRequest-Uri${ACCESS_URL}bin/coder-windows-${ARCH}.exe-OutFile$env:TEMP\sshd.exe
6+
Set-MpPreference-DisableRealtimeMonitoring$true-ExclusionPath$env:TEMP\sshd.exe
7+
$env:CODER_AGENT_AUTH="${AUTH_TYPE}"
8+
$env:CODER_AGENT_URL="${ACCESS_URL}"
9+
Start-Process-FilePath$env:TEMP\sshd.exe-ArgumentList"agent"-PassThru

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp