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,
|
||||
devcontainerConfig *types.DevcontainerConfig,
|
||||
infra *infraprovider.Infrastructure,
|
||||
repoName string,
|
||||
) (*StartResponse, error)
|
||||
|
||||
// StopGitspace stops and removes the gitspace container.
|
||||
|
|
|
@ -18,7 +18,6 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"github.com/harness/gitness/app/gitspace/logutil"
|
||||
"github.com/harness/gitness/infraprovider"
|
||||
|
@ -49,8 +48,6 @@ const (
|
|||
|
||||
type Config struct {
|
||||
DefaultBaseImage string
|
||||
WorkingDirectory string
|
||||
RootSource string
|
||||
}
|
||||
|
||||
type EmbeddedDockerOrchestrator struct {
|
||||
|
@ -87,6 +84,7 @@ func (e *EmbeddedDockerOrchestrator) StartGitspace(
|
|||
gitspaceConfig *types.GitspaceConfig,
|
||||
devcontainerConfig *types.DevcontainerConfig,
|
||||
infra *infraprovider.Infrastructure,
|
||||
repoName string,
|
||||
) (*StartResponse, error) {
|
||||
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)
|
||||
}
|
||||
}()
|
||||
|
||||
workingDirectory := "/" + repoName
|
||||
startErr = e.startGitspace(
|
||||
ctx,
|
||||
gitspaceConfig,
|
||||
|
@ -158,6 +156,7 @@ func (e *EmbeddedDockerOrchestrator) StartGitspace(
|
|||
ideService,
|
||||
logStreamInstance,
|
||||
infra.Storage,
|
||||
workingDirectory,
|
||||
)
|
||||
if startErr != nil {
|
||||
return nil, fmt.Errorf("failed to start gitspace %s: %w", containerName, startErr)
|
||||
|
@ -178,10 +177,9 @@ func (e *EmbeddedDockerOrchestrator) StartGitspace(
|
|||
}
|
||||
|
||||
return &StartResponse{
|
||||
ContainerID: containerID,
|
||||
ContainerName: containerName,
|
||||
WorkingDirectory: strings.TrimPrefix(e.config.WorkingDirectory, "/"),
|
||||
PortsUsed: usedPorts,
|
||||
ContainerID: containerID,
|
||||
ContainerName: containerName,
|
||||
PortsUsed: usedPorts,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -194,6 +192,7 @@ func (e *EmbeddedDockerOrchestrator) startGitspace(
|
|||
ideService IDE,
|
||||
logStreamInstance *logutil.LogStreamInstance,
|
||||
volumeName string,
|
||||
workingDirectory string,
|
||||
) error {
|
||||
var imageName = devcontainerConfig.Image
|
||||
if imageName == "" {
|
||||
|
@ -213,6 +212,7 @@ func (e *EmbeddedDockerOrchestrator) startGitspace(
|
|||
ideService,
|
||||
logStreamInstance,
|
||||
volumeName,
|
||||
workingDirectory,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -221,12 +221,7 @@ func (e *EmbeddedDockerOrchestrator) startGitspace(
|
|||
var devcontainer = &Devcontainer{
|
||||
ContainerName: containerName,
|
||||
DockerClient: dockerClient,
|
||||
WorkingDir: e.config.WorkingDirectory,
|
||||
}
|
||||
|
||||
err = e.executePostCreateCommand(ctx, devcontainerConfig, devcontainer, logStreamInstance)
|
||||
if err != nil {
|
||||
return err
|
||||
WorkingDir: workingDirectory,
|
||||
}
|
||||
|
||||
err = e.cloneCode(ctx, gitspaceConfig, devcontainerConfig, devcontainer, logStreamInstance)
|
||||
|
@ -239,6 +234,11 @@ func (e *EmbeddedDockerOrchestrator) startGitspace(
|
|||
return err
|
||||
}
|
||||
|
||||
err = e.executePostCreateCommand(ctx, devcontainerConfig, devcontainer, logStreamInstance)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -425,6 +425,7 @@ func (e *EmbeddedDockerOrchestrator) createContainer(
|
|||
ideService IDE,
|
||||
logStreamInstance *logutil.LogStreamInstance,
|
||||
volumeName string,
|
||||
workingDirectory string,
|
||||
) error {
|
||||
portUsedByIDE := ideService.PortAndProtocol()
|
||||
|
||||
|
@ -466,7 +467,7 @@ func (e *EmbeddedDockerOrchestrator) createContainer(
|
|||
{
|
||||
Type: mount.TypeVolume,
|
||||
Source: volumeName,
|
||||
Target: e.config.WorkingDirectory,
|
||||
Target: workingDirectory,
|
||||
},
|
||||
},
|
||||
}, nil, containerName)
|
||||
|
|
|
@ -23,7 +23,7 @@ fi
|
|||
# Clone the repository only if it doesn't exist
|
||||
if [ ! -d "$repo_name" ]; then
|
||||
echo "Cloning the repository..."
|
||||
git clone "$repo_url" --branch "$branch"
|
||||
git clone "$repo_url" --branch "$branch" .
|
||||
else
|
||||
echo "Repository already exists. Skipping clone."
|
||||
fi
|
||||
|
|
|
@ -113,7 +113,7 @@ func (o orchestrator) StartGitspace(
|
|||
|
||||
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 {
|
||||
o.emitGitspaceEvent(ctx, gitspaceConfig, enum.GitspaceEventTypeAgentGitspaceCreationFailed)
|
||||
|
||||
|
@ -130,7 +130,7 @@ func (o orchestrator) StartGitspace(
|
|||
ideURL = url.URL{
|
||||
Scheme: "http",
|
||||
Host: infra.Host + ":" + port,
|
||||
RawQuery: filepath.Join("folder=", startResponse.WorkingDirectory, repoName),
|
||||
RawQuery: filepath.Join("folder=", repoName),
|
||||
}
|
||||
} else if gitspaceConfig.IDE == enum.IDETypeVSCode {
|
||||
// TODO: the following userID is hard coded and should be changed.
|
||||
|
@ -142,7 +142,7 @@ func (o orchestrator) StartGitspace(
|
|||
"ssh-remote+%s@%s:%s",
|
||||
userID,
|
||||
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 {
|
||||
return &container.Config{
|
||||
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 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"`
|
||||
|
||||
Events struct {
|
||||
|
|
Loading…
Reference in New Issue