mirror of https://github.com/coder/coder.git
feat(coderd): allow customizing provisioner daemon binary path via env
This commit is contained in:
parent
2afaeb0f71
commit
d43a57f4ee
|
@ -1353,6 +1353,12 @@ func newProvisionerDaemon(
|
|||
return nil, xerrors.Errorf("mkdir terraform dir: %w", err)
|
||||
}
|
||||
|
||||
if cfg.Provisioner.BinaryPath != "" {
|
||||
if _, err := os.Stat(cfg.Provisioner.BinaryPath.Value()); errors.Is(err, os.ErrNotExist) {
|
||||
return nil, xerrors.Errorf("stat provisioner binary path: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
tracer := coderAPI.TracerProvider.Tracer(tracing.TracerName)
|
||||
terraformClient, terraformServer := drpc.MemTransportPipe()
|
||||
wg.Add(1)
|
||||
|
@ -1368,6 +1374,7 @@ func newProvisionerDaemon(
|
|||
defer cancel()
|
||||
|
||||
err := terraform.Serve(ctx, &terraform.ServeOptions{
|
||||
BinaryPath: cfg.Provisioner.BinaryPath.String(),
|
||||
ServeOptions: &provisionersdk.ServeOptions{
|
||||
Listener: terraformServer,
|
||||
Logger: logger.Named("terraform"),
|
||||
|
|
|
@ -1487,6 +1487,26 @@ func TestServer(t *testing.T) {
|
|||
})
|
||||
})
|
||||
|
||||
t.Run("Provisioners", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
t.Run("CustomBinaryNotFound", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
inv, _ := clitest.New(t,
|
||||
"server",
|
||||
"--in-memory",
|
||||
"--http-address", ":0",
|
||||
"--access-url", "http://example.com",
|
||||
"--provisioner-daemons", "1",
|
||||
"--provisioner-daemon-binary-path", "/this/path/will/never/exist",
|
||||
)
|
||||
waiter := clitest.StartWithWaiter(t, inv)
|
||||
waiter.Cancel()
|
||||
waiter.RequireIs(os.ErrNotExist)
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("YAML", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
|
|
@ -443,6 +443,11 @@ updating, and deleting workspace resources.
|
|||
--provisioner-daemon-poll-jitter duration, $CODER_PROVISIONER_DAEMON_POLL_JITTER (default: 100ms)
|
||||
Deprecated and ignored.
|
||||
|
||||
--provisioner-daemon-binary-path string, $CODER_PROVISIONER_DAEMON_BINARY_PATH
|
||||
Override the binary used by the provisioner. This can allow, for
|
||||
example, overriding the Terraform version in use. If unset, the first
|
||||
available match in path will be used.
|
||||
|
||||
--provisioner-daemon-psk string, $CODER_PROVISIONER_DAEMON_PSK
|
||||
Pre-shared key to authenticate external provisioner daemons to Coder
|
||||
server.
|
||||
|
|
|
@ -386,6 +386,11 @@ provisioning:
|
|||
# Pre-shared key to authenticate external provisioner daemons to Coder server.
|
||||
# (default: <unset>, type: string)
|
||||
daemonPSK: ""
|
||||
# Override the binary used by the provisioner. This can allow, for example,
|
||||
# overriding the Terraform version in use. If unset, the first available match in
|
||||
# path will be used.
|
||||
# (default: <unset>, type: string)
|
||||
binaryPath: ""
|
||||
# Enable one or more experiments. These are not ready for production. Separate
|
||||
# multiple experiments with commas, or enter '*' to opt-in to all available
|
||||
# experiments.
|
||||
|
|
|
@ -10260,6 +10260,10 @@ const docTemplate = `{
|
|||
"codersdk.ProvisionerConfig": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"binary_path": {
|
||||
"description": "BinaryPath is the absolute path to the provisioner binary to use.\nThis may be interpreted differently depending on the provisioner type.",
|
||||
"type": "string"
|
||||
},
|
||||
"daemon_poll_interval": {
|
||||
"type": "integer"
|
||||
},
|
||||
|
|
|
@ -9228,6 +9228,10 @@
|
|||
"codersdk.ProvisionerConfig": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"binary_path": {
|
||||
"description": "BinaryPath is the absolute path to the provisioner binary to use.\nThis may be interpreted differently depending on the provisioner type.",
|
||||
"type": "string"
|
||||
},
|
||||
"daemon_poll_interval": {
|
||||
"type": "integer"
|
||||
},
|
||||
|
|
|
@ -372,6 +372,9 @@ type ProvisionerConfig struct {
|
|||
DaemonPollJitter clibase.Duration `json:"daemon_poll_jitter" typescript:",notnull"`
|
||||
ForceCancelInterval clibase.Duration `json:"force_cancel_interval" typescript:",notnull"`
|
||||
DaemonPSK clibase.String `json:"daemon_psk" typescript:",notnull"`
|
||||
// BinaryPath is the absolute path to the provisioner binary to use.
|
||||
// This may be interpreted differently depending on the provisioner type.
|
||||
BinaryPath clibase.String `json:"binary_path" typescript:",notnull"`
|
||||
}
|
||||
|
||||
type RateLimitConfig struct {
|
||||
|
@ -1408,6 +1411,15 @@ when required by your organization's security policy.`,
|
|||
Group: &deploymentGroupProvisioning,
|
||||
YAML: "daemonPSK",
|
||||
},
|
||||
{
|
||||
Name: "Provisioner Daemon Binary Path",
|
||||
Description: "Override the binary used by the provisioner. This can allow, for example, overriding the Terraform version in use. If unset, the first available match in path will be used.",
|
||||
Flag: "provisioner-daemon-binary-path",
|
||||
Env: "CODER_PROVISIONER_DAEMON_BINARY_PATH",
|
||||
Value: &c.Provisioner.BinaryPath,
|
||||
Group: &deploymentGroupProvisioning,
|
||||
YAML: "binaryPath",
|
||||
},
|
||||
// RateLimit settings
|
||||
{
|
||||
Name: "Disable All Rate Limits",
|
||||
|
|
|
@ -322,6 +322,7 @@ curl -X GET http://coder-server:8080/api/v2/deployment/config \
|
|||
"enable": true
|
||||
},
|
||||
"provisioner": {
|
||||
"binary_path": "string",
|
||||
"daemon_poll_interval": 0,
|
||||
"daemon_poll_jitter": 0,
|
||||
"daemon_psk": "string",
|
||||
|
|
|
@ -2297,6 +2297,7 @@ AuthorizationObject can represent a "set" of objects, such as: all workspaces in
|
|||
"enable": true
|
||||
},
|
||||
"provisioner": {
|
||||
"binary_path": "string",
|
||||
"daemon_poll_interval": 0,
|
||||
"daemon_poll_jitter": 0,
|
||||
"daemon_psk": "string",
|
||||
|
@ -2665,6 +2666,7 @@ AuthorizationObject can represent a "set" of objects, such as: all workspaces in
|
|||
"enable": true
|
||||
},
|
||||
"provisioner": {
|
||||
"binary_path": "string",
|
||||
"daemon_poll_interval": 0,
|
||||
"daemon_poll_jitter": 0,
|
||||
"daemon_psk": "string",
|
||||
|
@ -3959,6 +3961,7 @@ AuthorizationObject can represent a "set" of objects, such as: all workspaces in
|
|||
|
||||
```json
|
||||
{
|
||||
"binary_path": "string",
|
||||
"daemon_poll_interval": 0,
|
||||
"daemon_poll_jitter": 0,
|
||||
"daemon_psk": "string",
|
||||
|
@ -3970,14 +3973,15 @@ AuthorizationObject can represent a "set" of objects, such as: all workspaces in
|
|||
|
||||
### Properties
|
||||
|
||||
| Name | Type | Required | Restrictions | Description |
|
||||
| ----------------------- | ------- | -------- | ------------ | ----------- |
|
||||
| `daemon_poll_interval` | integer | false | | |
|
||||
| `daemon_poll_jitter` | integer | false | | |
|
||||
| `daemon_psk` | string | false | | |
|
||||
| `daemons` | integer | false | | |
|
||||
| `daemons_echo` | boolean | false | | |
|
||||
| `force_cancel_interval` | integer | false | | |
|
||||
| Name | Type | Required | Restrictions | Description |
|
||||
| ----------------------- | ------- | -------- | ------------ | ----------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `binary_path` | string | false | | Binary path is the absolute path to the provisioner binary to use. This may be interpreted differently depending on the provisioner type. |
|
||||
| `daemon_poll_interval` | integer | false | | |
|
||||
| `daemon_poll_jitter` | integer | false | | |
|
||||
| `daemon_psk` | string | false | | |
|
||||
| `daemons` | integer | false | | |
|
||||
| `daemons_echo` | boolean | false | | |
|
||||
| `force_cancel_interval` | integer | false | | |
|
||||
|
||||
## codersdk.ProvisionerDaemon
|
||||
|
||||
|
|
|
@ -88,6 +88,15 @@ Deprecated and ignored.
|
|||
|
||||
Deprecated and ignored.
|
||||
|
||||
### --provisioner-daemon-binary-path
|
||||
|
||||
| | |
|
||||
| ----------- | -------------------------------------------------- |
|
||||
| Type | <code>string</code> |
|
||||
| Environment | <code>$CODER_PROVISIONER_DAEMON_BINARY_PATH</code> |
|
||||
|
||||
Override the binary used by the provisioner. This can allow, for example, overriding the Terraform version in use. If unset, the first available match in path will be used.
|
||||
|
||||
### --psk
|
||||
|
||||
| | |
|
||||
|
|
|
@ -773,6 +773,16 @@ Collect database metrics (may increase charges for metrics storage).
|
|||
|
||||
Serve prometheus metrics on the address defined by prometheus address.
|
||||
|
||||
### --provisioner-daemon-binary-path
|
||||
|
||||
| | |
|
||||
| ----------- | -------------------------------------------------- |
|
||||
| Type | <code>string</code> |
|
||||
| Environment | <code>$CODER_PROVISIONER_DAEMON_BINARY_PATH</code> |
|
||||
| YAML | <code>provisioning.binaryPath</code> |
|
||||
|
||||
Override the binary used by the provisioner. This can allow, for example, overriding the Terraform version in use. If unset, the first available match in path will be used.
|
||||
|
||||
### --provisioner-daemon-psk
|
||||
|
||||
| | |
|
||||
|
|
|
@ -56,6 +56,7 @@ func validateProvisionerDaemonName(name string) error {
|
|||
|
||||
func (r *RootCmd) provisionerDaemonStart() *clibase.Cmd {
|
||||
var (
|
||||
binaryPath string
|
||||
cacheDir string
|
||||
logHuman string
|
||||
logJSON string
|
||||
|
@ -82,6 +83,12 @@ func (r *RootCmd) provisionerDaemonStart() *clibase.Cmd {
|
|||
ctx, cancel := context.WithCancel(inv.Context())
|
||||
defer cancel()
|
||||
|
||||
if binaryPath != "" {
|
||||
if _, err := os.Stat(binaryPath); xerrors.Is(err, os.ErrNotExist) {
|
||||
return xerrors.Errorf("stat provisioner binary path: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
notifyCtx, notifyStop := inv.SignalNotifyContext(ctx, agpl.InterruptSignals...)
|
||||
defer notifyStop()
|
||||
|
||||
|
@ -151,6 +158,7 @@ func (r *RootCmd) provisionerDaemonStart() *clibase.Cmd {
|
|||
defer cancel()
|
||||
|
||||
err := terraform.Serve(ctx, &terraform.ServeOptions{
|
||||
BinaryPath: binaryPath,
|
||||
ServeOptions: &provisionersdk.ServeOptions{
|
||||
Listener: terraformServer,
|
||||
Logger: logger.Named("terraform"),
|
||||
|
@ -292,6 +300,13 @@ func (r *RootCmd) provisionerDaemonStart() *clibase.Cmd {
|
|||
Value: clibase.StringArrayOf(&logFilter),
|
||||
Default: "",
|
||||
},
|
||||
{
|
||||
Flag: "provisioner-daemon-binary-path",
|
||||
Env: "CODER_PROVISIONER_DAEMON_BINARY_PATH",
|
||||
Description: "Override the binary used by the provisioner. This can allow, for example, overriding the Terraform version in use. If unset, the first available match in path will be used.",
|
||||
Value: clibase.StringOf(&binaryPath),
|
||||
Default: "",
|
||||
},
|
||||
}
|
||||
|
||||
return cmd
|
||||
|
|
|
@ -2,6 +2,7 @@ package cli_test
|
|||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -161,3 +162,20 @@ func TestProvisionerDaemon_SessionToken(t *testing.T) {
|
|||
assert.Equal(t, provisionersdk.VersionCurrent.String(), daemons[0].APIVersion)
|
||||
})
|
||||
}
|
||||
|
||||
func TestProvisionerDaemon_CustomBinary(t *testing.T) {
|
||||
t.Parallel()
|
||||
client, _ := coderdenttest.New(t, &coderdenttest.Options{
|
||||
ProvisionerDaemonPSK: "provisionersftw",
|
||||
LicenseOptions: &coderdenttest.LicenseOptions{
|
||||
Features: license.Features{
|
||||
codersdk.FeatureExternalProvisionerDaemons: 1,
|
||||
},
|
||||
},
|
||||
})
|
||||
inv, conf := newCLI(t, "provisionerd", "start", "--psk=provisionersftw", "--provisioner-daemon-binary-path=/this/will/never/exist")
|
||||
err := conf.URL().Write(client.URL.String())
|
||||
require.NoError(t, err)
|
||||
waiter := clitest.StartWithWaiter(t, inv)
|
||||
waiter.RequireIs(os.ErrNotExist)
|
||||
}
|
||||
|
|
|
@ -32,6 +32,11 @@ OPTIONS:
|
|||
--poll-jitter duration, $CODER_PROVISIONERD_POLL_JITTER (default: 100ms)
|
||||
Deprecated and ignored.
|
||||
|
||||
--provisioner-daemon-binary-path string, $CODER_PROVISIONER_DAEMON_BINARY_PATH
|
||||
Override the binary used by the provisioner. This can allow, for
|
||||
example, overriding the Terraform version in use. If unset, the first
|
||||
available match in path will be used.
|
||||
|
||||
--psk string, $CODER_PROVISIONER_DAEMON_PSK
|
||||
Pre-shared key to authenticate with Coder server.
|
||||
|
||||
|
|
|
@ -444,6 +444,11 @@ updating, and deleting workspace resources.
|
|||
--provisioner-daemon-poll-jitter duration, $CODER_PROVISIONER_DAEMON_POLL_JITTER (default: 100ms)
|
||||
Deprecated and ignored.
|
||||
|
||||
--provisioner-daemon-binary-path string, $CODER_PROVISIONER_DAEMON_BINARY_PATH
|
||||
Override the binary used by the provisioner. This can allow, for
|
||||
example, overriding the Terraform version in use. If unset, the first
|
||||
available match in path will be used.
|
||||
|
||||
--provisioner-daemon-psk string, $CODER_PROVISIONER_DAEMON_PSK
|
||||
Pre-shared key to authenticate external provisioner daemons to Coder
|
||||
server.
|
||||
|
|
|
@ -833,6 +833,7 @@ export interface ProvisionerConfig {
|
|||
readonly daemon_poll_jitter: number;
|
||||
readonly force_cancel_interval: number;
|
||||
readonly daemon_psk: string;
|
||||
readonly binary_path: string;
|
||||
}
|
||||
|
||||
// From codersdk/provisionerdaemons.go
|
||||
|
|
Loading…
Reference in New Issue