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

Commitb21da38

Browse files
authored
chore: deprecate template create command in favor of template push (#11390)
1 parent3d54bc0 commitb21da38

File tree

42 files changed

+467
-389
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+467
-389
lines changed

‎.github/workflows/pr-deploy.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ jobs:
416416
417417
# Create template
418418
cd ./.github/pr-deployments/template
419-
coder templatescreate -y --variable namespace=pr${{ env.PR_NUMBER }} kubernetes
419+
coder templatespush -y --variable namespace=pr${{ env.PR_NUMBER }} kubernetes
420420
421421
# Create workspace
422422
coder create --template="kubernetes" kube --parameter cpu=2 --parameter memory=4 --parameter home_disk_size=2 -y

‎cli/cliui/deprecation.go‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package cliui
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/coder/coder/v2/cli/clibase"
7+
"github.com/coder/pretty"
8+
)
9+
10+
funcDeprecationWarning(messagestring) clibase.MiddlewareFunc {
11+
returnfunc(next clibase.HandlerFunc) clibase.HandlerFunc {
12+
returnfunc(i*clibase.Invocation)error {
13+
_,_=fmt.Fprintln(i.Stdout,"\n"+pretty.Sprint(DefaultStyles.Wrap,
14+
pretty.Sprint(
15+
DefaultStyles.Warn,
16+
"DEPRECATION WARNING: This command will be removed in a future release."+"\n"+message+"\n"),
17+
))
18+
returnnext(i)
19+
}
20+
}
21+
}

‎cli/templatecreate.go‎

Lines changed: 5 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
package cli
22

