refactor(cli): avoid importing coderd in slim server (#9483)

This small change removes 11 MB from the slim binary size.

Ref: #9380
This commit is contained in:
Mathias Fredriksson
2023-09-01 13:32:21 +00:00
committed by GitHub
parent 5d7a77911e
commit f1f9cb030d
6 changed files with 12 additions and 31 deletions
+1 -5
View File
@@ -35,7 +35,6 @@ import (
"github.com/coder/coder/v2/cli/clibase"
"github.com/coder/coder/v2/cli/cliui"
"github.com/coder/coder/v2/cli/config"
"github.com/coder/coder/v2/coderd"
"github.com/coder/coder/v2/coderd/gitauth"
"github.com/coder/coder/v2/coderd/telemetry"
"github.com/coder/coder/v2/codersdk"
@@ -119,10 +118,7 @@ func (r *RootCmd) Core() []*clibase.Cmd {
}
func (r *RootCmd) AGPL() []*clibase.Cmd {
all := append(r.Core(), r.Server(func(_ context.Context, o *coderd.Options) (*coderd.API, io.Closer, error) {
api := coderd.New(o)
return api, api, nil
}))
all := append(r.Core(), r.Server( /* Do not import coderd here. */ nil))
return all
}
+7
View File
@@ -306,6 +306,13 @@ func enablePrometheus(
}
func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.API, io.Closer, error)) *clibase.Cmd {
if newAPI == nil {
newAPI = func(_ context.Context, o *coderd.Options) (*coderd.API, io.Closer, error) {
api := coderd.New(o)
return api, api, nil
}
}
var (
vals = new(codersdk.DeploymentValues)
opts = vals.Options()
+1 -3
View File
@@ -3,17 +3,15 @@
package cli
import (
"context"
"fmt"
"io"
"os"
"github.com/coder/coder/v2/cli/clibase"
"github.com/coder/coder/v2/cli/cliui"
"github.com/coder/coder/v2/coderd"
)
func (r *RootCmd) Server(_ func(context.Context, *coderd.Options) (*coderd.API, io.Closer, error)) *clibase.Cmd {
func (r *RootCmd) Server(_ func()) *clibase.Cmd {
root := &clibase.Cmd{
Use: "server",
Short: "Start a Coder server",