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
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
/coder-v1-cliPublic archive

feat: add envs create-from-repo subcommand#212

Merged
sreya merged 1 commit intomasterfromenvs-as-code
Jan 26, 2021
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
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
40 changes: 30 additions & 10 deletionscoder-sdk/env.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -73,16 +73,17 @@ const (

// CreateEnvironmentRequest is used to configure a new environment.
type CreateEnvironmentRequest struct {
Name string `json:"name"`
ImageID string `json:"image_id"`
OrgID string `json:"org_id"`
ImageTag string `json:"image_tag"`
CPUCores float32 `json:"cpu_cores"`
MemoryGB float32 `json:"memory_gb"`
DiskGB int `json:"disk_gb"`
GPUs int `json:"gpus"`
Services []string `json:"services"`
UseContainerVM bool `json:"use_container_vm"`
Name string `json:"name"`
ImageID string `json:"image_id"`
OrgID string `json:"org_id"`
ImageTag string `json:"image_tag"`
CPUCores float32 `json:"cpu_cores"`
MemoryGB float32 `json:"memory_gb"`
DiskGB int `json:"disk_gb"`
GPUs int `json:"gpus"`
Services []string `json:"services"`
UseContainerVM bool `json:"use_container_vm"`
Template *Template `json:"template"`
}

// CreateEnvironment sends a request to create an environment.
Expand All@@ -94,6 +95,25 @@ func (c Client) CreateEnvironment(ctx context.Context, req CreateEnvironmentRequ
return &env, nil
}

// Template is used to configure a new environment from a repo.
// It is currently in alpha and subject to API-breaking change.
type Template struct {
RepositoryURL string `json:"repository_url"`
// Optional. The default branch will be used if not provided.
Branch string `json:"branch"`
// Optional. The template name will be used if not provided.
Name string `json:"name"`
}

// CreateEnvironmentFromRepo sends a request to create an environment from a repository.
func (c Client) CreateEnvironmentFromRepo(ctx context.Context, orgID string, req Template) (*Environment, error) {
var env Environment
if err := c.requestBody(ctx, http.MethodPost, "/api/private/orgs/"+orgID+"/environments/from-repo", req, &env); err != nil {
return nil, err
}
return &env, nil
}

// Environments lists environments returned by the given filter.
// TODO: add the filter options, explore performance issue.
func (c Client) Environments(ctx context.Context) ([]Environment, error) {
Expand Down
61 changes: 60 additions & 1 deletioninternal/cmd/envs.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,6 +32,7 @@ func envsCmd() *cobra.Command {
watchBuildLogCommand(),
rebuildEnvCommand(),
createEnvCmd(),
createEnvFromRepoCmd(),
editEnvCmd(),
)
return cmd
Expand DownExpand Up@@ -184,7 +185,6 @@ coder envs create my-new-powerful-env --cpu 12 --disk 100 --memory 16 --image ub
if multiOrgMember && org == "" {
return xerrors.New("org is required for multi-org members")
}

importedImg, err := findImg(ctx, client, findImgConf{
email: coder.Me,
imgName: img,
Expand DownExpand Up@@ -252,6 +252,65 @@ coder envs create my-new-powerful-env --cpu 12 --disk 100 --memory 16 --image ub
return cmd
}

func createEnvFromRepoCmd() *cobra.Command {
var (
branch string
name string
follow bool
)

cmd := &cobra.Command{
Use: "create-from-repo [environment_name]",
Short: "create a new environment from a git repository.",
Args: xcobra.ExactArgs(1),
Long: "Create a new Coder environment from a Git repository.",
Hidden: true,
Example: `# create a new environment from git repository template
coder envs create-from-repo github.com/cdr/m
coder envs create-from-repo github.com/cdr/m --branch envs-as-code`,
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()

client, err := newClient(ctx)
if err != nil {
return err
}

// ExactArgs(1) ensures our name value can't panic on an out of bounds.
createReq := &coder.Template{
RepositoryURL: args[0],
Branch: branch,
Name: name,
}

env, err := client.CreateEnvironment(ctx, coder.CreateEnvironmentRequest{
Template: createReq,
})
if err != nil {
return xerrors.Errorf("create environment: %w", err)
}

if follow {
clog.LogSuccess("creating environment...")
if err := trailBuildLogs(ctx, client, env.ID); err != nil {
return err
}
return nil
}

clog.LogSuccess("creating environment...",
clog.BlankLine,
clog.Tipf(`run "coder envs watch-build %s" to trail the build logs`, env.Name),
)
return nil
},
}
cmd.Flags().StringVarP(&branch, "branch", "b", "master", "name of the branch to create the environment from.")
cmd.Flags().StringVarP(&name, "name", "n", "coder.yaml", "name of the config file.")
cmd.Flags().BoolVar(&follow, "follow", false, "follow buildlog after initiating rebuild")
return cmd
}

func editEnvCmd() *cobra.Command {
var (
org string
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp