mirror of
https://github.com/coder/coder.git
synced 2025-07-08 11:39:50 +00:00
* feat: Add bufferring to provisioner job logs This should improve overall build performance, and especially under load. It removes the old `id` column on the `provisioner_job_logs` table and replaces it with an auto-incrementing big integer to preserve order. Funny enough, we never had to care about order before because inserts would at minimum be 1ms different. Now they aren't, so the order needs to be preserved. * Fix log bufferring * Fix frontend log streaming * Fix JS test
87 lines
2.2 KiB
Go
87 lines
2.2 KiB
Go
package cli
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/coder/coder/cli/cliflag"
|
|
"github.com/coder/coder/codersdk"
|
|
)
|
|
|
|
func update() *cobra.Command {
|
|
var (
|
|
parameterFile string
|
|
alwaysPrompt bool
|
|
)
|
|
|
|
cmd := &cobra.Command{
|
|
Annotations: workspaceCommand,
|
|
Use: "update <workspace>",
|
|
Args: cobra.ExactArgs(1),
|
|
Short: "Update a workspace",
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
client, err := CreateClient(cmd)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
workspace, err := namedWorkspace(cmd, client, args[0])
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if !workspace.Outdated && !alwaysPrompt {
|
|
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "Workspace isn't outdated!\n")
|
|
return nil
|
|
}
|
|
template, err := client.Template(cmd.Context(), workspace.TemplateID)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
|
|
var existingParams []codersdk.Parameter
|
|
if !alwaysPrompt {
|
|
existingParams, err = client.Parameters(cmd.Context(), codersdk.ParameterWorkspace, workspace.ID)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
}
|
|
|
|
parameters, err := prepWorkspaceBuild(cmd, client, prepWorkspaceBuildArgs{
|
|
Template: template,
|
|
ExistingParams: existingParams,
|
|
ParameterFile: parameterFile,
|
|
NewWorkspaceName: workspace.Name,
|
|
})
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
|
|
build, err := client.CreateWorkspaceBuild(cmd.Context(), workspace.ID, codersdk.CreateWorkspaceBuildRequest{
|
|
TemplateVersionID: template.ActiveVersionID,
|
|
Transition: workspace.LatestBuild.Transition,
|
|
ParameterValues: parameters,
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
logs, closer, err := client.WorkspaceBuildLogsAfter(cmd.Context(), build.ID, 0)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer closer.Close()
|
|
for {
|
|
log, ok := <-logs
|
|
if !ok {
|
|
break
|
|
}
|
|
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "Output: %s\n", log.Output)
|
|
}
|
|
return nil
|
|
},
|
|
}
|
|
|
|
cmd.Flags().BoolVar(&alwaysPrompt, "always-prompt", false, "Always prompt all parameters. Does not pull parameter values from existing workspace")
|
|
cliflag.StringVarP(cmd.Flags(), ¶meterFile, "parameter-file", "", "CODER_PARAMETER_FILE", "", "Specify a file path with parameter values.")
|
|
return cmd
|
|
}
|