mirror of https://github.com/harness/drone.git
Changing order of execution for postCreateCommand and using repo name as working dir (#2236)
* Changing order of execution for postCreateCommand and using repo name as working dirunified-ui
parent
050c0f6aa3
commit
411eda9819
|
@ -29,6 +29,7 @@ type Orchestrator interface {
|
||||||
gitspaceConfig *types.GitspaceConfig,
|
gitspaceConfig *types.GitspaceConfig,
|
||||||
devcontainerConfig *types.DevcontainerConfig,
|
devcontainerConfig *types.DevcontainerConfig,
|
||||||
infra *infraprovider.Infrastructure,
|
infra *infraprovider.Infrastructure,
|
||||||
|
repoName string,
|
||||||
) (*StartResponse, error)
|
) (*StartResponse, error)
|
||||||
|
|
||||||
// StopGitspace stops and removes the gitspace container.
|
// StopGitspace stops and removes the gitspace container.
|
||||||
|
|
|
@ -18,7 +18,6 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/harness/gitness/app/gitspace/logutil"
|
"github.com/harness/gitness/app/gitspace/logutil"
|
||||||
"github.com/harness/gitness/infraprovider"
|
"github.com/harness/gitness/infraprovider"
|
||||||
|
@ -49,8 +48,6 @@ const (
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
DefaultBaseImage string
|
DefaultBaseImage string
|
||||||
WorkingDirectory string
|
|
||||||
RootSource string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type EmbeddedDockerOrchestrator struct {
|
type EmbeddedDockerOrchestrator struct {
|
||||||
|
@ -87,6 +84,7 @@ func (e *EmbeddedDockerOrchestrator) StartGitspace(
|
||||||
gitspaceConfig *types.GitspaceConfig,
|
gitspaceConfig *types.GitspaceConfig,
|
||||||
devcontainerConfig *types.DevcontainerConfig,
|
devcontainerConfig *types.DevcontainerConfig,
|
||||||
infra *infraprovider.Infrastructure,
|
infra *infraprovider.Infrastructure,
|
||||||
|
repoName string,
|
||||||
) (*StartResponse, error) {
|
) (*StartResponse, error) {
|
||||||
containerName := getGitspaceContainerName(gitspaceConfig)
|
containerName := getGitspaceContainerName(gitspaceConfig)
|
||||||
|
|
||||||
|
@ -148,7 +146,7 @@ func (e *EmbeddedDockerOrchestrator) StartGitspace(
|
||||||
log.Warn().Err(loggerErr).Msgf("failed to flush log stream for gitspace ID %d", gitspaceConfig.ID)
|
log.Warn().Err(loggerErr).Msgf("failed to flush log stream for gitspace ID %d", gitspaceConfig.ID)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
workingDirectory := "/" + repoName
|
||||||
startErr = e.startGitspace(
|
startErr = e.startGitspace(
|
||||||
ctx,
|
ctx,
|
||||||
gitspaceConfig,
|
gitspaceConfig,
|
||||||
|
@ -158,6 +156,7 @@ func (e *EmbeddedDockerOrchestrator) StartGitspace(
|
||||||
ideService,
|
ideService,
|
||||||
logStreamInstance,
|
logStreamInstance,
|
||||||
infra.Storage,
|
infra.Storage,
|
||||||
|
workingDirectory,
|
||||||
)
|
)
|
||||||
if startErr != nil {
|
if startErr != nil {
|
||||||
return nil, fmt.Errorf("failed to start gitspace %s: %w", containerName, startErr)
|
return nil, fmt.Errorf("failed to start gitspace %s: %w", containerName, startErr)
|
||||||
|
@ -178,10 +177,9 @@ func (e *EmbeddedDockerOrchestrator) StartGitspace(
|
||||||
}
|
}
|
||||||
|
|
||||||
return &StartResponse{
|
return &StartResponse{
|
||||||
ContainerID: containerID,
|
ContainerID: containerID,
|
||||||
ContainerName: containerName,
|
ContainerName: containerName,
|
||||||
WorkingDirectory: strings.TrimPrefix(e.config.WorkingDirectory, "/"),
|
PortsUsed: usedPorts,
|
||||||
PortsUsed: usedPorts,
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,6 +192,7 @@ func (e *EmbeddedDockerOrchestrator) startGitspace(
|
||||||
ideService IDE,
|
ideService IDE,
|
||||||
logStreamInstance *logutil.LogStreamInstance,
|
logStreamInstance *logutil.LogStreamInstance,
|
||||||
volumeName string,
|
volumeName string,
|
||||||
|
workingDirectory string,
|
||||||
) error {
|
) error {
|
||||||
var imageName = devcontainerConfig.Image
|
var imageName = devcontainerConfig.Image
|
||||||
if imageName == "" {
|
if imageName == "" {
|
||||||
|
@ -213,6 +212,7 @@ func (e *EmbeddedDockerOrchestrator) startGitspace(
|
||||||
ideService,
|
ideService,
|
||||||
logStreamInstance,
|
logStreamInstance,
|
||||||
volumeName,
|
volumeName,
|
||||||
|
workingDirectory,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -221,12 +221,7 @@ func (e *EmbeddedDockerOrchestrator) startGitspace(
|
||||||
var devcontainer = &Devcontainer{
|
var devcontainer = &Devcontainer{
|
||||||
ContainerName: containerName,
|
ContainerName: containerName,
|
||||||
DockerClient: dockerClient,
|
DockerClient: dockerClient,
|
||||||
WorkingDir: e.config.WorkingDirectory,
|
WorkingDir: workingDirectory,
|
||||||
}
|
|
||||||
|
|
||||||
err = e.executePostCreateCommand(ctx, devcontainerConfig, devcontainer, logStreamInstance)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = e.cloneCode(ctx, gitspaceConfig, devcontainerConfig, devcontainer, logStreamInstance)
|
err = e.cloneCode(ctx, gitspaceConfig, devcontainerConfig, devcontainer, logStreamInstance)
|
||||||
|
@ -239,6 +234,11 @@ func (e *EmbeddedDockerOrchestrator) startGitspace(
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = e.executePostCreateCommand(ctx, devcontainerConfig, devcontainer, logStreamInstance)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -425,6 +425,7 @@ func (e *EmbeddedDockerOrchestrator) createContainer(
|
||||||
ideService IDE,
|
ideService IDE,
|
||||||
logStreamInstance *logutil.LogStreamInstance,
|
logStreamInstance *logutil.LogStreamInstance,
|
||||||
volumeName string,
|
volumeName string,
|
||||||
|
workingDirectory string,
|
||||||
) error {
|
) error {
|
||||||
portUsedByIDE := ideService.PortAndProtocol()
|
portUsedByIDE := ideService.PortAndProtocol()
|
||||||
|
|
||||||
|
@ -466,7 +467,7 @@ func (e *EmbeddedDockerOrchestrator) createContainer(
|
||||||
{
|
{
|
||||||
Type: mount.TypeVolume,
|
Type: mount.TypeVolume,
|
||||||
Source: volumeName,
|
Source: volumeName,
|
||||||
Target: e.config.WorkingDirectory,
|
Target: workingDirectory,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}, nil, containerName)
|
}, nil, containerName)
|
||||||
|
|
|
@ -23,7 +23,7 @@ fi
|
||||||
# Clone the repository only if it doesn't exist
|
# Clone the repository only if it doesn't exist
|
||||||
if [ ! -d "$repo_name" ]; then
|
if [ ! -d "$repo_name" ]; then
|
||||||
echo "Cloning the repository..."
|
echo "Cloning the repository..."
|
||||||
git clone "$repo_url" --branch "$branch"
|
git clone "$repo_url" --branch "$branch" .
|
||||||
else
|
else
|
||||||
echo "Repository already exists. Skipping clone."
|
echo "Repository already exists. Skipping clone."
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -113,7 +113,7 @@ func (o orchestrator) StartGitspace(
|
||||||
|
|
||||||
o.emitGitspaceEvent(ctx, gitspaceConfig, enum.GitspaceEventTypeAgentGitspaceCreationStart)
|
o.emitGitspaceEvent(ctx, gitspaceConfig, enum.GitspaceEventTypeAgentGitspaceCreationStart)
|
||||||
|
|
||||||
startResponse, err := o.containerOrchestrator.StartGitspace(ctx, gitspaceConfig, devcontainerConfig, infra)
|
startResponse, err := o.containerOrchestrator.StartGitspace(ctx, gitspaceConfig, devcontainerConfig, infra, repoName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
o.emitGitspaceEvent(ctx, gitspaceConfig, enum.GitspaceEventTypeAgentGitspaceCreationFailed)
|
o.emitGitspaceEvent(ctx, gitspaceConfig, enum.GitspaceEventTypeAgentGitspaceCreationFailed)
|
||||||
|
|
||||||
|
@ -130,7 +130,7 @@ func (o orchestrator) StartGitspace(
|
||||||
ideURL = url.URL{
|
ideURL = url.URL{
|
||||||
Scheme: "http",
|
Scheme: "http",
|
||||||
Host: infra.Host + ":" + port,
|
Host: infra.Host + ":" + port,
|
||||||
RawQuery: filepath.Join("folder=", startResponse.WorkingDirectory, repoName),
|
RawQuery: filepath.Join("folder=", repoName),
|
||||||
}
|
}
|
||||||
} else if gitspaceConfig.IDE == enum.IDETypeVSCode {
|
} else if gitspaceConfig.IDE == enum.IDETypeVSCode {
|
||||||
// TODO: the following userID is hard coded and should be changed.
|
// TODO: the following userID is hard coded and should be changed.
|
||||||
|
@ -142,7 +142,7 @@ func (o orchestrator) StartGitspace(
|
||||||
"ssh-remote+%s@%s:%s",
|
"ssh-remote+%s@%s:%s",
|
||||||
userID,
|
userID,
|
||||||
infra.Host,
|
infra.Host,
|
||||||
filepath.Join(port, startResponse.WorkingDirectory, repoName),
|
filepath.Join(port, repoName),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -408,7 +408,6 @@ func ProvideIDEVSCodeWebConfig(config *types.Config) *container.VSCodeWebConfig
|
||||||
func ProvideGitspaceContainerOrchestratorConfig(config *types.Config) *container.Config {
|
func ProvideGitspaceContainerOrchestratorConfig(config *types.Config) *container.Config {
|
||||||
return &container.Config{
|
return &container.Config{
|
||||||
DefaultBaseImage: config.Gitspace.DefaultBaseImage,
|
DefaultBaseImage: config.Gitspace.DefaultBaseImage,
|
||||||
WorkingDirectory: config.Gitspace.WorkingDirectory,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -401,9 +401,6 @@ type Config struct {
|
||||||
// DefaultBaseImage is used to create the Gitspace when no devcontainer.json is absent or doesn't have image.
|
// DefaultBaseImage is used to create the Gitspace when no devcontainer.json is absent or doesn't have image.
|
||||||
DefaultBaseImage string `envconfig:"GITNESS_GITSPACE_DEFAULT_BASE_IMAGE" default:"mcr.microsoft.com/devcontainers/base:dev-ubuntu-24.04"` //nolint:lll
|
DefaultBaseImage string `envconfig:"GITNESS_GITSPACE_DEFAULT_BASE_IMAGE" default:"mcr.microsoft.com/devcontainers/base:dev-ubuntu-24.04"` //nolint:lll
|
||||||
|
|
||||||
// WorkingDirectory is the default working directory in the Gitspace container.
|
|
||||||
WorkingDirectory string `envconfig:"GITNESS_GITSPACE_WORKING_DIR" default:"/gitspace"`
|
|
||||||
|
|
||||||
Enable bool `envconfig:"GITNESS_GITSPACE_ENABLE" default:"false"`
|
Enable bool `envconfig:"GITNESS_GITSPACE_ENABLE" default:"false"`
|
||||||
|
|
||||||
Events struct {
|
Events struct {
|
||||||
|
|
Loading…
Reference in New Issue