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

chore: deprecate template create command in favor of template push#11390

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
f0ssel merged 43 commits intomainfromf0ssel/templatepush-2
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
43 commits
Select commitHold shift + click to select a range
0cc46c8
fix: make template push a superset of template create
f0sselDec 20, 2023
93da7d0
add back work dir
f0sselDec 20, 2023
3c409f6
add groupacl
f0sselDec 20, 2023
4b763d7
Add back workdir
f0sselDec 20, 2023
d178cc7
combine edit flags
f0sselDec 20, 2023
5474942
fix edit
f0sselDec 20, 2023
2b9bcf6
unify edit and push
f0sselDec 20, 2023
44f264b
make gen
f0sselDec 20, 2023
d58cf18
fix test
f0sselDec 21, 2023
9b32922
make gen
f0sselDec 21, 2023
c6ef6f4
update golden
f0sselDec 21, 2023
e1e1653
fix tests:
f0sselDec 21, 2023
0cdefbc
fix merge
f0sselDec 21, 2023
d2a7866
add test
f0sselDec 22, 2023
63d57fd
remove test
f0sselDec 22, 2023
ca65869
add unset test
f0sselDec 22, 2023
9866235
Add deprecation warning
f0sselDec 22, 2023
35c7adf
fix
f0sselDec 22, 2023
4abf179
rename functions
f0sselJan 2, 2024
a3fdb76
test removing flags
f0sselJan 3, 2024
7599090
revert
f0sselJan 3, 2024
e958e1a
cleanup
f0sselJan 3, 2024
c8cae6c
add back flag
f0sselJan 3, 2024
1b03e89
remove create command
f0sselJan 4, 2024
8918cda
make gen
f0sselJan 4, 2024
7d2a7ac
fix gen
f0sselJan 4, 2024
5b2792d
add private flag to template edit
f0sselJan 4, 2024
b85a73c
fix test
f0sselJan 4, 2024
7655bc9
fix golden
f0sselJan 4, 2024
2f2911a
update mentions of templates create command
f0sselJan 4, 2024
5334e8e
update golden
f0sselJan 4, 2024
79c0c02
add removal comment
f0sselJan 4, 2024
2dfb98e
Add back create
f0sselJan 4, 2024
cb0aec4
fix formatting
f0sselJan 4, 2024
d1f13d1
add disableeveryonegroupaccess test
f0sselJan 4, 2024
5792279
update test
f0sselJan 5, 2024
2e54259
fix test lint
f0sselJan 5, 2024
de78f4b
pr comments
f0sselJan 5, 2024
0c859bc
fix text formatting
f0sselJan 5, 2024
b65ab81
Add deprecation to help text
f0sselJan 5, 2024
77c9edf
fix template push wording
f0sselJan 5, 2024
13794fd
golden
f0sselJan 5, 2024
8355850
fix gen again
f0sselJan 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion.github/workflows/pr-deploy.yaml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -416,7 +416,7 @@ jobs:

# Create template
cd ./.github/pr-deployments/template
coder templatescreate -y --variable namespace=pr${{ env.PR_NUMBER }} kubernetes
coder templatespush -y --variable namespace=pr${{ env.PR_NUMBER }} kubernetes

# Create workspace
coder create --template="kubernetes" kube --parameter cpu=2 --parameter memory=4 --parameter home_disk_size=2 -y
Expand Down
21 changes: 21 additions & 0 deletionscli/cliui/deprecation.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
package cliui

import (
"fmt"

"github.com/coder/coder/v2/cli/clibase"
"github.com/coder/pretty"
)

func DeprecationWarning(message string) clibase.MiddlewareFunc {
return func(next clibase.HandlerFunc) clibase.HandlerFunc {
return func(i *clibase.Invocation) error {
_, _ = fmt.Fprintln(i.Stdout, "\n"+pretty.Sprint(DefaultStyles.Wrap,
pretty.Sprint(
DefaultStyles.Warn,
"DEPRECATION WARNING: This command will be removed in a future release."+"\n"+message+"\n"),
))
return next(i)
}
}
}
114 changes: 5 additions & 109 deletionscli/templatecreate.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
package cli