33
import (
4-
"errors"
54
"fmt"
6-
"io"
75
"net/http"
8-
"strings"
96
"time"
107
"unicode/utf8"
118

12-
"github.com/google/uuid"
139
"golang.org/x/xerrors"
1410

1511
"github.com/coder/pretty"
@@ -40,9 +36,13 @@ func (r *RootCmd) templateCreate() *clibase.Cmd {
4036
client:=new(codersdk.Client)
4137
cmd:=&clibase.Cmd{
4238
Use:"create [name]",
43-
Short:"Create a template from the current directory or as specified by flag",
39+
Short:"DEPRECATED:Create a template from the current directory or as specified by flag",
4440
Middleware:clibase.Chain(
4541
clibase.RequireRangeArgs(0,1),
42+
cliui.DeprecationWarning(
43+
"Use `coder templates push` command for creating and updating templates.\n"+
44+
"Use `coder templates edit` command for editing template settings. ",
45+
),
4646
r.InitClient(client),
4747
),
4848
Handler:func(inv*clibase.Invocation)error {
@@ -253,107 +253,3 @@ func (r *RootCmd) templateCreate() *clibase.Cmd {
253253
cmd.Options=append(cmd.Options,uploadFlags.options()...)
254254
returncmd
255255
}
256-
257-
typecreateValidTemplateVersionArgsstruct {
258-
Namestring
259-
Messagestring
260-
Client*codersdk.Client
261-
Organization codersdk.Organization
262-
Provisioner codersdk.ProvisionerType
263-
FileID uuid.UUID
264-
265-
// Template is only required if updating a template's active version.
266-
Template*codersdk.Template
267-
// ReuseParameters will attempt to reuse params from the Template field
268-
// before prompting the user. Set to false to always prompt for param
269-
// values.
270-
ReuseParametersbool
271-
ProvisionerTagsmap[string]string
272-
UserVariableValues []codersdk.VariableValue
273-
}
274-
275-
funccreateValidTemplateVersion(inv*clibase.Invocation,argscreateValidTemplateVersionArgs) (*codersdk.TemplateVersion,error) {
276-
client:=args.Client
277-
278-
req:= codersdk.CreateTemplateVersionRequest{
279-
Name:args.Name,
280-
Message:args.Message,
281-
StorageMethod:codersdk.ProvisionerStorageMethodFile,
282-
FileID:args.FileID,
283-
Provisioner:args.Provisioner,
284-
ProvisionerTags:args.ProvisionerTags,
285-
UserVariableValues:args.UserVariableValues,
286-
}
287-
ifargs.Template!=nil {
288-
req.TemplateID=args.Template.ID
289-
}
290-
version,err:=client.CreateTemplateVersion(inv.Context(),args.Organization.ID,req)
291-
iferr!=nil {
292-
returnnil,err
293-
}
294-
295-
err=cliui.ProvisionerJob(inv.Context(),inv.Stdout, cliui.ProvisionerJobOptions{
296-
Fetch:func() (codersdk.ProvisionerJob,error) {
297-
version,err:=client.TemplateVersion(inv.Context(),version.ID)
298-
returnversion.Job,err
299-
},
300-
Cancel:func()error {
301-
returnclient.CancelTemplateVersion(inv.Context(),version.ID)
302-
},
303-
Logs:func() (<-chan codersdk.ProvisionerJobLog, io.Closer,error) {
304-
returnclient.TemplateVersionLogsAfter(inv.Context(),version.ID,0)
305-
},
306-
})
307-
iferr!=nil {
308-
varjobErr*cliui.ProvisionerJobError
309-
iferrors.As(err,&jobErr)&&!codersdk.JobIsMissingParameterErrorCode(jobErr.Code) {
310-
returnnil,err
311-
}
312-
iferr!=nil {
313-
returnnil,err
314-
}
315-
}
316-
version,err=client.TemplateVersion(inv.Context(),version.ID)
317-
iferr!=nil {
318-
returnnil,err
319-
}
320-
321-
ifversion.Job.Status!=codersdk.ProvisionerJobSucceeded {
322-
returnnil,xerrors.New(version.Job.Error)
323-
}
324-
325-
resources,err:=client.TemplateVersionResources(inv.Context(),version.ID)
326-
iferr!=nil {
327-
returnnil,err
328-
}
329-
330-
// Only display the resources on the start transition, to avoid listing them more than once.
331-
varstartResources []codersdk.WorkspaceResource
332-
for_,r:=rangeresources {
333-
ifr.Transition==codersdk.WorkspaceTransitionStart {
334-
startResources=append(startResources,r)
335-
}
336-
}
337-
err=cliui.WorkspaceResources(inv.Stdout,startResources, cliui.WorkspaceResourcesOptions{
338-
HideAgentState:true,
339-
HideAccess:true,
340-
Title:"Template Preview",
341-
})
342-
iferr!=nil {
343-
returnnil,xerrors.Errorf("preview template resources: %w",err)
344-
}
345-
346-
return&version,nil
347-
}
348-
349-
funcParseProvisionerTags(rawTags []string) (map[string]string,error) {
350-
tags:=map[string]string{}
351-
for_,rawTag:=rangerawTags {
352-
parts:=strings.SplitN(rawTag,"=",2)
353-
iflen(parts)<2 {
354-
returnnil,xerrors.Errorf("invalid tag format for %q. must be key=value",rawTag)
355-
}
356-
tags[parts[0]]=parts[1]
357-
}
358-
returntags,nil
359-
}

‎cli/templatecreate_test.go‎

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -19,54 +19,6 @@ import (
1919
"github.com/coder/coder/v2/testutil"
2020
)
2121

22-
funccompleteWithAgent()*echo.Responses {
23-
return&echo.Responses{
24-
Parse:echo.ParseComplete,
25-
ProvisionPlan: []*proto.Response{
26-
{
27-
Type:&proto.Response_Plan{
28-
Plan:&proto.PlanComplete{
29-
Resources: []*proto.Resource{
30-
{
31-
Type:"compute",
32-
Name:"main",
33-
Agents: []*proto.Agent{
34-
{
35-
Name:"smith",
36-
OperatingSystem:"linux",
37-
Architecture:"i386",
38-
},
39-
},
40-
},
41-
},
42-
},
43-
},
44-
},
45-
},
46-
ProvisionApply: []*proto.Response{
47-
{
48-
Type:&proto.Response_Apply{
49-
Apply:&proto.ApplyComplete{
50-
Resources: []*proto.Resource{
51-
{
52-
Type:"compute",
53-
Name:"main",
54-
Agents: []*proto.Agent{
55-
{
56-
Name:"smith",
57-
OperatingSystem:"linux",
58-
Architecture:"i386",
59-
},
60-
},
61-
},
62-
},
63-
},
64-
},
65-
},
66-
},
67-
}
68-
}
69-
7022
funcTestTemplateCreate(t*testing.T) {
7123
t.Parallel()
7224
t.Run("Create",func(t*testing.T) {
@@ -418,15 +370,3 @@ func TestTemplateCreate(t *testing.T) {
418370
require.Contains(t,err.Error(),"your deployment appears to be an AGPL deployment, so you cannot set enterprise-only flags")
419371
})
420372
}
421-
422-
// Need this for Windows because of a known issue with Go:
423-
// https://github.com/golang/go/issues/52986
424-
funcremoveTmpDirUntilSuccessAfterTest(t*testing.T,tempDirstring) {
425-
t.Helper()
426-
t.Cleanup(func() {
427-
err:=os.RemoveAll(tempDir)
428-
forerr!=nil {
429-
err=os.RemoveAll(tempDir)
430-
}
431-
})
432-
}

‎cli/templateedit.go‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func (r *RootCmd) templateEdit() *clibase.Cmd {
3535
allowUserAutostopbool
3636
requireActiveVersionbool
3737
deprecationMessagestring
38+
disableEveryonebool
3839
)
3940
client:=new(codersdk.Client)
4041

@@ -162,6 +163,7 @@ func (r *RootCmd) templateEdit() *clibase.Cmd {
162163
AllowUserAutostop:allowUserAutostop,
163164
RequireActiveVersion:requireActiveVersion,
164165
DeprecationMessage:deprecated,
166+
DisableEveryoneGroupAccess:disableEveryone,
165167
}
166168

167169
_,err=client.UpdateTemplateMeta(inv.Context(),template.ID,req)
@@ -292,6 +294,13 @@ func (r *RootCmd) templateEdit() *clibase.Cmd {
292294
Value:clibase.BoolOf(&requireActiveVersion),
293295
Default:"false",
294296
},
297+
{
298+
Flag:"private",
299+
Description:"Disable the default behavior of granting template access to the 'everyone' group. "+
300+
"The template permissions must be updated to allow non-admin users to use this template.",
301+
Value:clibase.BoolOf(&disableEveryone),
302+
Default:"false",
303+
},
295304
cliui.SkipPromptOption(),
296305
}
297306

‎cli/templateinit.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func (*RootCmd) templateInit() *clibase.Cmd {
113113
inv.Stdout,
114114
pretty.Sprint(
115115
cliui.DefaultStyles.Code,
116-
"cd "+relPath+" && coder templatescreate"),
116+
"cd "+relPath+" && coder templatespush"),
117117
)
118118
_,_=fmt.Fprintln(inv.Stdout,pretty.Sprint(cliui.DefaultStyles.Wrap,"\nExamples provide a starting point and are expected to be edited! 🎨"))
119119
returnnil

‎cli/templatelist.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (r *RootCmd) templateList() *clibase.Cmd {
3636

3737
iflen(templates)==0 {
3838
_,_=fmt.Fprintf(inv.Stderr,"%s No templates found in %s! Create one:\n\n",Caret,color.HiWhiteString(organization.Name))
39-
_,_=fmt.Fprintln(inv.Stderr,color.HiMagentaString(" $ coder templatescreate <directory>\n"))
39+
_,_=fmt.Fprintln(inv.Stderr,color.HiMagentaString(" $ coder templatespush <directory>\n"))
4040
returnnil
4141
}
4242

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp