Skip to content

Commit cd5cd2d

Browse files
committed
feat: provider name enhancements
- chore: typos and minor cleanup - feat: convey to the provider the name it is running under - feat: use `DEVPOD_PROVIDER_<provider name>_SOURCE` environment variable Signed-off-by: Leonid Dubinsky <dub@podval.org>
1 parent 0606504 commit cd5cd2d

16 files changed

Lines changed: 79 additions & 47 deletions

File tree

cmd/context/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func (cmd *CreateCmd) Run(ctx context.Context, context string) error {
5353

5454
// verify name
5555
if provider2.ProviderNameRegEx.MatchString(context) {
56-
return fmt.Errorf("context name can only include smaller case letters, numbers or dashes")
56+
return fmt.Errorf("context name can only include lower case letters, numbers or dashes")
5757
} else if len(context) > 48 {
5858
return fmt.Errorf("context name cannot be longer than 48 characters")
5959
}

cmd/provider/add.go

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package provider
33
import (
44
"context"
55
"fmt"
6+
"os"
67
"strings"
78

89
"github.com/sirupsen/logrus"
@@ -33,7 +34,7 @@ func NewAddCmd(f *flags.GlobalFlags) *cobra.Command {
3334
GlobalFlags: f,
3435
}
3536
addCmd := &cobra.Command{
36-
Use: "add [URL or path]",
37+
Use: "add [name, GitHub link, URL or path]",
3738
Short: "Adds a new provider to DevPod",
3839
PreRunE: func(cobraCommand *cobra.Command, args []string) error {
3940
if cmd.FromExisting != "" {
@@ -56,7 +57,7 @@ func NewAddCmd(f *flags.GlobalFlags) *cobra.Command {
5657
BoolVar(&cmd.SingleMachine, "single-machine", false, "If enabled will use a single machine for all workspaces")
5758
addCmd.Flags().
5859
StringVar(&cmd.Name, "name", "",
59-
"The name for the new provider. If not specified, the name from the provider's configuration file will be used.")
60+
"The name for the new provider. If not specified, the name from the provider's configuration file will be used")
6061
addCmd.Flags().
6162
StringVar(&cmd.FromExisting, "from-existing", "",
6263
"The name of an existing provider to use as a template. Needs to be used in conjunction with the --name flag")
@@ -69,23 +70,43 @@ func NewAddCmd(f *flags.GlobalFlags) *cobra.Command {
6970
}
7071

7172
func (cmd *AddCmd) Run(ctx context.Context, devPodConfig *config.Config, args []string) error {
72-
if len(args) != 1 && cmd.FromExisting == "" {
73-
return fmt.Errorf("please specify either a local file, URL or Git repository. " +
74-
"E.g. devpod provider add https://path/to/my/provider.yaml")
75-
} else if cmd.Name != "" && provider.ProviderNameRegEx.MatchString(cmd.Name) {
76-
return fmt.Errorf("provider name can only include smaller case letters, numbers or dashes")
77-
} else if cmd.Name != "" && len(cmd.Name) > 32 {
78-
return fmt.Errorf("provider name cannot be longer than 32 characters")
79-
} else if cmd.FromExisting != "" && devPodConfig.Current() != nil && devPodConfig.Current().Providers[cmd.FromExisting] == nil {
80-
return fmt.Errorf("provider %s does not exist", cmd.FromExisting)
73+
providerName := cmd.Name
74+
75+
if providerName != "" {
76+
if provider.ProviderNameRegEx.MatchString(providerName) {
77+
return fmt.Errorf(
78+
"provider name can only include lower case letters, numbers or dashes",
79+
)
80+
}
81+
if len(providerName) > 32 {
82+
return fmt.Errorf("provider name cannot be longer than 32 characters")
83+
}
84+
}
85+
86+
providerSource := ""
87+
if len(args) == 1 {
88+
providerSource = args[0]
89+
}
90+
if providerSource == "" {
91+
var sourceEnvVar string
92+
if providerName == "" {
93+
sourceEnvVar = "DEVPOD_PROVIDER_SOURCE"
94+
} else {
95+
sourceEnvVar = "DEVPOD_PROVIDER_" + strings.ToUpper(providerName) + "_SOURCE"
96+
}
97+
providerSource = os.Getenv(sourceEnvVar)
8198
}
8299

83100
var providerConfig *provider.ProviderConfig
84101
var options []string
85102
if cmd.FromExisting != "" {
103+
if devPodConfig.Current() != nil &&
104+
devPodConfig.Current().Providers[cmd.FromExisting] == nil {
105+
return fmt.Errorf("provider %s does not exist", cmd.FromExisting)
106+
}
86107
providerWithOptions, err := workspace.CloneProvider(
87108
devPodConfig,
88-
cmd.Name,
109+
providerName,
89110
cmd.FromExisting,
90111
log.Default,
91112
)
@@ -100,7 +121,11 @@ func (cmd *AddCmd) Run(ctx context.Context, devPodConfig *config.Config, args []
100121
cmd.Options,
101122
)
102123
} else {
103-
c, err := workspace.AddProvider(devPodConfig, cmd.Name, args[0], log.Default)
124+
if providerSource == "" {
125+
return fmt.Errorf("please specify either a name, GitHub link, URL or path, " +
126+
"e.g. devpod provider add https://path/to/my/provider.yaml")
127+
}
128+
c, err := workspace.AddProvider(devPodConfig, providerName, providerSource, log.Default)
104129
if err != nil {
105130
return err
106131
}

cmd/provider/delete.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@ func NewDeleteCmd(flags *flags.GlobalFlags) *cobra.Command {
5757
}
5858

5959
func (cmd *DeleteCmd) Run(ctx context.Context, args []string) error {
60-
if len(args) > 1 {
61-
return fmt.Errorf("please specify a provider to delete")
62-
}
63-
6460
devPodConfig, err := config.LoadConfig(cmd.Context, cmd.Provider)
6561
if err != nil {
6662
return err

cmd/provider/update.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func NewUpdateCmd(flags *flags.GlobalFlags) *cobra.Command {
2626
GlobalFlags: flags,
2727
}
2828
updateCmd := &cobra.Command{
29-
Use: "update [name] [URL or path]",
29+
Use: "update [name] [name, GitHub link, URL or path]",
3030
Short: "Updates a provider in DevPod",
3131
RunE: func(cobraCmd *cobra.Command, args []string) error {
3232
ctx := cobraCmd.Context()
@@ -48,8 +48,8 @@ func NewUpdateCmd(flags *flags.GlobalFlags) *cobra.Command {
4848

4949
func (cmd *UpdateCmd) Run(ctx context.Context, devPodConfig *config.Config, args []string) error {
5050
if len(args) != 1 && len(args) != 2 {
51-
return fmt.Errorf("please specify either a local file, URL or Git repository. " +
52-
"E.g. devpod provider update my-provider skevetter/devpod-provider-gcloud")
51+
return fmt.Errorf("please specify either a local file, URL or Git repository, " +
52+
"e.g. devpod provider update my-provider skevetter/devpod-provider-gcloud")
5353
}
5454

5555
providerSource := ""

cmd/up.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func (cmd *UpCmd) registerDotfilesFlags(upCmd *cobra.Command) {
157157
"The path in dotfiles directory to use to install the dotfiles, if empty will try to guess")
158158
upCmd.Flags().
159159
StringSliceVar(&cmd.DotfilesScriptEnv, "dotfiles-script-env", []string{},
160-
"Extra environment variables to put into the dotfiles install script. E.g. MY_ENV_VAR=MY_VALUE")
160+
"Extra environment variables to put into the dotfiles install script, e.g. MY_ENV_VAR=MY_VALUE")
161161
upCmd.Flags().
162162
StringSliceVar(&cmd.DotfilesScriptEnvFile, "dotfiles-script-env-file", []string{},
163163
"The path to files containing environment variables to set for the dotfiles install script")
@@ -226,7 +226,7 @@ func (cmd *UpCmd) registerWorkspaceFlags(upCmd *cobra.Command) {
226226
"The machine to use for this workspace. The machine needs to exist beforehand or the "+
227227
"command will fail. If the workspace already exists, this option has no effect")
228228
upCmd.Flags().
229-
StringVar(&cmd.Source, "source", "", "Optional source for the workspace. E.g. git:https://github.com/my-org/my-repo")
229+
StringVar(&cmd.Source, "source", "", "Optional source for the workspace, e.g. git:https://github.com/my-org/my-repo")
230230
upCmd.Flags().
231231
StringArrayVar(&cmd.ProviderOptions, "provider-option", []string{}, "Provider option in the form KEY=VALUE")
232232
upCmd.Flags().
@@ -242,14 +242,14 @@ func (cmd *UpCmd) registerWorkspaceFlags(upCmd *cobra.Command) {
242242
"Docker repository that hosts devpod prebuilds for this workspace")
243243
upCmd.Flags().
244244
StringArrayVar(&cmd.WorkspaceEnv, "workspace-env", []string{},
245-
"Extra env variables to put into the workspace. E.g. MY_ENV_VAR=MY_VALUE")
245+
"Extra env variables to put into the workspace, e.g. MY_ENV_VAR=MY_VALUE")
246246
upCmd.Flags().
247247
StringSliceVar(&cmd.WorkspaceEnvFile, "workspace-env-file", []string{},
248-
"The path to files containing a list of extra env variables to put into the workspace. "+
249-
"E.g. MY_ENV_VAR=MY_VALUE")
248+
"The path to files containing a list of extra env variables to put into the workspace, "+
249+
"e.g. MY_ENV_VAR=MY_VALUE")
250250
upCmd.Flags().
251251
StringArrayVar(&cmd.InitEnv, "init-env", []string{},
252-
"Extra env variables to inject during the initialization of the workspace. E.g. MY_ENV_VAR=MY_VALUE")
252+
"Extra env variables to inject during the initialization of the workspace, e.g. MY_ENV_VAR=MY_VALUE")
253253
upCmd.Flags().
254254
BoolVar(&cmd.DisableDaemon, "disable-daemon", false,
255255
"If enabled, will not install a daemon into the target machine to track activity")

docs/pages/developing-providers/options.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ configuring or adding the provider:
6767
- `command`: A command to retrieve the option value automatically. Can also reference other variables in the command, e.g. `echo ${MY_OTHER_VAR}-suffix`. For compatibility reasons, this command will be executed in an emulated shell on Windows.
6868
- `local`: If true, the option will be filled individually for each machine / workspace
6969
- `global`: If true, the option will be reused for each machine / workspace
70-
- `cache`: If non-empty, DevPod will re-execute the command after the given timeout. E.g. if this is 5m, DevPod will re-execute the command after 5 minutes to re-fill this value. This is useful if you want to store a token or something that expires locally in a variable.
70+
- `cache`: If non-empty, DevPod will re-execute the command after the given timeout, e.g. if this is 5m, DevPod will re-execute the command after 5 minutes to re-fill this value. This is useful if you want to store a token or something that expires locally in a variable.
7171
- `hidden`: If true, DevPod will not show this option in the Desktop application or through `devpod provider options`. Can be used to calculate variables internally or save tokens or other things internally.
7272

7373
### Default values

docs/pages/managing-providers/add-provider.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ AWS_AMI | false | The disk image to use. |
140140
AWS_DISK_SIZE | false | The disk size to use. | 40 | 40
141141
AWS_INSTANCE_TYPE | false | The machine type to use. | c5.xlarge | c5.xlarge
142142
AWS_REGION | true | The AWS cloud region to create | | us-west-2
143-
| | the VM in. E.g. us-west-1 | |
143+
| | the VM in, e.g. us-west-1 | |
144144
AWS_SECRET_ACCESS_KEY | false | The AWS secret access key | |
145145
AWS_VPC_ID | false | The vpc id to use. | |
146146
INACTIVITY_TIMEOUT | false | If defined, will automatically | 10m | 10m
@@ -178,7 +178,7 @@ AWS_AMI | false | The disk image to use. |
178178
AWS_DISK_SIZE | false | The disk size to use. | 40 | 120
179179
AWS_INSTANCE_TYPE | false | The machine type to use. | c5.xlarge | c5.xlarge
180180
AWS_REGION | true | The aws cloud region to create | | us-west-2
181-
| | the VM in. E.g. us-west-1 | |
181+
| | the VM in, e.g. us-west-1 | |
182182
AWS_SECRET_ACCESS_KEY | false | The aws secret access key | |
183183
AWS_VPC_ID | false | The vpc id to use. | |
184184
INACTIVITY_TIMEOUT | false | If defined, will automatically | 10m | 10m

pkg/driver/custom/custom.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ func ToEnvironWithBinaries(
360360
workspace.Machine,
361361
workspace.Options,
362362
nil,
363+
"",
363364
)
364365
for k, v := range agentBinaries {
365366
environ = append(environ, k+"="+v)

pkg/ide/jupyter/jupyter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const (
2020
var Options = ide.Options{
2121
BindAddressOption: {
2222
Name: BindAddressOption,
23-
Description: "The address to bind the server to locally. E.g. 0.0.0.0:12345",
23+
Description: "The address to bind the server to locally, e.g. 0.0.0.0:12345",
2424
Default: "",
2525
},
2626
OpenOption: {

pkg/ide/openvscode/openvscode.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ var Options = ide.Options{
4747
},
4848
BindAddressOption: {
4949
Name: BindAddressOption,
50-
Description: "The address to bind VSCode web to locally. E.g. 0.0.0.0:12345",
50+
Description: "The address to bind VSCode web to locally, e.g. 0.0.0.0:12345",
5151
Default: "",
5252
},
5353
VersionOption: {

0 commit comments

Comments
 (0)