Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
Revert "feat: deprecate external url cli option (#6781)" (#6788)
Danny Xub002da0dbc95
diff --git a/backend/bin/server/cmd/profile.go b/backend/bin/server/cmd/profile.goindex 89a2d3cbd8..c5aafe6b04 100644--- a/backend/bin/server/cmd/profile.go+++ b/backend/bin/server/cmd/profile.go@@ -16,6 +16,7 @@ func getBaseProfile(dataDir string) config.Profile {}return config.Profile{+ ExternalURL: flags.externalURL,GrpcPort: flags.port + 1, // Using flags.port + 1 as our gRPC server port.DatastorePort: flags.port + 2, // Using flags.port + 2 as our datastore port.SampleDatabasePort: flags.port + 3, // Using flags.port + 3 as our sample database port.diff --git a/backend/bin/server/cmd/root.go b/backend/bin/server/cmd/root.goindex 8395bc24d2..41e0ded369 100644--- a/backend/bin/server/cmd/root.go+++ b/backend/bin/server/cmd/root.go@@ -16,6 +16,7 @@ import ("github.com/spf13/cobra""go.uber.org/zap"+ "github.com/bytebase/bytebase/backend/common""github.com/bytebase/bytebase/backend/common/log""github.com/bytebase/bytebase/backend/server")@@ -58,8 +59,9 @@ ________________________________________________________________________________var (flags struct {// Used for Bytebase command line config- port int- dataDir string+ port int+ externalURL string+ dataDir string// When we are running in readonly mode:// - The data file will be opened in readonly mode, no applicable migration or seeding will be applied.// - Requests other than GET will be rejected@@ -107,6 +109,11 @@ func init() {// Instead they would configure a gateway to forward the traffic to Bytebase. Users need to set --external-url to the address// exposed on that gateway accordingly.//+ // It's important to set the correct --external-url. This is used for:+ // 1. Constructing the correct callback URL when configuring the VCS provider. The callback URL points to the frontend.+ // 2. Creating the correct webhook endpoint when configuring the project GitOps workflow. The webhook endpoint points to the backend.+ // Since frontend and backend are bundled and run on the same address in the release build, thus we just need to specify a single external URL.+ rootCmd.PersistentFlags().StringVar(&flags.externalURL, "external-url", "", "the external URL where user visits Bytebase, must start with http:// or https://")rootCmd.PersistentFlags().StringVar(&flags.dataDir, "data", ".", "directory where Bytebase stores data. If relative path is supplied, then the path is relative to the directory where Bytebase is under")rootCmd.PersistentFlags().BoolVar(&flags.readonly, "readonly", false, "whether to run in read-only mode")rootCmd.PersistentFlags().BoolVar(&flags.saas, "saas", false, "whether to run in SaaS mode")@@ -182,6 +189,13 @@ func start() {var err error+ if flags.externalURL != "" {+ flags.externalURL, err = common.NormalizeExternalURL(flags.externalURL)+ if err != nil {+ log.Error("invalid --external-url", zap.Error(err))+ return+ }+ }if err := checkDataDir(); err != nil {log.Error(err.Error())returndiff --git a/backend/component/config/profile.go b/backend/component/config/profile.goindex 5747684d5a..3858a2b9b2 100644--- a/backend/component/config/profile.go+++ b/backend/component/config/profile.go@@ -12,6 +12,8 @@ import (type Profile struct {// Mode can be "prod" or "dev"Mode common.ReleaseMode+ // ExternalURL is the URL user visits Bytebase.+ ExternalURL string// DatastorePort is the binding port for database instance for storing Bytebase metadata.// Only applicable when using embedded PG (PgURL is empty).DatastorePort intdiff --git a/backend/server/server.go b/backend/server/server.goindex 9f81b0acdc..7040c0f0cc 100644--- a/backend/server/server.go+++ b/backend/server/server.go@@ -342,7 +342,7 @@ func NewServer(ctx context.Context, profile config.Profile) (*Server, error) {// Cache the license.s.licenseService.LoadSubscription(ctx)- config, err := getInitSetting(ctx, storeInstance)+ config, err := s.getInitSetting(ctx, storeInstance)if err != nil {return nil, errors.Wrap(err, "failed to init config")}@@ -731,7 +731,7 @@ type workspaceConfig struct {workspaceID string}-func getInitSetting(ctx context.Context, datastore *store.Store) (*workspaceConfig, error) {+func (s *Server) getInitSetting(ctx context.Context, datastore *store.Store) (*workspaceConfig, error) {// secretLength is the length for the secret used to sign the JWT auto token.const secretLength = 32@@ -844,7 +844,7 @@ func getInitSetting(ctx context.Context, datastore *store.Store) (*workspaceConf// initial workspace profile settingsettingName := api.SettingWorkspaceProfile- workspaceProfileSetting, err := datastore.GetSettingV2(ctx, &store.FindSettingMessage{+ workspaceProfileSetting, err := s.store.GetSettingV2(ctx, &store.FindSettingMessage{Name: &settingName,Enforce: true,})@@ -852,12 +852,17 @@ func getInitSetting(ctx context.Context, datastore *store.Store) (*workspaceConfreturn nil, err}- workspaceProfilePayload := &storepb.WorkspaceProfileSetting{}+ workspaceProfilePayload := &storepb.WorkspaceProfileSetting{+ ExternalUrl: s.profile.ExternalURL,+ }if workspaceProfileSetting != nil {workspaceProfilePayload = new(storepb.WorkspaceProfileSetting)if err := protojson.Unmarshal([]byte(workspaceProfileSetting.Value), workspaceProfilePayload); err != nil {return nil, err}+ if s.profile.ExternalURL != "" {+ workspaceProfilePayload.ExternalUrl = s.profile.ExternalURL+ }}bytes, err := protojson.Marshal(workspaceProfilePayload)diff --git a/backend/tests/tests.go b/backend/tests/tests.goindex b04be71738..c981b81a99 100644--- a/backend/tests/tests.go+++ b/backend/tests/tests.go@@ -157,7 +157,6 @@ CREATE TABLE book4 ()type controller struct {- externalURL stringserver *server.Serverprofile componentConfig.Profileclient *http.Client@@ -266,7 +265,6 @@ func (ctl *controller) StartServerWithExternalPg(ctx context.Context, config *co}ctl.server = serverctl.profile = profile- ctl.externalURL = fmt.Sprintf("http://localhost:%d", serverPort)metaCtx, err := ctl.start(ctx, serverPort)if err != nil {@@ -292,7 +290,6 @@ func (ctl *controller) StartServer(ctx context.Context, config *config) (context}ctl.server = serverctl.profile = profile- ctl.externalURL = fmt.Sprintf("http://localhost:%d", serverPort)return ctl.start(ctx, serverPort)}@@ -304,7 +301,7 @@ func (ctl *controller) initWorkspaceProfile(ctx context.Context) error {Value: &v1pb.Value{Value: &v1pb.Value_WorkspaceProfileSettingValue{WorkspaceProfileSettingValue: &v1pb.WorkspaceProfileSetting{- ExternalUrl: ctl.externalURL,+ ExternalUrl: ctl.profile.ExternalURL,DisallowSignup: false,},},@@ -319,6 +316,7 @@ func (ctl *controller) initWorkspaceProfile(ctx context.Context) error {func getTestProfile(dataDir, resourceDir string, port int, readOnly bool, feishuAPIURL string) componentConfig.Profile {return componentConfig.Profile{Mode: testReleaseMode,+ ExternalURL: fmt.Sprintf("http://localhost:%d", port),GrpcPort: port + 1,DatastorePort: port + 2,SampleDatabasePort: 0,@@ -339,6 +337,7 @@ func getTestProfile(dataDir, resourceDir string, port int, readOnly bool, feishufunc getTestProfileWithExternalPg(dataDir, resourceDir string, port int, pgUser string, pgURL string, feishuAPIURL string, skipOnboardingData bool) componentConfig.Profile {return componentConfig.Profile{Mode: testReleaseMode,+ ExternalURL: fmt.Sprintf("http://localhost:%d", port),GrpcPort: port + 1,SampleDatabasePort: 0,PgUser: pgUser,