Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions handler/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import (
"encoding/json"
"errors"
"net/http"
"path/filepath"
"runtime"
"strings"
"time"

"github.com/harness/harness-docker-runner/executor"
Expand Down Expand Up @@ -62,6 +64,8 @@ func HandleStartStep() http.HandlerFunc {
}
}

updateGitCloneConfig(&s.StartStepRequestConfig)

ctx := r.Context()
if err := stageData.StepExecutor.StartStep(ctx, &s, stageData.State.GetSecrets(), stageData.State.GetLogStreamClient(), stageData.State.GetTiClient()); err != nil {
WriteError(w, err)
Expand Down Expand Up @@ -96,6 +100,7 @@ func getSharedVolumeMount() *spec.VolumeMount {
}
}

// this returns back the host volume which is being used to clone repositories
func getHarnessVolume(volumes []*spec.Volume) (*spec.Volume, error) {
for _, v := range volumes {
if v.HostPath != nil {
Expand Down Expand Up @@ -131,6 +136,28 @@ func HandlePollStep(e *pruntime.StepExecutor) http.HandlerFunc {
}
}

// TODO: Move this logic to Java so that we pass in the right arguments to the runner
func updateGitCloneConfig(s *api.StartStepRequestConfig) {
if strings.Contains(s.Image, "harness/drone-git") {
if ws, ok := s.Envs["DRONE_WORKSPACE"]; ok {
// If it's an explicit git clone step, make sure the workspace is namespaced
if strings.HasPrefix(ws, "/harness") || strings.HasPrefix(ws, "/tmp/harness") {
last := ws[strings.LastIndex(ws, "/")+1:]
if last == "" {
// Retrieve the name from the remote URL. Eg: https://github.com/harness/drone-git should return drone-git
if url, ok2 := s.Envs["DRONE_REMOTE_URL"]; ok2 {
last = url[strings.LastIndex(url, "/")+1:]
}
}
ws := filepath.Join(s.WorkingDir, last)
s.Envs["DRONE_WORKSPACE"] = ws
} else if !filepath.IsAbs(ws) {
s.Envs["DRONE_WORKSPACE"] = filepath.Join(s.WorkingDir, ws)
}
}
}
}

func getDockerSockVolumeMount() *spec.VolumeMount {
path := engine.DockerSockUnixPath
if runtime.GOOS == "windows" {
Expand Down