import (
"errors"
"fmt"
"io"
"net/http"
"strings"
"time"
"unicode/utf8"

"github.com/google/uuid"
"golang.org/x/xerrors"

"github.com/coder/pretty"
Expand DownExpand Up@@ -40,9 +36,13 @@ func (r *RootCmd) templateCreate() *clibase.Cmd {
client := new(codersdk.Client)
cmd := &clibase.Cmd{
Use: "create [name]",
Short: "Create a template from the current directory or as specified by flag",
Short: "DEPRECATED:Create a template from the current directory or as specified by flag",
Middleware: clibase.Chain(
clibase.RequireRangeArgs(0, 1),
cliui.DeprecationWarning(
"Use `coder templates push` command for creating and updating templates. \n"+
"Use `coder templates edit` command for editing template settings. ",
),
r.InitClient(client),
),
Handler: func(inv *clibase.Invocation) error {
Expand DownExpand Up@@ -253,107 +253,3 @@ func (r *RootCmd) templateCreate() *clibase.Cmd {
cmd.Options = append(cmd.Options, uploadFlags.options()...)
return cmd
}

type createValidTemplateVersionArgs struct {
Name string
Message string
Client *codersdk.Client
Organization codersdk.Organization
Provisioner codersdk.ProvisionerType
FileID uuid.UUID

// Template is only required if updating a template's active version.
Template *codersdk.Template
// ReuseParameters will attempt to reuse params from the Template field
// before prompting the user. Set to false to always prompt for param
// values.
ReuseParameters bool
ProvisionerTags map[string]string
UserVariableValues []codersdk.VariableValue
}

func createValidTemplateVersion(inv *clibase.Invocation, args createValidTemplateVersionArgs) (*codersdk.TemplateVersion, error) {
client := args.Client

req := codersdk.CreateTemplateVersionRequest{
Name: args.Name,
Message: args.Message,
StorageMethod: codersdk.ProvisionerStorageMethodFile,
FileID: args.FileID,
Provisioner: args.Provisioner,
ProvisionerTags: args.ProvisionerTags,
UserVariableValues: args.UserVariableValues,
}
if args.Template != nil {
req.TemplateID = args.Template.ID
}
version, err := client.CreateTemplateVersion(inv.Context(), args.Organization.ID, req)
if err != nil {
return nil, err
}

err = cliui.ProvisionerJob(inv.Context(), inv.Stdout, cliui.ProvisionerJobOptions{
Fetch: func() (codersdk.ProvisionerJob, error) {
version, err := client.TemplateVersion(inv.Context(), version.ID)
return version.Job, err
},
Cancel: func() error {
return client.CancelTemplateVersion(inv.Context(), version.ID)
},
Logs: func() (<-chan codersdk.ProvisionerJobLog, io.Closer, error) {
return client.TemplateVersionLogsAfter(inv.Context(), version.ID, 0)
},
})
if err != nil {
var jobErr *cliui.ProvisionerJobError
if errors.As(err, &jobErr) && !codersdk.JobIsMissingParameterErrorCode(jobErr.Code) {
return nil, err
}
if err != nil {
return nil, err
}
}
version, err = client.TemplateVersion(inv.Context(), version.ID)
if err != nil {
return nil, err
}

if version.Job.Status != codersdk.ProvisionerJobSucceeded {
return nil, xerrors.New(version.Job.Error)
}

resources, err := client.TemplateVersionResources(inv.Context(), version.ID)
if err != nil {
return nil, err
}

// Only display the resources on the start transition, to avoid listing them more than once.
var startResources []codersdk.WorkspaceResource
for _, r := range resources {
if r.Transition == codersdk.WorkspaceTransitionStart {
startResources = append(startResources, r)
}
}
err = cliui.WorkspaceResources(inv.Stdout, startResources, cliui.WorkspaceResourcesOptions{
HideAgentState: true,
HideAccess: true,
Title: "Template Preview",
})
if err != nil {
return nil, xerrors.Errorf("preview template resources: %w", err)
}

return &version, nil
}

func ParseProvisionerTags(rawTags []string) (map[string]string, error) {
tags := map[string]string{}
for _, rawTag := range rawTags {
parts := strings.SplitN(rawTag, "=", 2)
if len(parts) < 2 {
return nil, xerrors.Errorf("invalid tag format for %q. must be key=value", rawTag)
}
tags[parts[0]] = parts[1]
}
return tags, nil
}
60 changes: 0 additions & 60 deletionscli/templatecreate_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,54 +19,6 @@ import (
"github.com/coder/coder/v2/testutil"
)

func completeWithAgent() *echo.Responses {
return &echo.Responses{
Parse: echo.ParseComplete,
ProvisionPlan: []*proto.Response{
{
Type: &proto.Response_Plan{
Plan: &proto.PlanComplete{
Resources: []*proto.Resource{
{
Type: "compute",
Name: "main",
Agents: []*proto.Agent{
{
Name: "smith",
OperatingSystem: "linux",
Architecture: "i386",
},
},
},
},
},
},
},
},
ProvisionApply: []*proto.Response{
{
Type: &proto.Response_Apply{
Apply: &proto.ApplyComplete{
Resources: []*proto.Resource{
{
Type: "compute",
Name: "main",
Agents: []*proto.Agent{
{
Name: "smith",
OperatingSystem: "linux",
Architecture: "i386",
},
},
},
},
},
},
},
},
}
}

func TestTemplateCreate(t *testing.T) {
t.Parallel()
t.Run("Create", func(t *testing.T) {
Expand DownExpand Up@@ -418,15 +370,3 @@ func TestTemplateCreate(t *testing.T) {
require.Contains(t, err.Error(), "your deployment appears to be an AGPL deployment, so you cannot set enterprise-only flags")
})
}

// Need this for Windows because of a known issue with Go:
// https://github.com/golang/go/issues/52986
func removeTmpDirUntilSuccessAfterTest(t *testing.T, tempDir string) {
t.Helper()
t.Cleanup(func() {
err := os.RemoveAll(tempDir)
for err != nil {
err = os.RemoveAll(tempDir)
}
})
}
9 changes: 9 additions & 0 deletionscli/templateedit.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,6 +35,7 @@ func (r *RootCmd) templateEdit() *clibase.Cmd {
allowUserAutostop bool
requireActiveVersion bool
deprecationMessage string
disableEveryone bool
)
client := new(codersdk.Client)

Expand DownExpand Up@@ -162,6 +163,7 @@ func (r *RootCmd) templateEdit() *clibase.Cmd {
AllowUserAutostop: allowUserAutostop,
RequireActiveVersion: requireActiveVersion,
DeprecationMessage: deprecated,
DisableEveryoneGroupAccess: disableEveryone,
}

_, err = client.UpdateTemplateMeta(inv.Context(), template.ID, req)
Expand DownExpand Up@@ -292,6 +294,13 @@ func (r *RootCmd) templateEdit() *clibase.Cmd {
Value: clibase.BoolOf(&requireActiveVersion),
Default: "false",
},
{
Flag: "private",
Description: "Disable the default behavior of granting template access to the 'everyone' group. " +
"The template permissions must be updated to allow non-admin users to use this template.",
Value: clibase.BoolOf(&disableEveryone),
Default: "false",
},
cliui.SkipPromptOption(),
}

Expand Down
2 changes: 1 addition & 1 deletioncli/templateinit.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -113,7 +113,7 @@ func (*RootCmd) templateInit() *clibase.Cmd {
inv.Stdout,
pretty.Sprint(
cliui.DefaultStyles.Code,
"cd "+relPath+" && coder templatescreate"),
"cd "+relPath+" && coder templatespush"),
)
_, _ = fmt.Fprintln(inv.Stdout, pretty.Sprint(cliui.DefaultStyles.Wrap, "\nExamples provide a starting point and are expected to be edited! 🎨"))
return nil
Expand Down
2 changes: 1 addition & 1 deletioncli/templatelist.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -36,7 +36,7 @@ func (r *RootCmd) templateList() *clibase.Cmd {

if len(templates) == 0 {
_, _ = fmt.Fprintf(inv.Stderr, "%s No templates found in %s! Create one:\n\n", Caret, color.HiWhiteString(organization.Name))
_, _ = fmt.Fprintln(inv.Stderr, color.HiMagentaString(" $ coder templatescreate <directory>\n"))
_, _ = fmt.Fprintln(inv.Stderr, color.HiMagentaString(" $ coder templatespush <directory>\n"))
return nil
}

Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp