all: better default env vars for App (#47142)

Previously one needed to specify all of these env vars in order to run the `sourcegraph` App:

```
SRC_FRONTEND_INTERNAL=localhost:3090
EXECUTOR_FRONTEND_PASSWORD=asdf
```

After this, just running `sourcegraph` is enough.

* `EXECUTOR_FRONTEND_PASSWORD`, although it is ignored in the App deployment type,
  must be set to _something_ otherwise a validation error will occur.

Signed-off-by: Stephen Gutekanst <stephen@sourcegraph.com>
This commit is contained in:
Stephen Gutekanst 2023-01-31 05:18:25 -07:00 committed by GitHub
parent 7d8b85ec9c
commit a4eaada3ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 2 deletions

View File

@ -50,7 +50,7 @@ import (
)
var (
printLogo, _ = strconv.ParseBool(env.Get("LOGO", "false", "print Sourcegraph logo upon startup"))
printLogo, _ = strconv.ParseBool(env.Get("LOGO", defaultPrintLogo(), "print Sourcegraph logo upon startup"))
httpAddr = env.Get("SRC_HTTP_ADDR", func() string {
if env.InsecureDev {
@ -66,6 +66,14 @@ var (
prodExtension = "chrome-extension://dgjhfomjieaadpoljlnidmbgkdffpack"
)
func defaultPrintLogo() string {
isSingleProgram := deploy.IsDeployTypeSingleProgram(deploy.Type())
if isSingleProgram {
return "true"
}
return "false"
}
// InitDB initializes and returns the global database connection and sets the
// version of the frontend in our versions table.
func InitDB(logger sglog.Logger) (*sql.DB, error) {

View File

@ -14,13 +14,22 @@ import (
"github.com/sourcegraph/sourcegraph/internal/actor"
"github.com/sourcegraph/sourcegraph/internal/api"
"github.com/sourcegraph/sourcegraph/internal/conf/conftypes"
"github.com/sourcegraph/sourcegraph/internal/conf/deploy"
"github.com/sourcegraph/sourcegraph/internal/env"
"github.com/sourcegraph/sourcegraph/internal/httpcli"
"github.com/sourcegraph/sourcegraph/internal/txemail/txtypes"
"github.com/sourcegraph/sourcegraph/lib/errors"
)
var frontendInternal = env.Get("SRC_FRONTEND_INTERNAL", "sourcegraph-frontend-internal", "HTTP address for internal frontend HTTP API.")
var frontendInternal = env.Get("SRC_FRONTEND_INTERNAL", defaultFrontendInternal(), "HTTP address for internal frontend HTTP API.")
func defaultFrontendInternal() string {
isSingleProgram := deploy.IsDeployTypeSingleProgram(deploy.Type())
if isSingleProgram {
return "localhost:3090"
}
return "sourcegraph-frontend-internal"
}
type internalClient struct {
// URL is the root to the internal API frontend server.

View File

@ -114,6 +114,14 @@ func Init(logger log.Logger) {
// We disable the use of executors passwords, because executors only listen on `localhost` this
// is safe to do.
setDefaultEnv(logger, "EXECUTOR_FRONTEND_URL", "http://localhost:3080")
setDefaultEnv(logger, "EXECUTOR_FRONTEND_PASSWORD", confdefaults.SingleProgramInMemoryExecutorPassword)
// TODO(single-binary): HACK: This is a hack to workaround the fact that the 2nd time you run `sourcegraph`
// OOB migration validation fails:
//
// {"SeverityText":"FATAL","Timestamp":1675128552556359000,"InstrumentationScope":"sourcegraph","Caller":"svcmain/svcmain.go:143","Function":"github.com/sourcegraph/sourcegraph/internal/service/svcmain.run.func1","Body":"failed to start service","Resource":{"service.name":"sourcegraph","service.version":"0.0.196384-snapshot+20230131-6902ad","service.instance.id":"Stephens-MacBook-Pro.local"},"Attributes":{"service":"frontend","error":"failed to validate out of band migrations: Unfinished migrations. Please revert Sourcegraph to the previous version and wait for the following migrations to complete.\n - migration 1 expected to be at 0.00% (at 100.00%)\n - migration 13 expected to be at 0.00% (at 100.00%)\n - migration 14 expected to be at 0.00% (at 100.00%)\n - migration 15 expected to be at 0.00% (at 100.00%)\n - migration 16 expected to be at 0.00% (at 100.00%)\n - migration 17 expected to be at 0.00% (at 100.00%)\n - migration 18 expected to be at 0.00% (at 100.00%)\n - migration 19 expected to be at 0.00% (at 100.00%)\n - migration 2 expected to be at 0.00% (at 100.00%)\n - migration 20 expected to be at 0.00% (at 100.00%)\n - migration 4 expected to be at 0.00% (at 100.00%)\n - migration 5 expected to be at 0.00% (at 100.00%)\n - migration 7 expected to be at 0.00% (at 100.00%)"}}
//
setDefaultEnv(logger, "SRC_DISABLE_OOBMIGRATION_VALIDATION", "1")
setDefaultEnv(logger, "EXECUTOR_USE_FIRECRACKER", "false")
// TODO(sqs): TODO(single-binary): Make it so we can run multiple executors in single-program mode. Right now, you