Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit 91bc23d

Browse files
authored
support fast, simple sg start single-program-experimental-blame-sqs for local dev (#63435)
This makes it easier to run Sourcegraph in local dev by compiling a few key services (frontend, searcher, repo-updater, gitserver, and worker) into a single Go binary and running that. Compared to `sg start` (which compiles and runs ~10 services), it's faster to start up (by ~10% or a few seconds), takes a lot less memory and CPU when running, has less log noise, and rebuilds faster. It is slower to recompile for changes just to `frontend` because it needs to link in more code on each recompile, but it's faster for most other Go changes that require recompilation of multiple services. This is only intended for local dev as a convenience. There may be different behavior in this mode that could result in problems when your code runs in the normal deployment. Usually our e2e tests should catch this, but to be safe, you should run in the usual mode if you are making sensitive cross-service changes. Partially reverts "svcmain: Simplify service setup (#61903)" (commit 9541032). ## Test plan Existing tests cover any regressions to existing behavior. This new behavior is for local dev only.
1 parent ef50a04 commit 91bc23d

File tree

15 files changed

+191
-77
lines changed

15 files changed

+191
-77
lines changed

cmd/appliance/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ import (
88

99
func main() {
1010
sanitycheck.Pass()
11-
svcmain.SingleServiceMainWithoutConf(shared.Service, svcmain.OutOfBandConfiguration{})
11+
svcmain.SingleServiceMainWithoutConf(shared.Service, nil, svcmain.OutOfBandConfiguration{})
1212
}

cmd/cody-gateway/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var sentryDSN = env.Get("CODY_GATEWAY_SENTRY_DSN", "", "Sentry DSN")
1515

1616
func main() {
1717
sanitycheck.Pass()
18-
svcmain.SingleServiceMainWithoutConf(shared.Service, svcmain.OutOfBandConfiguration{
18+
svcmain.SingleServiceMainWithoutConf(shared.Service, nil, svcmain.OutOfBandConfiguration{
1919
Logging: func() conf.LogSinksSource {
2020
if sentryDSN == "" {
2121
return nil

cmd/frontend/BUILD.bazel

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,8 @@ go_library(
1010
importpath = "github.com/sourcegraph/sourcegraph/cmd/frontend",
1111
visibility = ["//visibility:private"],
1212
deps = [
13-
"//client/web/dist",
1413
"//cmd/frontend/shared",
15-
"//internal/conf",
1614
"//internal/sanitycheck",
17-
"//internal/service/svcmain",
18-
"//internal/tracer",
19-
"//ui/assets",
2015
],
2116
)
2217

cmd/frontend/main.go

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,11 @@
22
package main
33

44
import (
5-
"os"
6-
75
"github.com/sourcegraph/sourcegraph/cmd/frontend/shared"
8-
"github.com/sourcegraph/sourcegraph/internal/conf"
96
"github.com/sourcegraph/sourcegraph/internal/sanitycheck"
10-
"github.com/sourcegraph/sourcegraph/internal/service/svcmain"
11-
"github.com/sourcegraph/sourcegraph/internal/tracer"
12-
"github.com/sourcegraph/sourcegraph/ui/assets"
13-
14-
_ "github.com/sourcegraph/sourcegraph/client/web/dist" // use assets
157
)
168

179
func main() {
1810
sanitycheck.Pass()
19-
if os.Getenv("WEB_BUILDER_DEV_SERVER") == "1" {
20-
assets.UseDevAssetsProvider()
21-
}
22-
svcmain.SingleServiceMainWithoutConf(shared.Service, svcmain.OutOfBandConfiguration{
23-
// use a switchable config here so we can switch it out for a proper conf client
24-
// once we can use it after autoupgrading
25-
Logging: conf.NewLogsSinksSource(shared.SwitchableSiteConfig()),
26-
Tracing: tracer.ConfConfigurationSource{WatchableSiteConfig: shared.SwitchableSiteConfig()},
27-
})
11+
shared.FrontendMain(nil)
2812
}

cmd/frontend/shared/BUILD.bazel

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ go_library(
1010
importpath = "github.com/sourcegraph/sourcegraph/cmd/frontend/shared",
1111
visibility = ["//visibility:public"],
1212
deps = [
13+
"//client/web/dist",
1314
"//cmd/frontend/enterprise",
1415
"//cmd/frontend/internal/auth",
1516
"//cmd/frontend/internal/authz",
@@ -51,7 +52,10 @@ go_library(
5152
"//internal/observation",
5253
"//internal/oobmigration/migrations/register",
5354
"//internal/service",
55+
"//internal/service/svcmain",
56+
"//internal/tracer",
5457
"//schema",
58+
"//ui/assets",
5559
"@com_github_sourcegraph_log//:log",
5660
],
5761
)

cmd/frontend/shared/service.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,40 @@ package shared
33

44
import (
55
"context"
6+
"os"
67

78
"github.com/sourcegraph/sourcegraph/cmd/frontend/internal/cli"
89
"github.com/sourcegraph/sourcegraph/cmd/frontend/internal/codeintel"
910
"github.com/sourcegraph/sourcegraph/cmd/frontend/internal/search"
11+
"github.com/sourcegraph/sourcegraph/internal/conf"
1012
"github.com/sourcegraph/sourcegraph/internal/debugserver"
1113
"github.com/sourcegraph/sourcegraph/internal/env"
1214
"github.com/sourcegraph/sourcegraph/internal/observation"
1315
"github.com/sourcegraph/sourcegraph/internal/oobmigration/migrations/register"
1416
"github.com/sourcegraph/sourcegraph/internal/service"
17+
"github.com/sourcegraph/sourcegraph/internal/service/svcmain"
18+
"github.com/sourcegraph/sourcegraph/internal/tracer"
19+
"github.com/sourcegraph/sourcegraph/ui/assets"
1520

21+
_ "github.com/sourcegraph/sourcegraph/client/web/dist" // use assets
1622
_ "github.com/sourcegraph/sourcegraph/cmd/frontend/internal/registry"
1723
_ "github.com/sourcegraph/sourcegraph/cmd/frontend/registry/api"
1824
)
1925

26+
// FrontendMain is called from the `main` function of a command that includes the frontend.
27+
func FrontendMain(otherServices []service.Service) {
28+
if os.Getenv("WEB_BUILDER_DEV_SERVER") == "1" {
29+
assets.UseDevAssetsProvider()
30+
}
31+
oobConfig := svcmain.OutOfBandConfiguration{
32+
// Use a switchable config here so we can switch it out for a proper conf client
33+
// once we can use it after autoupgrading.
34+
Logging: conf.NewLogsSinksSource(switchableSiteConfig()),
35+
Tracing: tracer.ConfConfigurationSource{WatchableSiteConfig: switchableSiteConfig()},
36+
}
37+
svcmain.SingleServiceMainWithoutConf(Service, otherServices, oobConfig)
38+
}
39+
2040
type svc struct {
2141
ready chan struct{}
2242
debugserverEndpoints cli.LazyDebugserverEndpoint

cmd/frontend/shared/shared.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func mustInitializeCodeIntelDB(logger log.Logger) codeintelshared.CodeIntelDB {
129129
return codeintelshared.NewCodeIntelDB(logger, db)
130130
}
131131

132-
func SwitchableSiteConfig() conftypes.WatchableSiteConfig {
132+
func switchableSiteConfig() conftypes.WatchableSiteConfig {
133133
confClient := conf.DefaultClient()
134134
switchable := &switchingSiteConfig{
135135
watchers: make([]func(), 0),

cmd/sourcegraph/BUILD.bazel

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
2+
3+
go_library(
4+
name = "sourcegraph_lib",
5+
srcs = ["main.go"],
6+
importpath = "github.com/sourcegraph/sourcegraph/cmd/sourcegraph",
7+
visibility = ["//visibility:private"],
8+
deps = [
9+
"//cmd/frontend/shared",
10+
"//cmd/gitserver/shared",
11+
"//cmd/repo-updater/shared",
12+
"//cmd/searcher/shared",
13+
"//cmd/worker/shared",
14+
"//internal/sanitycheck",
15+
"//internal/service",
16+
],
17+
)
18+
19+
go_binary(
20+
name = "sourcegraph",
21+
embed = [":sourcegraph_lib"],
22+
visibility = ["//visibility:public"],
23+
)

cmd/sourcegraph/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Single-program distribution (dev only)
2+
3+
Run `sg start single-program-experimental-blame-sqs` to run Sourcegraph locally with some services. This can be faster than `sg start`, which runs more services and compiles/runs them each individually.
4+
5+
Use at your own risk, and blame @sqs if this has any problems.
6+
7+
**Status:** only for local dev

cmd/sourcegraph/main.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package main
2+
3+
import (
4+
"github.com/sourcegraph/sourcegraph/internal/sanitycheck"
5+
"github.com/sourcegraph/sourcegraph/internal/service"
6+
7+
frontend_shared "github.com/sourcegraph/sourcegraph/cmd/frontend/shared"
8+
gitserver_shared "github.com/sourcegraph/sourcegraph/cmd/gitserver/shared"
9+
repoupdater_shared "github.com/sourcegraph/sourcegraph/cmd/repo-updater/shared"
10+
searcher_shared "github.com/sourcegraph/sourcegraph/cmd/searcher/shared"
11+
worker_shared "github.com/sourcegraph/sourcegraph/cmd/worker/shared"
12+
)
13+
14+
func main() {
15+
sanitycheck.Pass()
16+
17+
// Other services to run (in addition to `frontend`).
18+
otherServices := []service.Service{
19+
gitserver_shared.Service,
20+
repoupdater_shared.Service,
21+
searcher_shared.Service,
22+
worker_shared.Service,
23+
}
24+
25+
frontend_shared.FrontendMain(otherServices)
26+
}

0 commit comments

Comments
 (0)