Skip to content

Commit b21da38

Browse files
authored
chore: deprecate template create command in favor of template push (#11390)
1 parent 3d54bc0 commit b21da38

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 templates create -y --variable namespace=pr${{ env.PR_NUMBER }} kubernetes
419+
coder templates push -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+
func DeprecationWarning(message string) clibase.MiddlewareFunc {
11+
return func(next clibase.HandlerFunc) clibase.HandlerFunc {
12+
return func(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+
return next(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
return cmd
255255
}
256-
257-
type createValidTemplateVersionArgs struct {
258-
Name string
259-
Message string
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-
ReuseParameters bool
271-
ProvisionerTags map[string]string
272-
UserVariableValues []codersdk.VariableValue
273-
}
274-
275-
func createValidTemplateVersion(inv *clibase.Invocation, args createValidTemplateVersionArgs) (*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-
if args.Template != nil {
288-
req.TemplateID = args.Template.ID
289-
}
290-
version, err := client.CreateTemplateVersion(inv.Context(), args.Organization.ID, req)
291-
if err != nil {
292-
return nil, 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-
return version.Job, err
299-
},
300-
Cancel: func() error {
301-
return client.CancelTemplateVersion(inv.Context(), version.ID)
302-
},
303-
Logs: func() (<-chan codersdk.ProvisionerJobLog, io.Closer, error) {
304-
return client.TemplateVersionLogsAfter(inv.Context(), version.ID, 0)
305-
},
306-
})
307-
if err != nil {
308-
var jobErr *cliui.ProvisionerJobError
309-
if errors.As(err, &jobErr) && !codersdk.JobIsMissingParameterErrorCode(jobErr.Code) {
310-
return nil, err
311-
}
312-
if err != nil {
313-
return nil, err
314-
}
315-
}
316-
version, err = client.TemplateVersion(inv.Context(), version.ID)
317-
if err != nil {
318-
return nil, err
319-
}
320-
321-
if version.Job.Status != codersdk.ProvisionerJobSucceeded {
322-
return nil, xerrors.New(version.Job.Error)
323-
}
324-
325-
resources, err := client.TemplateVersionResources(inv.Context(), version.ID)
326-
if err != nil {
327-
return nil, err
328-
}
329-
330-
// Only display the resources on the start transition, to avoid listing them more than once.
331-
var startResources []codersdk.WorkspaceResource
332-
for _, r := range resources {
333-
if r.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-
if err != nil {
343-
return nil, xerrors.Errorf("preview template resources: %w", err)
344-
}
345-
346-
return &version, nil
347-
}
348-
349-
func ParseProvisionerTags(rawTags []string) (map[string]string, error) {
350-
tags := map[string]string{}
351-
for _, rawTag := range rawTags {
352-
parts := strings.SplitN(rawTag, "=", 2)
353-
if len(parts) < 2 {
354-
return nil, xerrors.Errorf("invalid tag format for %q. must be key=value", rawTag)
355-
}
356-
tags[parts[0]] = parts[1]
357-
}
358-
return tags, 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-
func completeWithAgent() *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
func TestTemplateCreate(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-
func removeTmpDirUntilSuccessAfterTest(t *testing.T, tempDir string) {
425-
t.Helper()
426-
t.Cleanup(func() {
427-
err := os.RemoveAll(tempDir)
428-
for err != 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
allowUserAutostop bool
3636
requireActiveVersion bool
3737
deprecationMessage string
38+
disableEveryone bool
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 templates create"),
116+
"cd "+relPath+" && coder templates push"),
117117
)
118118
_, _ = fmt.Fprintln(inv.Stdout, pretty.Sprint(cliui.DefaultStyles.Wrap, "\nExamples provide a starting point and are expected to be edited! 🎨"))
119119
return nil

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
if len(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 templates create <directory>\n"))
39+
_, _ = fmt.Fprintln(inv.Stderr, color.HiMagentaString(" $ coder templates push <directory>\n"))
4040
return nil
4141
}
4242

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy