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

Skip to content

feat: arm(v7/64) builds for releases and agent scripts #1337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,18 @@ builds:
["-s -w -X github.com/coder/coder/buildinfo.tag={{ .Version }}"]
env: [CGO_ENABLED=0]
goos: [darwin, linux, windows]
goarch: [amd64]
goarch: [amd64, arm, arm64]
goarm: ["7"]
# Only build arm 7 for Linux
ignore:
- goos: windows
goarm: '7'
- goos: darwin
goarm: '7'
hooks:
# The "trimprefix" appends ".exe" on Windows.
post: |
cp {{.Path}} site/out/bin/coder-{{ .Os }}-{{ .Arch }}{{ trimprefix .Name "coder" }}
cp {{.Path}} site/out/bin/coder-{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ trimprefix .Name "coder" }}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


- id: coder-linux
dir: cmd/coder
Expand All @@ -45,7 +52,8 @@ builds:
["-s -w -X github.com/coder/coder/buildinfo.tag={{ .Version }}"]
env: [CGO_ENABLED=0]
goos: [linux]
goarch: [amd64, arm64]
goarch: [amd64, arm, arm64]
goarm: ["7"]

- id: coder-windows
dir: cmd/coder
Expand Down
59 changes: 37 additions & 22 deletions provisionersdk/agent.go
Original file line number Diff line number Diff line change
@@ -1,42 +1,56 @@
package provisionersdk

import "fmt"
import (
"fmt"
"strings"
)

var (
// A mapping of operating-system ($GOOS) to architecture ($GOARCH)
// to agent install and run script. ${DOWNLOAD_URL} is replaced
// with strings.ReplaceAll() when being consumed.
agentScripts = map[string]map[string]string{
// On Windows, VS Code Remote requires a parent process of the
// executing shell to be named "sshd", otherwise it fails. See:
// https://github.com/microsoft/vscode-remote-release/issues/5699
"windows": {
"amd64": `$ProgressPreference = "SilentlyContinue"
Invoke-WebRequest -Uri ${ACCESS_URL}bin/coder-windows-amd64.exe -OutFile $env:TEMP\sshd.exe
// On Windows, VS Code Remote requires a parent process of the
// executing shell to be named "sshd", otherwise it fails. See:
// https://github.com/microsoft/vscode-remote-release/issues/5699
windowsScript = `$ProgressPreference = "SilentlyContinue"
Invoke-WebRequest -Uri ${ACCESS_URL}bin/coder-windows-${ARCH}.exe -OutFile $env:TEMP\sshd.exe
Set-MpPreference -DisableRealtimeMonitoring $true -ExclusionPath $env:TEMP\sshd.exe
$env:CODER_AGENT_AUTH = "${AUTH_TYPE}"
$env:CODER_AGENT_URL = "${ACCESS_URL}"
Start-Process -FilePath $env:TEMP\sshd.exe -ArgumentList "agent" -PassThru`,
},
"linux": {
"amd64": `#!/usr/bin/env sh
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-amd64 -o $BINARY_LOCATION
curl -fsSL ${ACCESS_URL}bin/coder-linux-${ARCH} -o $BINARY_LOCATION
chmod +x $BINARY_LOCATION
export CODER_AGENT_AUTH="${AUTH_TYPE}"
export CODER_AGENT_URL="${ACCESS_URL}"
exec $BINARY_LOCATION agent`,
},
"darwin": {
"amd64": `#!/usr/bin/env sh
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-amd64 -o $BINARY_LOCATION
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}"
exec $BINARY_LOCATION agent`,
exec $BINARY_LOCATION agent`

// A mapping of operating-system ($GOOS) to architecture ($GOARCH)
// to agent install and run script. ${DOWNLOAD_URL} is replaced
// with strings.ReplaceAll() when being consumed. ${ARCH} is replaced
// with the architecture when being provided.
agentScripts = map[string]map[string]string{
"windows": {
"amd64": windowsScript,
"arm64": windowsScript,
},
"linux": {
"amd64": linuxScript,
"arm64": linuxScript,
"armv7": linuxScript,
},
"darwin": {
"amd64": darwinScript,
"arm64": darwinScript,
},
}
)
Expand All @@ -48,6 +62,7 @@ func AgentScriptEnv() map[string]string {
env := map[string]string{}
for operatingSystem, scripts := range agentScripts {
for architecture, script := range scripts {
script := strings.ReplaceAll(script, "${ARCH}", architecture)
env[fmt.Sprintf("CODER_AGENT_SCRIPT_%s_%s", operatingSystem, architecture)] = script
}
}
Expand Down