mirror of https://github.com/harness/drone.git
[MISC] Replace `BIND` with `PORT`, fix space_path for postgres (#607)
parent
1246bd78ab
commit
5ca48e7f59
|
@ -61,16 +61,7 @@ func LoadConfig() (*types.Config, error) {
|
|||
|
||||
func backfillURLs(config *types.Config) error {
|
||||
// default base url
|
||||
scheme, host, port, path := "http", "localhost", "3000", ""
|
||||
|
||||
// override default with whatever server bind provided
|
||||
bindHost, bindPort, _ := strings.Cut(config.Server.HTTP.Bind, ":")
|
||||
if bindHost != "" {
|
||||
host = bindHost
|
||||
}
|
||||
if bindPort != "" {
|
||||
port = bindPort
|
||||
}
|
||||
scheme, host, port, path := "http", "localhost", fmt.Sprint(config.Server.HTTP.Port), ""
|
||||
|
||||
// TODO: handle https of server bind
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ import (
|
|||
|
||||
func TestBackfilURLsPortBind(t *testing.T) {
|
||||
config := &types.Config{}
|
||||
config.Server.HTTP.Bind = ":1234"
|
||||
config.Server.HTTP.Port = 1234
|
||||
|
||||
err := backfillURLs(config)
|
||||
require.NoError(t, err)
|
||||
|
@ -35,23 +35,9 @@ func TestBackfilURLsPortBind(t *testing.T) {
|
|||
require.Equal(t, "http://host.docker.internal:1234/git", config.URL.GitContainer)
|
||||
}
|
||||
|
||||
func TestBackfilURLsHostBind(t *testing.T) {
|
||||
config := &types.Config{}
|
||||
config.Server.HTTP.Bind = "abc:1234"
|
||||
|
||||
err := backfillURLs(config)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, "http://abc:1234/api", config.URL.API)
|
||||
require.Equal(t, "http://abc:1234/git", config.URL.Git)
|
||||
require.Equal(t, "http://abc:1234", config.URL.UI)
|
||||
require.Equal(t, "http://localhost:1234/api", config.URL.APIInternal)
|
||||
require.Equal(t, "http://host.docker.internal:1234/git", config.URL.GitContainer)
|
||||
}
|
||||
|
||||
func TestBackfilURLsBase(t *testing.T) {
|
||||
config := &types.Config{}
|
||||
config.Server.HTTP.Bind = "abc:1234"
|
||||
config.Server.HTTP.Port = 1234
|
||||
config.URL.Base = "https://xyz:4321/test"
|
||||
|
||||
err := backfillURLs(config)
|
||||
|
@ -66,7 +52,7 @@ func TestBackfilURLsBase(t *testing.T) {
|
|||
|
||||
func TestBackfilURLsCustom(t *testing.T) {
|
||||
config := &types.Config{}
|
||||
config.Server.HTTP.Bind = "abc:1234"
|
||||
config.Server.HTTP.Port = 1234
|
||||
config.URL.Base = "https://xyz:4321/test"
|
||||
config.URL.API = "http://API:1111/API/p"
|
||||
config.URL.APIInternal = "http://APIInternal:1111/APIInternal/p"
|
||||
|
|
|
@ -119,7 +119,7 @@ func (c *command) run(*kingpin.ParseContext) error {
|
|||
}
|
||||
|
||||
log.Info().
|
||||
Str("port", config.Server.HTTP.Bind).
|
||||
Int("port", config.Server.HTTP.Port).
|
||||
Str("revision", version.GitCommit).
|
||||
Str("repository", version.GitRepository).
|
||||
Stringer("version", version.Version).
|
||||
|
|
|
@ -27,8 +27,8 @@ const (
|
|||
|
||||
// Config represents the configuration for the gitrpc server.
|
||||
type Config struct {
|
||||
// Bind specifies the addr used to bind the grpc server.
|
||||
Bind string `envconfig:"GITRPC_SERVER_BIND" default:":3001"`
|
||||
// Port specifies the port used to bind the grpc server.
|
||||
Port int `envconfig:"GITRPC_SERVER_PORT" default:"3001"`
|
||||
// GitRoot specifies the directory containing git related data (e.g. repos, ...)
|
||||
GitRoot string `envconfig:"GITRPC_SERVER_GIT_ROOT"`
|
||||
// TmpDir (optional) specifies the directory for temporary data (e.g. repo clones, ...)
|
||||
|
@ -37,7 +37,7 @@ type Config struct {
|
|||
GitHookPath string `envconfig:"GITRPC_SERVER_GIT_HOOK_PATH"`
|
||||
|
||||
HTTP struct {
|
||||
Bind string `envconfig:"GITRPC_SERVER_HTTP_BIND" default:":4001"`
|
||||
Port int `envconfig:"GITRPC_SERVER_HTTP_PORT" default:"4001"`
|
||||
}
|
||||
MaxConnAge time.Duration `envconfig:"GITRPC_SERVER_MAX_CONN_AGE" default:"630720000s"`
|
||||
MaxConnAgeGrace time.Duration `envconfig:"GITRPC_SERVER_MAX_CONN_AGE_GRACE" default:"630720000s"`
|
||||
|
@ -66,23 +66,23 @@ func (c *Config) Validate() error {
|
|||
if c == nil {
|
||||
return errors.New("config is required")
|
||||
}
|
||||
if c.Bind == "" {
|
||||
return errors.New("config.Bind is required")
|
||||
if c.Port < 0 {
|
||||
return errors.New("Port is required")
|
||||
}
|
||||
if c.GitRoot == "" {
|
||||
return errors.New("config.GitRoot is required")
|
||||
return errors.New("GitRoot is required")
|
||||
}
|
||||
if c.GitHookPath == "" {
|
||||
return errors.New("config.GitHookPath is required")
|
||||
return errors.New("GitHookPath is required")
|
||||
}
|
||||
if c.MaxConnAge == 0 {
|
||||
return errors.New("config.MaxConnAge is required")
|
||||
return errors.New("MaxConnAge is required")
|
||||
}
|
||||
if c.MaxConnAgeGrace == 0 {
|
||||
return errors.New("config.MaxConnAgeGrace is required")
|
||||
return errors.New("MaxConnAgeGrace is required")
|
||||
}
|
||||
if m := c.LastCommitCache.Mode; m != "" && m != ModeInMemory && m != ModeRedis && m != ModeNone {
|
||||
return errors.New("config.LastCommitCache.Mode has unsupported value")
|
||||
return errors.New("LastCommitCache.Mode has unsupported value")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -57,7 +57,7 @@ func NewHTTPServer(config Config) (*HTTPServer, error) {
|
|||
return &HTTPServer{
|
||||
gitnesshttp.NewServer(
|
||||
gitnesshttp.Config{
|
||||
Addr: config.HTTP.Bind,
|
||||
Port: config.HTTP.Port,
|
||||
},
|
||||
handleHTTP(reposRoot),
|
||||
),
|
||||
|
|
|
@ -39,7 +39,7 @@ const (
|
|||
|
||||
type GRPCServer struct {
|
||||
*grpc.Server
|
||||
Bind string
|
||||
Port int
|
||||
}
|
||||
|
||||
func NewServer(config Config, adapter service.GitAdapter) (*GRPCServer, error) {
|
||||
|
@ -124,12 +124,12 @@ func NewServer(config Config, adapter service.GitAdapter) (*GRPCServer, error) {
|
|||
|
||||
return &GRPCServer{
|
||||
Server: s,
|
||||
Bind: config.Bind,
|
||||
Port: config.Port,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *GRPCServer) Start() error {
|
||||
lis, err := net.Listen("tcp", s.Bind)
|
||||
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", s.Port))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -17,7 +17,9 @@ package http
|
|||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"golang.org/x/crypto/acme/autocert"
|
||||
|
@ -33,7 +35,7 @@ const (
|
|||
// TODO: expose via options?
|
||||
type Config struct {
|
||||
Acme bool
|
||||
Addr string
|
||||
Port int
|
||||
Cert string
|
||||
Key string
|
||||
AcmeHost string
|
||||
|
@ -74,7 +76,7 @@ func (s *Server) ListenAndServe() (*errgroup.Group, ShutdownFunction) {
|
|||
func (s *Server) listenAndServe() (*errgroup.Group, ShutdownFunction) {
|
||||
var g errgroup.Group
|
||||
s1 := &http.Server{
|
||||
Addr: s.config.Addr,
|
||||
Addr: fmt.Sprintf(":%d", s.config.Port),
|
||||
ReadHeaderTimeout: s.config.ReadHeaderTimeout,
|
||||
Handler: s.handler,
|
||||
}
|
||||
|
@ -161,6 +163,7 @@ func (s Server) listenAndServeAcme() (*errgroup.Group, ShutdownFunction) {
|
|||
}
|
||||
|
||||
func redirect(w http.ResponseWriter, req *http.Request) {
|
||||
target := "https://" + req.Host + req.URL.Path
|
||||
// TODO: in case of reverse-proxy the host might be not the external host.
|
||||
target := "https://" + req.Host + "/" + strings.TrimPrefix(req.URL.Path, "/")
|
||||
http.Redirect(w, req, target, http.StatusTemporaryRedirect)
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ func ProvideServer(config *types.Config, router *router.Router) *Server {
|
|||
return &Server{
|
||||
http.NewServer(
|
||||
http.Config{
|
||||
Addr: config.Server.HTTP.Bind,
|
||||
Port: config.Server.HTTP.Port,
|
||||
Acme: config.Server.Acme.Enabled,
|
||||
AcmeHost: config.Server.Acme.Host,
|
||||
},
|
||||
|
|
|
@ -143,8 +143,8 @@ func (s *SpacePathStore) FindPrimaryBySpaceID(ctx context.Context, spaceID int64
|
|||
}, nil
|
||||
}
|
||||
func (s *SpacePathStore) FindByPath(ctx context.Context, path string) (*types.SpacePath, error) {
|
||||
const sqlQueryParent = spacePathSelectBase + ` WHERE space_path_uid_unique = $1 AND space_path_parent_id = $2`
|
||||
const sqlQueryNoParent = spacePathSelectBase + ` WHERE space_path_uid_unique = $1 AND space_path_parent_id IS NULL`
|
||||
const sqlQueryParent = spacePathSelectBase + ` WHERE space_path_uid_unique = $1 AND space_path_parent_id = $2`
|
||||
|
||||
db := dbtx.GetAccessor(ctx, s.db)
|
||||
segment := new(spacePathSegment)
|
||||
|
@ -154,13 +154,18 @@ func (s *SpacePathStore) FindByPath(ctx context.Context, path string) (*types.Sp
|
|||
return nil, fmt.Errorf("path with no segments was passed '%s'", path)
|
||||
}
|
||||
|
||||
var err error
|
||||
var parentID int64
|
||||
sqlquery := sqlQueryNoParent
|
||||
originalPath := ""
|
||||
isPrimary := true
|
||||
for i, segmentUID := range segmentUIDs {
|
||||
uniqueSegmentUID := s.spacePathTransformation(segmentUID, i == 0)
|
||||
err := db.GetContext(ctx, segment, sqlquery, uniqueSegmentUID, parentID)
|
||||
|
||||
if parentID == 0 {
|
||||
err = db.GetContext(ctx, segment, sqlQueryNoParent, uniqueSegmentUID)
|
||||
} else {
|
||||
err = db.GetContext(ctx, segment, sqlQueryParent, uniqueSegmentUID, parentID)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, database.ProcessSQLErrorf(err, "Failed to find segment for '%s' in '%s'", uniqueSegmentUID, path)
|
||||
}
|
||||
|
@ -168,7 +173,6 @@ func (s *SpacePathStore) FindByPath(ctx context.Context, path string) (*types.Sp
|
|||
originalPath = paths.Concatinate(originalPath, segment.UID)
|
||||
parentID = segment.SpaceID
|
||||
isPrimary = isPrimary && segment.IsPrimary.ValueOrZero()
|
||||
sqlquery = sqlQueryParent
|
||||
}
|
||||
|
||||
return &types.SpacePath{
|
||||
|
|
|
@ -93,7 +93,7 @@ type Config struct {
|
|||
Server struct {
|
||||
// HTTP defines the http configuration parameters
|
||||
HTTP struct {
|
||||
Bind string `envconfig:"GITNESS_HTTP_BIND" default:":3000"`
|
||||
Port int `envconfig:"GITNESS_HTTP_PORT" default:"3000"`
|
||||
Proto string `envconfig:"GITNESS_HTTP_PROTO" default:"http"`
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue