mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
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:
+1
-5
@@ -35,7 +35,6 @@ import (
|
|||||||
"github.com/coder/coder/v2/cli/clibase"
|
"github.com/coder/coder/v2/cli/clibase"
|
||||||
"github.com/coder/coder/v2/cli/cliui"
|
"github.com/coder/coder/v2/cli/cliui"
|
||||||
"github.com/coder/coder/v2/cli/config"
|
"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/gitauth"
|
||||||
"github.com/coder/coder/v2/coderd/telemetry"
|
"github.com/coder/coder/v2/coderd/telemetry"
|
||||||
"github.com/coder/coder/v2/codersdk"
|
"github.com/coder/coder/v2/codersdk"
|
||||||
@@ -119,10 +118,7 @@ func (r *RootCmd) Core() []*clibase.Cmd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *RootCmd) AGPL() []*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) {
|
all := append(r.Core(), r.Server( /* Do not import coderd here. */ nil))
|
||||||
api := coderd.New(o)
|
|
||||||
return api, api, nil
|
|
||||||
}))
|
|
||||||
return all
|
return all
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -306,6 +306,13 @@ func enablePrometheus(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.API, io.Closer, error)) *clibase.Cmd {
|
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 (
|
var (
|
||||||
vals = new(codersdk.DeploymentValues)
|
vals = new(codersdk.DeploymentValues)
|
||||||
opts = vals.Options()
|
opts = vals.Options()
|
||||||
|
|||||||
+1
-3
@@ -3,17 +3,15 @@
|
|||||||
package cli
|
package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/coder/coder/v2/cli/clibase"
|
"github.com/coder/coder/v2/cli/clibase"
|
||||||
"github.com/coder/coder/v2/cli/cliui"
|
"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{
|
root := &clibase.Cmd{
|
||||||
Use: "server",
|
Use: "server",
|
||||||
Short: "Start a Coder server",
|
Short: "Start a Coder server",
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ type RootCmd struct {
|
|||||||
|
|
||||||
func (r *RootCmd) enterpriseOnly() []*clibase.Cmd {
|
func (r *RootCmd) enterpriseOnly() []*clibase.Cmd {
|
||||||
return []*clibase.Cmd{
|
return []*clibase.Cmd{
|
||||||
r.server(),
|
r.Server(nil),
|
||||||
r.workspaceProxy(),
|
r.workspaceProxy(),
|
||||||
r.features(),
|
r.features(),
|
||||||
r.licenses(),
|
r.licenses(),
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ import (
|
|||||||
agplcoderd "github.com/coder/coder/v2/coderd"
|
agplcoderd "github.com/coder/coder/v2/coderd"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (r *RootCmd) server() *clibase.Cmd {
|
func (r *RootCmd) Server(_ func()) *clibase.Cmd {
|
||||||
cmd := r.Server(func(ctx context.Context, options *agplcoderd.Options) (*agplcoderd.API, io.Closer, error) {
|
cmd := r.RootCmd.Server(func(ctx context.Context, options *agplcoderd.Options) (*agplcoderd.API, io.Closer, error) {
|
||||||
if options.DeploymentValues.DERP.Server.RelayURL.String() != "" {
|
if options.DeploymentValues.DERP.Server.RelayURL.String() != "" {
|
||||||
_, err := url.Parse(options.DeploymentValues.DERP.Server.RelayURL.String())
|
_, err := url.Parse(options.DeploymentValues.DERP.Server.RelayURL.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
//go:build slim
|
|
||||||
|
|
||||||
package cli
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"io"
|
|
||||||
|
|
||||||
"golang.org/x/xerrors"
|
|
||||||
|
|
||||||
"github.com/coder/coder/v2/cli/clibase"
|
|
||||||
agplcoderd "github.com/coder/coder/v2/coderd"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (r *RootCmd) server() *clibase.Cmd {
|
|
||||||
cmd := r.Server(func(ctx context.Context, options *agplcoderd.Options) (*agplcoderd.API, io.Closer, error) {
|
|
||||||
return nil, nil, xerrors.Errorf("slim build does not support `coder server`")
|
|
||||||
})
|
|
||||||
return cmd
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user