diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c4d2b08c81b0899be69370b3f95123de250a649f..f2df57eeb8a817e2356ad52ec78fe9281b5b9074 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -42,7 +42,6 @@ lint: - branches variables: - $CI_COMMIT_REF_SLUG != "master" - when: manual build-binary-alpine: image: golang:1.17-alpine @@ -58,14 +57,14 @@ build-binary-alpine: - apk add --update --no-cache make git - make build -build-binary-client-linux: +build-binary-client-dev: <<: *only_feature stage: build-binary artifacts: paths: - bin script: - - go build -o bin/dblab-linux-amd64 ./cmd/cli/main.go + - make build-client build-binary-client: <<: *only_tag_release @@ -88,7 +87,6 @@ build-binary-client: build-binary-client-rc: <<: *only_tag_rc stage: build-binary - when: manual script: - make build-client @@ -159,7 +157,7 @@ build-image-feature-client-extended: DOCKER_NAME: "registry.gitlab.com/postgres-ai/database-lab/dblab-extended" TAGS: "${DOCKER_NAME}:${CI_COMMIT_REF_SLUG}" before_script: - - cp ./bin/dblab-linux-amd64 ./bin/dblab + - cp ./bin/cli/dblab-linux-amd64 ./bin/dblab build-image-master-server: <<: *build_image_definition diff --git a/cmd/database-lab/main.go b/cmd/database-lab/main.go index 149612398058ff75dd55be454fed08540b95a7d0..e4fac27c7473e557b7c99f243805cb5d769b004e 100644 --- a/cmd/database-lab/main.go +++ b/cmd/database-lab/main.go @@ -175,8 +175,6 @@ func main() { log.Err("Failed to start local UI container:", err.Error()) return } - - log.Msg("Local UI has started successfully") }() } diff --git a/configs/config.example.logical_generic.yml b/configs/config.example.logical_generic.yml index 98e7c69e13b51761ce6f2bf604e1c1b9656704c4..b3fd37bbf3e7c50052f23bc67471bb70d117f792 100644 --- a/configs/config.example.logical_generic.yml +++ b/configs/config.example.logical_generic.yml @@ -15,13 +15,11 @@ server: # their personal tokens generated on the Platform. In this case, # it is recommended to keep "verificationToken" secret, known # only to the administrator of the Database Lab instance. + # + # Database Lab Engine can be running with an empty verification token, which is not recommended. + # In this case, the DLE API and the UI application will not require any credentials. verificationToken: "secret_token" - # The host to which the Database Lab server accepts HTTP connections. - # By default uses an empty string to accept connections to all network interfaces. - # Keep it default when running inside a Docker container. - host: "" - # HTTP server port. Default: 2345. port: 2345 diff --git a/configs/config.example.logical_rds_iam.yml b/configs/config.example.logical_rds_iam.yml index 796be79fb491ca9bc770654977816e25d01230e6..15aee308f5908b258ebde5083386ec5161d57a2c 100644 --- a/configs/config.example.logical_rds_iam.yml +++ b/configs/config.example.logical_rds_iam.yml @@ -15,13 +15,11 @@ server: # their personal tokens generated on the Platform. In this case, # it is recommended to keep "verificationToken" secret, known # only to the administrator of the Database Lab instance. + # + # Database Lab Engine can be running with an empty verification token, which is not recommended. + # In this case, the DLE API and the UI application will not require any credentials. verificationToken: "secret_token" - # The host to which the Database Lab server accepts HTTP connections. - # By default uses an empty string to accept connections to all network interfaces. - # Keep it default when running inside a Docker container. - host: "" - # HTTP server port. Default: 2345. port: 2345 diff --git a/configs/config.example.physical_generic.yml b/configs/config.example.physical_generic.yml index 3b04b22e26489b85ba95e847d7b0b89e2963c8c7..e8c32f4d934917d6f8f89b87a0da5022b2e02f69 100644 --- a/configs/config.example.physical_generic.yml +++ b/configs/config.example.physical_generic.yml @@ -15,13 +15,11 @@ server: # their personal tokens generated on the Platform. In this case, # it is recommended to keep "verificationToken" secret, known # only to the administrator of the Database Lab instance. + # + # Database Lab Engine can be running with an empty verification token, which is not recommended. + # In this case, the DLE API and the UI application will not require any credentials. verificationToken: "secret_token" - # The host to which the Database Lab server accepts HTTP connections. - # By default uses an empty string to accept connections to all network interfaces. - # Keep it default when running inside a Docker container. - host: "" - # HTTP server port. Default: 2345. port: 2345 diff --git a/configs/config.example.physical_walg.yml b/configs/config.example.physical_walg.yml index 8b1a4f1104d269a15425f80e5f846203d077ac2a..f54398b2e38f87e4ff6051c9ad0e193efb4c3dea 100644 --- a/configs/config.example.physical_walg.yml +++ b/configs/config.example.physical_walg.yml @@ -15,13 +15,11 @@ server: # their personal tokens generated on the Platform. In this case, # it is recommended to keep "verificationToken" secret, known # only to the administrator of the Database Lab instance. + # + # Database Lab Engine can be running with an empty verification token, which is not recommended. + # In this case, the DLE API and the UI application will not require any credentials. verificationToken: "secret_token" - # The host to which the Database Lab server accepts HTTP connections. - # By default uses an empty string to accept connections to all network interfaces. - # Keep it default when running inside a Docker container. - host: "" - # HTTP server port. Default: 2345. port: 2345 diff --git a/internal/localui/local_ui.go b/internal/localui/local_ui.go index 501c09dd2f2b85351eddafc234573b7d716b07ba..fee0833a7a130d865f869dfdcd369410aebdb235 100644 --- a/internal/localui/local_ui.go +++ b/internal/localui/local_ui.go @@ -22,6 +22,8 @@ import ( "gitlab.com/postgres-ai/database-lab/v3/internal/retrieval/engine/postgres/tools" "gitlab.com/postgres-ai/database-lab/v3/internal/retrieval/engine/postgres/tools/cont" "gitlab.com/postgres-ai/database-lab/v3/pkg/config/global" + "gitlab.com/postgres-ai/database-lab/v3/pkg/log" + "gitlab.com/postgres-ai/database-lab/v3/pkg/util/engine" "gitlab.com/postgres-ai/database-lab/v3/pkg/util/networks" ) @@ -138,6 +140,8 @@ func (ui *UIManager) Run(ctx context.Context) error { return fmt.Errorf("failed to start container %q: %w", localUI.ID, err) } + reportLaunching(ui.cfg) + return nil } @@ -160,3 +164,14 @@ func (ui *UIManager) Stop(ctx context.Context) { func getLocalUIName(instanceID string) string { return cont.DBLabLocalUILabel + "_" + instanceID } + +// reportLaunching reports the launch of the LocalUI container. +func reportLaunching(cfg Config) { + host := engine.DefaultListenerHost + + if cfg.Host != "" { + host = cfg.Host + } + + log.Msg(fmt.Sprintf("Local UI has started successfully on %s:%d.", host, cfg.Port)) +} diff --git a/internal/srv/routes.go b/internal/srv/routes.go index 690aadcbe239a8297cc8444600bc943dd330d815..36e4df2a507b202427351ff2468c4db94a96801a 100644 --- a/internal/srv/routes.go +++ b/internal/srv/routes.go @@ -80,7 +80,14 @@ func (s *Server) createClone(w http.ResponseWriter, r *http.Request) { newClone, err := s.Cloning.CreateClone(cloneRequest) if err != nil { + var reqErr *models.Error + if errors.As(err, &reqErr) { + api.SendBadRequestError(w, r, reqErr.Error()) + return + } + api.SendError(w, r, errors.Wrap(err, "failed to create clone")) + return } diff --git a/internal/srv/server.go b/internal/srv/server.go index d7f6f2f7d730b110ccba63e82dfa1c83af895cd6..120d6201a73028102a23ab05a7236f5d8ffc6b4a 100644 --- a/internal/srv/server.go +++ b/internal/srv/server.go @@ -144,7 +144,7 @@ func (s *Server) InitHandlers() { // Run starts HTTP server on specified port in configuration. func (s *Server) Run() error { - log.Msg(fmt.Sprintf("Server started listening on %s:%d.", s.Config.Host, s.Config.Port)) + reportLaunching(s.Config) return s.httpSrv.ListenAndServe() } @@ -158,3 +158,8 @@ func (s *Server) Shutdown(ctx context.Context) error { func (s *Server) Uptime() float64 { return time.Since(s.startedAt).Truncate(time.Second).Seconds() } + +// reportLaunching reports the launch of the HTTP server. +func reportLaunching(cfg *srvCfg.Config) { + log.Msg(fmt.Sprintf("API server started listening on %s:%d.", cfg.Host, cfg.Port)) +} diff --git a/pkg/util/engine/engine.go b/pkg/util/engine/engine.go new file mode 100644 index 0000000000000000000000000000000000000000..3a0b779acc53f977f0175150d4d7fdbbe86557b5 --- /dev/null +++ b/pkg/util/engine/engine.go @@ -0,0 +1,9 @@ +/* +2021 © Postgres.ai +*/ + +// Package engine contains tools. +package engine + +// DefaultListenerHost defines the default host of an HTTP listener. +const DefaultListenerHost = "0.0.0.0"