Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 29e3118

Browse files
committed
Merge remote-tracking branch 'origin/master' into stevenmasley/ch11741/workspace_new_template
2 parents 33a5cb5 + 75ef1bc commit 29e3118

32 files changed

+394
-133
lines changed

.github/workflows/build.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ jobs:
77
steps:
88
- name: Checkout
99
uses: actions/checkout@v1
10+
- uses: actions/setup-go@v2
11+
with:
12+
go-version: '^1.16.3'
1013
- name: Build
1114
run: make -j build/linux build/windows
1215
- name: Upload
@@ -19,6 +22,9 @@ jobs:
1922
steps:
2023
- name: Checkout
2124
uses: actions/checkout@v1
25+
- uses: actions/setup-go@v2
26+
with:
27+
go-version: '^1.16.3'
2228
- name: Install Gon
2329
run: |
2430
brew tap mitchellh/gon

ci/image/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1
1+
FROM golang:1.16.3
22

33
ENV GOFLAGS="-mod=readonly"
44
ENV CI=true

coder-sdk/config.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,21 @@ func (c *DefaultClient) SiteConfigExtensionMarketplace(ctx context.Context) (*Co
137137
func (c *DefaultClient) PutSiteConfigExtensionMarketplace(ctx context.Context, req ConfigExtensionMarketplace) error {
138138
return c.requestBody(ctx, http.MethodPut, "/api/private/extensions/config", req, nil)
139139
}
140+
141+
// ConfigWorkspaces is the site configuration for workspace attributes.
142+
type ConfigWorkspaces struct {
143+
GPUVendor string `json:"gpu_vendor,omitempty" valid:"in(nvidia|amd)"`
144+
EnableContainerVMs bool `json:"enable_container_vms,omitempty"`
145+
EnableWorkspacesAsCode bool `json:"enable_workspaces_as_code,omitempty"`
146+
EnableP2P bool `json:"enable_p2p,omitempty"`
147+
}
148+
149+
// SiteConfigWorkspaces fetches the workspace configuration.
150+
func (c *DefaultClient) SiteConfigWorkspaces(ctx context.Context) (*ConfigWorkspaces, error) {
151+
var conf ConfigWorkspaces
152+
// TODO: use the `/api/v0/workspaces/config route once we migrate from using general config
153+
if err := c.requestBody(ctx, http.MethodGet, "/api/private/config", nil, &conf); err != nil {
154+
return nil, err
155+
}
156+
return &conf, nil
157+
}

coder-sdk/devurl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type CreateDevURLReq struct {
4040
Scheme string `json:"scheme"`
4141
}
4242

43-
// CreateDevURL inserts a new devurl for the authenticated user.
43+
// CreateDevURL inserts a new dev URL for the authenticated user.
4444
func (c *DefaultClient) CreateDevURL(ctx context.Context, envID string, req CreateDevURLReq) error {
4545
return c.requestBody(ctx, http.MethodPost, "/api/v0/environments/"+envID+"/devurls", req, nil)
4646
}

coder-sdk/interface.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ type Client interface {
6262
// PutSiteConfigExtensionMarketplace sets the extension marketplace configuration.
6363
PutSiteConfigExtensionMarketplace(ctx context.Context, req ConfigExtensionMarketplace) error
6464

65+
// SiteConfigWorkspaces fetches the workspace configuration.
66+
SiteConfigWorkspaces(ctx context.Context) (*ConfigWorkspaces, error)
67+
6568
// DeleteDevURL deletes the specified devurl.
6669
DeleteDevURL(ctx context.Context, envID, urlID string) error
6770

docs/coder_config-ssh.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ coder config-ssh [flags]
1515
```
1616
--filepath string override the default path of your ssh config file (default "~/.ssh/config")
1717
-h, --help help for config-ssh
18-
--p2p (experimental) uses coder tunnel to proxy ssh connection
1918
--remove remove the auto-generated Coder ssh config
2019
```
2120

docs/coder_urls.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Interact with environment DevURLs
1717
### SEE ALSO
1818

1919
* [coder](coder.md) - coder provides a CLI for working with an existing Coder installation
20-
* [coder urls create](coder_urls_create.md) - Create a new devurl for an environment
20+
* [coder urls create](coder_urls_create.md) - Create a new dev URL for a workspace
2121
* [coder urls ls](coder_urls_ls.md) - List all DevURLs for an environment
2222
* [coder urls rm](coder_urls_rm.md) - Remove a dev url
2323

docs/coder_urls_create.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
## coder urls create
22

3-
Create a new devurl for an environment
3+
Create a new dev URL for a workspace
44

55
```
6-
coder urls create [env_name] [port] [flags]
6+
coder urls create [workspace_name] [port] [flags]
7+
```
8+
9+
### Examples
10+
11+
```
12+
coder urls create my-workspace 8080 --name my-dev-url
713
```
814

915
### Options

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ require (
1717
github.com/pion/dtls/v2 v2.0.9
1818
github.com/pion/ice/v2 v2.1.7
1919
github.com/pion/turn/v2 v2.0.5
20-
github.com/pion/webrtc/v3 v3.0.27
20+
github.com/pion/webrtc/v3 v3.0.29
2121
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4
2222
github.com/rjeczalik/notify v0.9.2
2323
github.com/spf13/cobra v1.1.3

go.sum

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,9 @@ github.com/pion/randutil v0.1.0 h1:CFG1UdESneORglEsnimhUjf33Rwjubwj6xfiOXBa3mA=
272272
github.com/pion/randutil v0.1.0/go.mod h1:XcJrSMMbbMRhASFVOlj/5hQial/Y8oH/HVo7TBZq+j8=
273273
github.com/pion/rtcp v1.2.6 h1:1zvwBbyd0TeEuuWftrd/4d++m+/kZSeiguxU61LFWpo=
274274
github.com/pion/rtcp v1.2.6/go.mod h1:52rMNPWFsjr39z9B9MhnkqhPLoeHTv1aN63o/42bWE0=
275-
github.com/pion/rtp v1.6.2 h1:iGBerLX6JiDjB9NXuaPzHyxHFG9JsIEdgwTC0lp5n/U=
276275
github.com/pion/rtp v1.6.2/go.mod h1:bDb5n+BFZxXx0Ea7E5qe+klMuqiBrP+w8XSjiWtCUko=
276+
github.com/pion/rtp v1.6.5 h1:o2cZf8OascA5HF/b0PAbTxRKvOWxTQxWYt7SlToxFGI=
277+
github.com/pion/rtp v1.6.5/go.mod h1:bDb5n+BFZxXx0Ea7E5qe+klMuqiBrP+w8XSjiWtCUko=
277278
github.com/pion/sctp v1.7.10/go.mod h1:EhpTUQu1/lcK3xI+eriS6/96fWetHGCvBi9MSsnaBN0=
278279
github.com/pion/sctp v1.7.12 h1:GsatLufywVruXbZZT1CKg+Jr8ZTkwiPnmUC/oO9+uuY=
279280
github.com/pion/sctp v1.7.12/go.mod h1:xFe9cLMZ5Vj6eOzpyiKjT9SwGM4KpK/8Jbw5//jc+0s=
@@ -291,8 +292,8 @@ github.com/pion/turn/v2 v2.0.5 h1:iwMHqDfPEDEOFzwWKT56eFmh6DYC6o/+xnLAEzgISbA=
291292
github.com/pion/turn/v2 v2.0.5/go.mod h1:APg43CFyt/14Uy7heYUOGWdkem/Wu4PhCO/bjyrTqMw=
292293
github.com/pion/udp v0.1.1 h1:8UAPvyqmsxK8oOjloDk4wUt63TzFe9WEJkg5lChlj7o=
293294
github.com/pion/udp v0.1.1/go.mod h1:6AFo+CMdKQm7UiA0eUPA8/eVCTx8jBIITLZHc9DWX5M=
294-
github.com/pion/webrtc/v3 v3.0.27 h1:cPQEFNFrRSMT11j9c9aTmXzL3ikKAFPE2kR0ZrQcviw=
295-
github.com/pion/webrtc/v3 v3.0.27/go.mod h1:QpLDmsU5a/a05n230gRtxZRvfHhFzn9ukGUL2x4G5ic=
295+
github.com/pion/webrtc/v3 v3.0.29 h1:pVs6mYjbbYvC8pMsztayEz35DnUEFLPswsicGXaQjxo=
296+
github.com/pion/webrtc/v3 v3.0.29/go.mod h1:XFQeLYBf++bWWA0sJqh6zF1ouWluosxwTOMOoTZGaD0=
296297
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4 h1:49lOXmGaUpV9Fz3gd7TFZY106KVlPVa5jcYD1gaQf98=
297298
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4/go.mod h1:4OwLy04Bl9Ef3GJJCoec+30X3LQs/0/m4HFRt/2LUSA=
298299
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=

internal/cmd/agent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ coder agent start --coder-url https://my-coder.com --token xxxx-xxxx
5151
var ok bool
5252
coderURL, ok = os.LookupEnv("CODER_URL")
5353
if !ok {
54-
client, err := newClient(ctx)
54+
client, err := newClient(ctx, true)
5555
if err != nil {
5656
return xerrors.New("must login, pass --coder-url flag, or set the CODER_URL env variable")
5757
}

internal/cmd/auth.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ var errNeedLogin = clog.Fatal(
2323
const tokenEnv = "CODER_TOKEN"
2424
const urlEnv = "CODER_URL"
2525

26-
func newClient(ctx context.Context) (coder.Client, error) {
26+
func newClient(ctx context.Context, checkVersion bool) (coder.Client, error) {
2727
var (
2828
err error
2929
sessionToken = os.Getenv(tokenEnv)
@@ -55,10 +55,14 @@ func newClient(ctx context.Context) (coder.Client, error) {
5555
return nil, xerrors.Errorf("failed to create new coder.Client: %w", err)
5656
}
5757

58-
apiVersion, err := c.APIVersion(ctx)
59-
if apiVersion != "" && !version.VersionsMatch(apiVersion) {
60-
logVersionMismatchError(apiVersion)
58+
if checkVersion {
59+
var apiVersion string
60+
apiVersion, err = c.APIVersion(ctx)
61+
if apiVersion != "" && !version.VersionsMatch(apiVersion) {
62+
logVersionMismatchError(apiVersion)
63+
}
6164
}
65+
6266
if err != nil {
6367
var he *coder.HTTPError
6468
if xerrors.As(err, &he) {

internal/cmd/configssh.go

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,21 @@ func configSSHCmd() *cobra.Command {
3535
var (
3636
configpath string
3737
remove = false
38-
p2p = false
3938
)
4039

4140
cmd := &cobra.Command{
4241
Use: "config-ssh",
4342
Short: "Configure SSH to access Coder environments",
4443
Long: "Inject the proper OpenSSH configuration into your local SSH config file.",
45-
RunE: configSSH(&configpath, &remove, &p2p),
44+
RunE: configSSH(&configpath, &remove),
4645
}
4746
cmd.Flags().StringVar(&configpath, "filepath", filepath.Join("~", ".ssh", "config"), "override the default path of your ssh config file")
4847
cmd.Flags().BoolVar(&remove, "remove", false, "remove the auto-generated Coder ssh config")
49-
cmd.Flags().BoolVar(&p2p, "p2p", false, "(experimental) uses coder tunnel to proxy ssh connection")
5048

5149
return cmd
5250
}
5351

54-
func configSSH(configpath *string, remove *bool, p2p *bool) func(cmd *cobra.Command, _ []string) error {
52+
func configSSH(configpath *string, remove *bool) func(cmd *cobra.Command, _ []string) error {
5553
return func(cmd *cobra.Command, _ []string) error {
5654
ctx := cmd.Context()
5755
usr, err := user.Current()
@@ -88,7 +86,7 @@ func configSSH(configpath *string, remove *bool, p2p *bool) func(cmd *cobra.Comm
8886
return nil
8987
}
9088

91-
client, err := newClient(ctx)
89+
client, err := newClient(ctx, true)
9290
if err != nil {
9391
return err
9492
}
@@ -115,7 +113,12 @@ func configSSH(configpath *string, remove *bool, p2p *bool) func(cmd *cobra.Comm
115113
return xerrors.New("SSH is disabled or not available for any environments in your Coder deployment.")
116114
}
117115

118-
newConfig := makeNewConfigs(user.Username, envsWithProviders, privateKeyFilepath, *p2p)
116+
wconf, err := client.SiteConfigWorkspaces(ctx)
117+
if err != nil {
118+
return xerrors.Errorf("getting site workspace config: %w", err)
119+
}
120+
121+
newConfig := makeNewConfigs(user.Username, envsWithProviders, privateKeyFilepath, wconf.EnableP2P)
119122

120123
err = os.MkdirAll(filepath.Dir(*configpath), os.ModePerm)
121124
if err != nil {
@@ -194,25 +197,28 @@ func makeNewConfigs(userName string, envs []coderutil.EnvWithWorkspaceProvider,
194197
clog.LogWarn("invalid access url", clog.Causef("malformed url: %q", env.WorkspaceProvider.EnvproxyAccessURL))
195198
continue
196199
}
197-
newConfig += makeSSHConfig(u.Host, userName, env.Env.Name, privateKeyFilepath, p2p)
200+
201+
useTunnel := env.WorkspaceProvider.BuiltIn && p2p
202+
newConfig += makeSSHConfig(u.Host, userName, env.Env.Name, privateKeyFilepath, useTunnel)
198203
}
199204
newConfig += fmt.Sprintf("\n%s\n", sshEndToken)
200205

201206
return newConfig
202207
}
203208

204-
func makeSSHConfig(host, userName, envName, privateKeyFilepath string, p2p bool) string {
205-
if p2p {
209+
func makeSSHConfig(host, userName, envName, privateKeyFilepath string, tunnel bool) string {
210+
if tunnel {
206211
return fmt.Sprintf(
207212
`Host coder.%s
208-
HostName localhost
209-
ProxyCommand coder tunnel %s 22 stdio
213+
HostName coder.%s
214+
ProxyCommand coder tunnel %s 12213 stdio
210215
StrictHostKeyChecking no
211216
ConnectTimeout=0
217+
IdentitiesOnly yes
212218
IdentityFile="%s"
213219
ServerAliveInterval 60
214220
ServerAliveCountMax 3
215-
`, envName, envName, privateKeyFilepath)
221+
`, envName, envName, envName, privateKeyFilepath)
216222
}
217223

218224
return fmt.Sprintf(

internal/cmd/envs.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func lsEnvsCommand() *cobra.Command {
6060
Long: "List all Coder environments owned by the active user.",
6161
RunE: func(cmd *cobra.Command, args []string) error {
6262
ctx := cmd.Context()
63-
client, err := newClient(ctx)
63+
client, err := newClient(ctx, true)
6464
if err != nil {
6565
return err
6666
}
@@ -129,7 +129,7 @@ coder envs --user [email protected] ls -o json \
129129
Args: cobra.MinimumNArgs(1),
130130
RunE: func(cmd *cobra.Command, args []string) error {
131131
ctx := cmd.Context()
132-
client, err := newClient(ctx)
132+
client, err := newClient(ctx, true)
133133
if err != nil {
134134
return xerrors.Errorf("new client: %w", err)
135135
}
@@ -190,7 +190,7 @@ coder envs create my-new-powerful-env --cpu 12 --disk 100 --memory 16 --image ub
190190
return xerrors.New("image unset")
191191
}
192192

193-
client, err := newClient(ctx)
193+
client, err := newClient(ctx, true)
194194
if err != nil {
195195
return err
196196
}
@@ -342,7 +342,7 @@ func environmentFromConfigCmd(update bool) *cobra.Command {
342342
)
343343
}
344344

345-
client, err := newClient(ctx)
345+
client, err := newClient(ctx, true)
346346
if err != nil {
347347
return err
348348
}
@@ -504,7 +504,7 @@ func editEnvCmd() *cobra.Command {
504504
coder envs edit back-end-env --disk 20`,
505505
RunE: func(cmd *cobra.Command, args []string) error {
506506
ctx := cmd.Context()
507-
client, err := newClient(ctx)
507+
client, err := newClient(ctx, true)
508508
if err != nil {
509509
return err
510510
}
@@ -598,7 +598,7 @@ func rmEnvsCmd() *cobra.Command {
598598
Args: cobra.MinimumNArgs(1),
599599
RunE: func(cmd *cobra.Command, args []string) error {
600600
ctx := cmd.Context()
601-
client, err := newClient(ctx)
601+
client, err := newClient(ctx, true)
602602
if err != nil {
603603
return err
604604
}

internal/cmd/images.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func lsImgsCommand(user *string) *cobra.Command {
3838
RunE: func(cmd *cobra.Command, args []string) error {
3939
ctx := cmd.Context()
4040

41-
client, err := newClient(ctx)
41+
client, err := newClient(ctx, true)
4242
if err != nil {
4343
return err
4444
}

internal/cmd/providers.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ coder providers create my-provider --hostname=https://provider.example.com --clu
5050
RunE: func(cmd *cobra.Command, args []string) error {
5151
ctx := cmd.Context()
5252

53-
client, err := newClient(ctx)
53+
client, err := newClient(ctx, true)
5454
if err != nil {
5555
return err
5656
}
@@ -143,7 +143,7 @@ coder providers ls`,
143143
RunE: func(cmd *cobra.Command, args []string) error {
144144
ctx := cmd.Context()
145145

146-
client, err := newClient(ctx)
146+
client, err := newClient(ctx, true)
147147
if err != nil {
148148
return err
149149
}
@@ -174,7 +174,7 @@ func deleteProviderCmd() *cobra.Command {
174174
coder providers rm my-workspace-provider`,
175175
RunE: func(cmd *cobra.Command, args []string) error {
176176
ctx := cmd.Context()
177-
client, err := newClient(ctx)
177+
client, err := newClient(ctx, true)
178178
if err != nil {
179179
return err
180180
}
@@ -232,7 +232,7 @@ func cordonProviderCmd() *cobra.Command {
232232
coder providers cordon my-workspace-provider --reason "limit cloud clost"`,
233233
RunE: func(cmd *cobra.Command, args []string) error {
234234
ctx := cmd.Context()
235-
client, err := newClient(ctx)
235+
client, err := newClient(ctx, true)
236236
if err != nil {
237237
return err
238238
}
@@ -265,7 +265,7 @@ func unCordonProviderCmd() *cobra.Command {
265265
coder providers uncordon my-workspace-provider`,
266266
RunE: func(cmd *cobra.Command, args []string) error {
267267
ctx := cmd.Context()
268-
client, err := newClient(ctx)
268+
client, err := newClient(ctx, true)
269269
if err != nil {
270270
return err
271271
}
@@ -296,7 +296,7 @@ func renameProviderCmd() *cobra.Command {
296296
coder providers rename build-in us-east-1`,
297297
RunE: func(cmd *cobra.Command, args []string) error {
298298
ctx := cmd.Context()
299-
client, err := newClient(ctx)
299+
client, err := newClient(ctx, true)
300300
if err != nil {
301301
return err
302302
}

internal/cmd/rebuild.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func rebuildEnvCommand() *cobra.Command {
2929
coder envs rebuild backend-env --force`,
3030
RunE: func(cmd *cobra.Command, args []string) error {
3131
ctx := cmd.Context()
32-
client, err := newClient(ctx)
32+
client, err := newClient(ctx, true)
3333
if err != nil {
3434
return err
3535
}
@@ -166,7 +166,7 @@ func watchBuildLogCommand() *cobra.Command {
166166
Args: xcobra.ExactArgs(1),
167167
RunE: func(cmd *cobra.Command, args []string) error {
168168
ctx := cmd.Context()
169-
client, err := newClient(ctx)
169+
client, err := newClient(ctx, true)
170170
if err != nil {
171171
return err
172172
}

internal/cmd/resourcemanager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ coder resources top --sort-by memory --show-empty`,
6262
func runResourceTop(options *resourceTopOptions) func(cmd *cobra.Command, args []string) error {
6363
return func(cmd *cobra.Command, args []string) error {
6464
ctx := cmd.Context()
65-
client, err := newClient(ctx)
65+
client, err := newClient(ctx, true)
6666
if err != nil {
6767
return err
6868
}

0 commit comments

Comments
 (0)