mirror of https://github.com/harness/drone.git
feat: [CDE-140]: Adding docker machine host name config to identify the public host name on which the docker host is running. Updated the docker config to read from the default docker env variables if config values are not set. Updated the events timestamp to use nanoseconds. Fixed the working directory response and cleaned the logic of how the gitspace instance url is generated. Updated the scm service to parse repo name in a provider agnostic manner. (#2201)
* feat: [CDE-140]: Fixing ProvideGitspaceContainerOrchestratorConfig. * feat: [CDE-140]: Fixing ProvideGitspaceContainerOrchestratorConfig. * feat: [CDE-140]: Addressing review comments. * feat: [CDE-140]: Reverting changes done for docker config default values. Adding default value of GITNESS_GITSPACE_DEFAULT_BIND_MOUNT_SOURCE_BASE_PATH and GITNESS_DOCKER_HOST to Dockerfile. Adding new column in gitspace_events table for storing event timestamp in nanoseconds and corresponding migrations. * Lingting. * feat: [CDE-140]: Adding docker machine host name config to identify the public host name on which the docker host is running. Updated the docker config to read from the default docker env variables if config values are not set. Updated the events timestamp to use nanoseconds. Fixed the working directory response and cleaned the logic of how the gitspace instance url is generated. Updated the scm service to parse repo name in a provider agnostic manner.unified-ui
parent
0a5ed06f02
commit
b9d3bb4d2b
|
@ -82,6 +82,8 @@ ENV GITNESS_DATABASE_DATASOURCE /data/database.sqlite
|
|||
ENV GITNESS_METRIC_ENABLED=true
|
||||
ENV GITNESS_METRIC_ENDPOINT=https://stats.drone.ci/api/v1/gitness
|
||||
ENV GITNESS_TOKEN_COOKIE_NAME=token
|
||||
ENV GITNESS_GITSPACE_DEFAULT_BIND_MOUNT_SOURCE_BASE_PATH /data
|
||||
ENV GITNESS_DOCKER_HOST unix:///var/run/docker.sock
|
||||
|
||||
COPY --from=builder /app/gitness /app/gitness
|
||||
COPY --from=cert-image /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
||||
|
|
|
@ -257,6 +257,6 @@ func (c *Controller) emitGitspaceConfigEvent(
|
|||
EntityID: config.ID,
|
||||
EntityType: enum.GitspaceEntityTypeGitspaceConfig,
|
||||
EventType: eventType,
|
||||
Created: time.Now().UnixMilli(),
|
||||
Timestamp: time.Now().UnixNano(),
|
||||
})
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ func (c *Controller) Events(
|
|||
gitspaceEventResponse := &types.GitspaceEventResponse{
|
||||
GitspaceEvent: *event,
|
||||
Message: eventMessageMap[event.Event],
|
||||
EventTime: time.UnixMilli(event.Created).Format(time.RFC3339)}
|
||||
EventTime: time.Unix(0, event.Timestamp).Format(time.RFC3339Nano)}
|
||||
result[index] = gitspaceEventResponse
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ type (
|
|||
QueryKey string `json:"query_key,omitempty"`
|
||||
EntityType enum.GitspaceEntityType `json:"entity_type,omitempty"`
|
||||
EventType enum.GitspaceEventType `json:"event_type,omitempty"`
|
||||
Created int64 `json:"created,omitempty"`
|
||||
Timestamp int64 `json:"timestamp,omitempty"`
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ import (
|
|||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/harness/gitness/app/gitspace/logutil"
|
||||
"github.com/harness/gitness/infraprovider"
|
||||
|
@ -51,9 +52,10 @@ const (
|
|||
)
|
||||
|
||||
type Config struct {
|
||||
DefaultBaseImage string
|
||||
DefaultBindMountTargetPath string
|
||||
DefaultBindMountSourceBasePath string
|
||||
DefaultBaseImage string
|
||||
DefaultBindMountTargetPath string
|
||||
DefaultBindMountSourceBasePath string
|
||||
DefaultBindMountSourceBasePathAbsolute string
|
||||
}
|
||||
|
||||
type EmbeddedDockerOrchestrator struct {
|
||||
|
@ -182,7 +184,7 @@ func (e *EmbeddedDockerOrchestrator) StartGitspace(
|
|||
return &StartResponse{
|
||||
ContainerID: containerID,
|
||||
ContainerName: containerName,
|
||||
WorkingDirectory: e.config.DefaultBindMountTargetPath,
|
||||
WorkingDirectory: strings.TrimPrefix(e.config.DefaultBindMountTargetPath, "/"),
|
||||
PortsUsed: usedPorts,
|
||||
}, nil
|
||||
}
|
||||
|
@ -509,7 +511,16 @@ func (e *EmbeddedDockerOrchestrator) createContainer(
|
|||
gitspaceConfig.Identifier,
|
||||
)
|
||||
|
||||
loggingErr := logStreamInstance.Write("Creating bind mount source directory: " + bindMountSourcePath)
|
||||
absoluteBindMountSourcePath :=
|
||||
filepath.Join(
|
||||
e.config.DefaultBindMountSourceBasePathAbsolute,
|
||||
gitspacesDir,
|
||||
gitspaceConfig.SpacePath,
|
||||
gitspaceConfig.Identifier,
|
||||
)
|
||||
|
||||
loggingErr := logStreamInstance.Write(
|
||||
"Creating bind mount source directory: " + bindMountSourcePath + " (" + absoluteBindMountSourcePath + " )")
|
||||
if loggingErr != nil {
|
||||
return fmt.Errorf("logging error: %w", loggingErr)
|
||||
}
|
||||
|
@ -548,7 +559,7 @@ func (e *EmbeddedDockerOrchestrator) createContainer(
|
|||
Mounts: []mount.Mount{
|
||||
{
|
||||
Type: mount.TypeBind,
|
||||
Source: bindMountSourcePath,
|
||||
Source: absoluteBindMountSourcePath,
|
||||
Target: e.config.DefaultBindMountTargetPath,
|
||||
},
|
||||
},
|
||||
|
|
|
@ -18,6 +18,7 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
events "github.com/harness/gitness/app/events/gitspace"
|
||||
|
@ -66,11 +67,12 @@ func (o orchestrator) StartGitspace(
|
|||
|
||||
o.emitGitspaceEvent(ctx, gitspaceConfig, enum.GitspaceEventTypeFetchDevcontainerStart)
|
||||
|
||||
devcontainerConfig, err := o.scm.DevcontainerConfig(ctx, gitspaceConfig)
|
||||
repoName, devcontainerConfig, err := o.scm.RepoNameAndDevcontainerConfig(ctx, gitspaceConfig)
|
||||
if err != nil {
|
||||
o.emitGitspaceEvent(ctx, gitspaceConfig, enum.GitspaceEventTypeFetchDevcontainerFailed)
|
||||
|
||||
log.Warn().Err(err).Msg("devcontainer config fetch failed.")
|
||||
return gitspaceInstance,
|
||||
fmt.Errorf("failed to fetch code repo details for gitspace config ID %d", gitspaceConfig.ID)
|
||||
}
|
||||
|
||||
if devcontainerConfig == nil {
|
||||
|
@ -121,39 +123,27 @@ func (o orchestrator) StartGitspace(
|
|||
|
||||
o.emitGitspaceEvent(ctx, gitspaceConfig, enum.GitspaceEventTypeAgentGitspaceCreationCompleted)
|
||||
|
||||
repoName, err := o.scm.RepositoryName(ctx, gitspaceConfig)
|
||||
if err != nil {
|
||||
log.Warn().Err(err).Msg("failed to fetch repository name.")
|
||||
}
|
||||
|
||||
port := startResponse.PortsUsed[gitspaceConfig.IDE]
|
||||
|
||||
var ideURL url.URL
|
||||
|
||||
if infra.Host == "" {
|
||||
// TODO: This fix does not cover all use-cases. Ideally, we need to read the host name
|
||||
// on which this docker is running and set it as the infra.Host. Remove once that change is done.
|
||||
infra.Host = "localhost"
|
||||
}
|
||||
|
||||
if gitspaceConfig.IDE == enum.IDETypeVSCodeWeb {
|
||||
ideURL = url.URL{
|
||||
Scheme: "http",
|
||||
Host: infra.Host + ":" + port,
|
||||
RawQuery: "folder=" + startResponse.WorkingDirectory + "/" + repoName,
|
||||
RawQuery: filepath.Join("folder=", startResponse.WorkingDirectory, repoName),
|
||||
}
|
||||
} else if gitspaceConfig.IDE == enum.IDETypeVSCode {
|
||||
// TODO: the following user ID is hard coded and should be changed.
|
||||
// TODO: the following userID is hard coded and should be changed.
|
||||
userID := "harness"
|
||||
ideURL = url.URL{
|
||||
Scheme: "vscode-remote",
|
||||
Host: "", // Empty since we include the host and port in the path
|
||||
Path: fmt.Sprintf(
|
||||
"ssh-remote+%s@%s:%s/%s/%s",
|
||||
"harness",
|
||||
"ssh-remote+%s@%s:%s",
|
||||
userID,
|
||||
infra.Host,
|
||||
port,
|
||||
startResponse.WorkingDirectory,
|
||||
repoName,
|
||||
filepath.Join(port, startResponse.WorkingDirectory, repoName),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
@ -303,6 +293,6 @@ func (o orchestrator) emitGitspaceEvent(
|
|||
EntityID: config.GitspaceInstance.ID,
|
||||
EntityType: enum.GitspaceEntityTypeGitspaceInstance,
|
||||
EventType: eventType,
|
||||
Created: time.Now().UnixMilli(),
|
||||
Timestamp: time.Now().UnixNano(),
|
||||
})
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import (
|
|||
"io"
|
||||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
|
@ -40,13 +41,15 @@ var (
|
|||
var _ SCM = (*scm)(nil)
|
||||
|
||||
type SCM interface {
|
||||
// DevcontainerConfig fetches devcontainer config file from the given repo and branch.
|
||||
DevcontainerConfig(ctx context.Context, gitspaceConfig *types.GitspaceConfig) (*types.DevcontainerConfig, error)
|
||||
// RepositoryName finds the repository name for the code repo URL from its provider.
|
||||
RepositoryName(ctx context.Context, gitspaceConfig *types.GitspaceConfig) (string, error)
|
||||
// check if the current URL is a valid and accessible code repo, input can be connector info, user token etc.
|
||||
CheckValidCodeRepo(ctx context.Context, request CodeRepositoryRequest,
|
||||
) (*CodeRepositoryResponse, error)
|
||||
// RepoNameAndDevcontainerConfig fetches repository name & devcontainer config file from the given repo and branch.
|
||||
RepoNameAndDevcontainerConfig(
|
||||
ctx context.Context,
|
||||
gitspaceConfig *types.GitspaceConfig,
|
||||
) (string, *types.DevcontainerConfig, error)
|
||||
|
||||
// CheckValidCodeRepo checks if the current URL is a valid and accessible code repo,
|
||||
// input can be connector info, user token etc.
|
||||
CheckValidCodeRepo(ctx context.Context, request CodeRepositoryRequest) (*CodeRepositoryResponse, error)
|
||||
}
|
||||
|
||||
type scm struct{}
|
||||
|
@ -79,17 +82,23 @@ func NewSCM() SCM {
|
|||
return &scm{}
|
||||
}
|
||||
|
||||
func (s scm) DevcontainerConfig(
|
||||
func (s scm) RepoNameAndDevcontainerConfig(
|
||||
ctx context.Context,
|
||||
gitspaceConfig *types.GitspaceConfig,
|
||||
) (*types.DevcontainerConfig, error) {
|
||||
) (string, *types.DevcontainerConfig, error) {
|
||||
repoURL, err := url.Parse(gitspaceConfig.CodeRepoURL)
|
||||
if err != nil {
|
||||
return "", nil, fmt.Errorf("failed to parse repository URL %s: %w", gitspaceConfig.CodeRepoURL, err)
|
||||
}
|
||||
repoName := strings.TrimSuffix(path.Base(repoURL.Path), ".git")
|
||||
|
||||
gitWorkingDirectory := "/tmp/git/"
|
||||
|
||||
cloneDir := gitWorkingDirectory + uuid.New().String()
|
||||
|
||||
err := os.MkdirAll(cloneDir, os.ModePerm)
|
||||
err = os.MkdirAll(cloneDir, os.ModePerm)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error creating directory %s: %w", cloneDir, err)
|
||||
return "", nil, fmt.Errorf("error creating directory %s: %w", cloneDir, err)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
|
@ -102,7 +111,7 @@ func (s scm) DevcontainerConfig(
|
|||
filePath := ".devcontainer/devcontainer.json"
|
||||
err = validateArgs(gitspaceConfig)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid branch or url: %w", err)
|
||||
return "", nil, fmt.Errorf("invalid branch or url: %w", err)
|
||||
}
|
||||
|
||||
log.Info().Msg("Cloning the repository...")
|
||||
|
@ -118,7 +127,7 @@ func (s scm) DevcontainerConfig(
|
|||
command.WithDir(cloneDir),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to clone repository %s: %w", gitspaceConfig.CodeRepoURL, err)
|
||||
return "", nil, fmt.Errorf("failed to clone repository %s: %w", gitspaceConfig.CodeRepoURL, err)
|
||||
}
|
||||
|
||||
var lsTreeOutput bytes.Buffer
|
||||
|
@ -132,13 +141,13 @@ func (s scm) DevcontainerConfig(
|
|||
command.WithStdout(&lsTreeOutput),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to list files in repository %s: %w", cloneDir, err)
|
||||
return "", nil, fmt.Errorf("failed to list files in repository %s: %w", cloneDir, err)
|
||||
}
|
||||
|
||||
if lsTreeOutput.Len() == 0 {
|
||||
log.Info().Msg("File not found, returning empty devcontainerConfig")
|
||||
emptyConfig := &types.DevcontainerConfig{}
|
||||
return emptyConfig, nil
|
||||
return repoName, emptyConfig, nil
|
||||
}
|
||||
|
||||
fields := strings.Fields(lsTreeOutput.String())
|
||||
|
@ -153,7 +162,7 @@ func (s scm) DevcontainerConfig(
|
|||
command.WithStdout(&catFileOutput),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to checkout devcontainer file from path %s: %w", filePath, err)
|
||||
return "", nil, fmt.Errorf("failed to read devcontainer file from path %s: %w", filePath, err)
|
||||
}
|
||||
|
||||
sanitizedJSON := removeComments(catFileOutput.Bytes())
|
||||
|
@ -161,26 +170,10 @@ func (s scm) DevcontainerConfig(
|
|||
var config types.DevcontainerConfig
|
||||
err = json.Unmarshal(sanitizedJSON, &config)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse devcontainer json: %w", err)
|
||||
return "", nil, fmt.Errorf("failed to parse devcontainer json: %w", err)
|
||||
}
|
||||
|
||||
return &config, nil
|
||||
}
|
||||
|
||||
// TODO: Make RepositoryName compatible with all SCM providers
|
||||
|
||||
func (s scm) RepositoryName(_ context.Context, gitspaceConfig *types.GitspaceConfig) (string, error) {
|
||||
parsedURL, err := url.Parse(gitspaceConfig.CodeRepoURL)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to parse url: %w", err)
|
||||
}
|
||||
pathSegments := strings.Split(parsedURL.Path, "/")
|
||||
|
||||
if len(pathSegments) < 3 || pathSegments[1] == "" || pathSegments[2] == "" {
|
||||
return "", fmt.Errorf("invalid repository name URL: %s", parsedURL.String())
|
||||
}
|
||||
repoName := pathSegments[2]
|
||||
return strings.ReplaceAll(repoName, ".git", ""), nil
|
||||
return repoName, &config, nil
|
||||
}
|
||||
|
||||
func removeComments(input []byte) []byte {
|
||||
|
|
|
@ -17,6 +17,7 @@ package gitspaceevent
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
gitspaceevents "github.com/harness/gitness/app/events/gitspace"
|
||||
"github.com/harness/gitness/events"
|
||||
|
@ -32,7 +33,8 @@ func (s *Service) handleGitspaceEvent(
|
|||
EntityID: event.Payload.EntityID,
|
||||
QueryKey: event.Payload.QueryKey,
|
||||
EntityType: event.Payload.EntityType,
|
||||
Created: event.Payload.Created,
|
||||
Timestamp: event.Payload.Timestamp,
|
||||
Created: time.Now().UnixMilli(),
|
||||
}
|
||||
|
||||
err := s.gitspaceEventStore.Create(ctx, gitspaceEvent)
|
||||
|
|
|
@ -36,8 +36,9 @@ const (
|
|||
geven_event,
|
||||
geven_created,
|
||||
geven_entity_type,
|
||||
geven_entity_uid,
|
||||
geven_entity_id
|
||||
geven_query_key,
|
||||
geven_entity_id,
|
||||
geven_timestamp
|
||||
`
|
||||
gitspaceEventsColumnsWithID = gitspaceEventIDColumn + `,
|
||||
` + gitspaceEventsColumns
|
||||
|
@ -53,8 +54,9 @@ type gitspaceEvent struct {
|
|||
Event enum.GitspaceEventType `db:"geven_event"`
|
||||
Created int64 `db:"geven_created"`
|
||||
EntityType enum.GitspaceEntityType `db:"geven_entity_type"`
|
||||
QueryKey string `db:"geven_entity_uid"` // TODO: change to query_key
|
||||
QueryKey string `db:"geven_query_key"`
|
||||
EntityID int64 `db:"geven_entity_id"`
|
||||
Timestamp int64 `db:"geven_timestamp"`
|
||||
}
|
||||
|
||||
func NewGitspaceEventStore(db *sqlx.DB) store.GitspaceEventStore {
|
||||
|
@ -73,7 +75,7 @@ func (g gitspaceEventStore) FindLatestByTypeAndGitspaceConfigID(
|
|||
From(gitspaceEventsTable).
|
||||
Where("geven_event = $1", eventType).
|
||||
Where("geven_entity_id = $2", gitspaceConfigID).
|
||||
OrderBy("geven_created DESC")
|
||||
OrderBy("geven_timestamp DESC")
|
||||
sql, args, err := stmt.ToSql()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to convert squirrel builder to sql: %w", err)
|
||||
|
@ -96,6 +98,7 @@ func (g gitspaceEventStore) Create(ctx context.Context, gitspaceEvent *types.Git
|
|||
gitspaceEvent.EntityType,
|
||||
gitspaceEvent.QueryKey,
|
||||
gitspaceEvent.EntityID,
|
||||
gitspaceEvent.Timestamp,
|
||||
).
|
||||
Suffix("RETURNING " + gitspaceEventIDColumn)
|
||||
db := dbtx.GetAccessor(ctx, g.db)
|
||||
|
@ -161,7 +164,7 @@ func (g gitspaceEventStore) setQueryFilter(
|
|||
filter *types.GitspaceEventFilter,
|
||||
) squirrel.SelectBuilder {
|
||||
if filter.QueryKey != "" {
|
||||
stmt = stmt.Where(squirrel.Eq{"geven_entity_uid": filter.QueryKey})
|
||||
stmt = stmt.Where(squirrel.Eq{"geven_query_key": filter.QueryKey})
|
||||
}
|
||||
if filter.EntityType != "" {
|
||||
stmt = stmt.Where(squirrel.Eq{"geven_entity_type": filter.EntityType})
|
||||
|
@ -176,7 +179,7 @@ func (g gitspaceEventStore) setSortFilter(
|
|||
stmt squirrel.SelectBuilder,
|
||||
_ *types.GitspaceEventFilter,
|
||||
) squirrel.SelectBuilder {
|
||||
return stmt.OrderBy("geven_created DESC")
|
||||
return stmt.OrderBy("geven_timestamp DESC")
|
||||
}
|
||||
|
||||
func (g gitspaceEventStore) setPaginationFilter(
|
||||
|
@ -204,5 +207,6 @@ func (g gitspaceEventStore) mapGitspaceEvent(event *gitspaceEvent) *types.Gitspa
|
|||
EntityType: event.EntityType,
|
||||
QueryKey: event.QueryKey,
|
||||
EntityID: event.EntityID,
|
||||
Timestamp: event.Timestamp,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
ALTER TABLE gitspace_events RENAME COLUMN geven_query_key to geven_entity_uid;
|
||||
|
||||
ALTER TABLE gitspace_events DROP COLUMN geven_timestamp;
|
|
@ -0,0 +1,8 @@
|
|||
ALTER TABLE gitspace_events RENAME COLUMN geven_entity_uid to geven_query_key;
|
||||
|
||||
ALTER TABLE gitspace_events
|
||||
ADD COLUMN geven_timestamp BIGINT;
|
||||
UPDATE gitspace_events
|
||||
SET geven_timestamp = geven_created * 1000000;
|
||||
ALTER TABLE gitspace_events
|
||||
ALTER COLUMN geven_timestamp SET NOT NULL;
|
|
@ -0,0 +1,25 @@
|
|||
CREATE TABLE gitspace_events_temp
|
||||
(
|
||||
geven_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
geven_event TEXT NOT NULL,
|
||||
geven_created BIGINT NOT NULL,
|
||||
geven_entity_type TEXT NOT NULL,
|
||||
geven_entity_uid TEXT,
|
||||
geven_entity_id INTEGER NOT NULL
|
||||
);
|
||||
|
||||
INSERT INTO gitspace_events_temp (geven_id, geven_event, geven_created, geven_entity_type, geven_entity_uid,
|
||||
geven_entity_id)
|
||||
SELECT geven_id,
|
||||
geven_event,
|
||||
geven_created,
|
||||
geven_entity_type,
|
||||
geven_query_key,
|
||||
geven_entity_id
|
||||
FROM gitspace_events;
|
||||
|
||||
DROP TABLE gitspace_events;
|
||||
|
||||
ALTER TABLE gitspace_events_temp RENAME TO gitspace_events;
|
||||
|
||||
CREATE INDEX gitspace_events_entity_id ON gitspace_events (geven_entity_id);
|
|
@ -0,0 +1,27 @@
|
|||
CREATE TABLE gitspace_events_temp
|
||||
(
|
||||
geven_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
geven_event TEXT NOT NULL,
|
||||
geven_created BIGINT NOT NULL,
|
||||
geven_entity_type TEXT NOT NULL,
|
||||
geven_query_key TEXT,
|
||||
geven_entity_id INTEGER NOT NULL,
|
||||
geven_timestamp BIGINT NOT NULL
|
||||
);
|
||||
|
||||
INSERT INTO gitspace_events_temp (geven_id, geven_event, geven_created, geven_entity_type, geven_query_key,
|
||||
geven_entity_id, geven_timestamp)
|
||||
SELECT geven_id,
|
||||
geven_event,
|
||||
geven_created,
|
||||
geven_entity_type,
|
||||
geven_entity_uid,
|
||||
geven_entity_id,
|
||||
geven_created * 1000000
|
||||
FROM gitspace_events;
|
||||
|
||||
DROP TABLE gitspace_events;
|
||||
|
||||
ALTER TABLE gitspace_events_temp RENAME TO gitspace_events;
|
||||
|
||||
CREATE INDEX gitspace_events_entity_id ON gitspace_events (geven_entity_id);
|
|
@ -158,6 +158,9 @@ func backfillURLs(config *types.Config) error {
|
|||
}
|
||||
|
||||
// backfill all external URLs that weren't explicitly overwritten
|
||||
if config.URL.Base == "" {
|
||||
config.URL.Base = baseURL.String()
|
||||
}
|
||||
if config.URL.API == "" {
|
||||
config.URL.API = baseURL.JoinPath("api").String()
|
||||
}
|
||||
|
@ -376,13 +379,22 @@ func ProvideJobsConfig(config *types.Config) job.Config {
|
|||
}
|
||||
|
||||
// ProvideDockerConfig loads config for Docker.
|
||||
func ProvideDockerConfig(config *types.Config) *infraprovider.DockerConfig {
|
||||
return &infraprovider.DockerConfig{
|
||||
DockerHost: config.Docker.Host,
|
||||
DockerAPIVersion: config.Docker.APIVersion,
|
||||
DockerCertPath: config.Docker.CertPath,
|
||||
DockerTLSVerify: config.Docker.TLSVerify,
|
||||
func ProvideDockerConfig(config *types.Config) (*infraprovider.DockerConfig, error) {
|
||||
if config.Docker.MachineHostName == "" {
|
||||
gitnessBaseURL, err := url.Parse(config.URL.Base)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to parse Gitness base URL %s: %w", gitnessBaseURL, err)
|
||||
}
|
||||
config.Docker.MachineHostName = gitnessBaseURL.Hostname()
|
||||
}
|
||||
|
||||
return &infraprovider.DockerConfig{
|
||||
DockerHost: config.Docker.Host,
|
||||
DockerAPIVersion: config.Docker.APIVersion,
|
||||
DockerCertPath: config.Docker.CertPath,
|
||||
DockerTLSVerify: config.Docker.TLSVerify,
|
||||
DockerMachineHostName: config.Docker.MachineHostName,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ProvideIDEVSCodeWebConfig loads the VSCode Web IDE config from the main config.
|
||||
|
@ -394,8 +406,6 @@ func ProvideIDEVSCodeWebConfig(config *types.Config) *container.VSCodeWebConfig
|
|||
|
||||
// ProvideGitspaceContainerOrchestratorConfig loads the Gitspace container orchestrator config from the main config.
|
||||
func ProvideGitspaceContainerOrchestratorConfig(config *types.Config) (*container.Config, error) {
|
||||
var bindMountSourceBasePath string
|
||||
|
||||
if config.Gitspace.DefaultBindMountSourceBasePath == "" {
|
||||
var homedir string
|
||||
|
||||
|
@ -404,13 +414,18 @@ func ProvideGitspaceContainerOrchestratorConfig(config *types.Config) (*containe
|
|||
return nil, fmt.Errorf("unable to determine home directory: %w", err)
|
||||
}
|
||||
|
||||
bindMountSourceBasePath = filepath.Join(homedir, gitnessHomeDir)
|
||||
config.Gitspace.DefaultBindMountSourceBasePath = filepath.Join(homedir, gitnessHomeDir)
|
||||
}
|
||||
|
||||
if config.Gitspace.DefaultBindMountSourceBasePathAbsolute == "" {
|
||||
config.Gitspace.DefaultBindMountSourceBasePathAbsolute = config.Gitspace.DefaultBindMountSourceBasePath
|
||||
}
|
||||
|
||||
return &container.Config{
|
||||
DefaultBaseImage: config.Gitspace.DefaultBaseImage,
|
||||
DefaultBindMountTargetPath: config.Gitspace.DefaultBindMountTargetPath,
|
||||
DefaultBindMountSourceBasePath: bindMountSourceBasePath,
|
||||
DefaultBaseImage: config.Gitspace.DefaultBaseImage,
|
||||
DefaultBindMountTargetPath: config.Gitspace.DefaultBindMountTargetPath,
|
||||
DefaultBindMountSourceBasePath: config.Gitspace.DefaultBindMountSourceBasePath,
|
||||
DefaultBindMountSourceBasePathAbsolute: config.Gitspace.DefaultBindMountSourceBasePathAbsolute,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -322,9 +322,12 @@ func initSystem(ctx context.Context, config *types.Config) (*server.System, erro
|
|||
keywordsearchController := keywordsearch2.ProvideController(authorizer, searcher, repoController, spaceController)
|
||||
infraProviderResourceStore := database.ProvideInfraProviderResourceStore(db)
|
||||
infraProviderConfigStore := database.ProvideInfraProviderConfigStore(db)
|
||||
dockerConfig := server.ProvideDockerConfig(config)
|
||||
dockerConfig, err := server.ProvideDockerConfig(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dockerClientFactory := infraprovider.ProvideDockerClientFactory(dockerConfig)
|
||||
dockerProvider := infraprovider.ProvideDockerProvider(dockerClientFactory)
|
||||
dockerProvider := infraprovider.ProvideDockerProvider(dockerConfig, dockerClientFactory)
|
||||
factory := infraprovider.ProvideFactory(dockerProvider)
|
||||
providerService := infraprovider2.ProvideInfraProvider(infraProviderResourceStore, infraProviderConfigStore, factory, spaceStore, transactor)
|
||||
infraproviderController := infraprovider3.ProvideController(authorizer, spaceStore, providerService)
|
||||
|
|
|
@ -26,13 +26,6 @@ import (
|
|||
"github.com/docker/go-connections/tlsconfig"
|
||||
)
|
||||
|
||||
type DockerConfig struct {
|
||||
DockerHost string
|
||||
DockerAPIVersion string
|
||||
DockerCertPath string
|
||||
DockerTLSVerify string
|
||||
}
|
||||
|
||||
type DockerClientFactory struct {
|
||||
config *DockerConfig
|
||||
}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
// Copyright 2023 Harness, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package infraprovider
|
||||
|
||||
type DockerConfig struct {
|
||||
DockerHost string
|
||||
DockerAPIVersion string
|
||||
DockerCertPath string
|
||||
DockerTLSVerify string
|
||||
DockerMachineHostName string
|
||||
}
|
|
@ -27,11 +27,13 @@ import (
|
|||
var _ InfraProvider = (*DockerProvider)(nil)
|
||||
|
||||
type DockerProvider struct {
|
||||
config *DockerConfig
|
||||
dockerClientFactory *DockerClientFactory
|
||||
}
|
||||
|
||||
func NewDockerProvider(dockerClientFactory *DockerClientFactory) *DockerProvider {
|
||||
func NewDockerProvider(config *DockerConfig, dockerClientFactory *DockerClientFactory) *DockerProvider {
|
||||
return &DockerProvider{
|
||||
config: config,
|
||||
dockerClientFactory: dockerClientFactory,
|
||||
}
|
||||
}
|
||||
|
@ -62,6 +64,7 @@ func (d DockerProvider) Provision(ctx context.Context, _ string, params []Parame
|
|||
Identifier: info.ID,
|
||||
ProviderType: enum.InfraProviderTypeDocker,
|
||||
Status: enum.InfraStatusProvisioned,
|
||||
Host: d.config.DockerMachineHostName,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -25,8 +25,8 @@ var WireSet = wire.NewSet(
|
|||
ProvideDockerClientFactory,
|
||||
)
|
||||
|
||||
func ProvideDockerProvider(dockerClientFactory *DockerClientFactory) *DockerProvider {
|
||||
return NewDockerProvider(dockerClientFactory)
|
||||
func ProvideDockerProvider(config *DockerConfig, dockerClientFactory *DockerClientFactory) *DockerProvider {
|
||||
return NewDockerProvider(config, dockerClientFactory)
|
||||
}
|
||||
|
||||
func ProvideFactory(dockerProvider *DockerProvider) Factory {
|
||||
|
|
|
@ -385,6 +385,9 @@ type Config struct {
|
|||
CertPath string `envconfig:"GITNESS_DOCKER_CERT_PATH"`
|
||||
// TLSVerify enables or disables TLS verification, off by default.
|
||||
TLSVerify string `envconfig:"GITNESS_DOCKER_TLS_VERIFY"`
|
||||
// MachineHostName is the public host name of the machine on which the Docker.Host is running.
|
||||
// If not set, it parses the host from the URL.Base (e.g. localhost from http://localhost:3000).
|
||||
MachineHostName string `envconfig:"GITNESS_DOCKER_MACHINE_HOST_NAME"`
|
||||
}
|
||||
|
||||
IDE struct {
|
||||
|
@ -406,6 +409,9 @@ type Config struct {
|
|||
// Sub-directories will be created from this eg <DefaultBindMountSourceBasePath>/gitspace/space1/space2/config1
|
||||
// If left blank, it will be set to $HOME/.gitness
|
||||
DefaultBindMountSourceBasePath string `envconfig:"GITNESS_GITSPACE_DEFAULT_BIND_MOUNT_SOURCE_BASE_PATH"`
|
||||
// DefaultBindMountSourceBasePathAbsolute is the source path on which the DefaultBindMountSourceBasePath
|
||||
// is mounted in Gitness container. If left blank, it will be equal to DefaultBindMountSourceBasePath.
|
||||
DefaultBindMountSourceBasePathAbsolute string `envconfig:"GITNESS_GITSPACE_DEFAULT_BIND_MOUNT_SOURCE_BASE_PATH_ABSOLUTE"` //nolint:lll
|
||||
|
||||
Events struct {
|
||||
Concurrency int `envconfig:"GITNESS_GITSPACE_EVENTS_CONCURRENCY" default:"4"`
|
||||
|
|
|
@ -22,7 +22,8 @@ type GitspaceEvent struct {
|
|||
EntityID int64 `json:"-"`
|
||||
QueryKey string `json:"query_key,omitempty"`
|
||||
EntityType enum.GitspaceEntityType `json:"entity_type,omitempty"`
|
||||
Created int64 `json:"timestamp,omitempty"`
|
||||
Timestamp int64 `json:"timestamp,omitempty"`
|
||||
Created int64 `json:"created,omitempty"`
|
||||
}
|
||||
|
||||
type GitspaceEventResponse struct {
|
||||
|
|
Loading…
Reference in New Issue