Skip to content

Commit 414672e

Browse files
committed
feat: [CI-11723]: introduced RUN_ON_HOST_ONLY flag
1 parent 50b1bc6 commit 414672e

File tree

8 files changed

+39
-7
lines changed

8 files changed

+39
-7
lines changed

cli/server/server.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (c *serverCommand) run(*kingpin.ParseContext) error {
9393
if loadedConfig.Server.SkipPrepareServer {
9494
logrus.Infoln("skipping prepare server eg install docker / git")
9595
} else {
96-
setup.PrepareSystem()
96+
setup.PrepareSystem(&loadedConfig)
9797
}
9898
// starts the http server.
9999
err = serverInstance.Start(ctx)

config/config.go

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type Config struct {
1717
Runner struct {
1818
Volumes []string `envconfig:"CI_MOUNT_VOLUMES"`
1919
NetworkDriver string `envconfig:"NETWORK_DRIVER"`
20+
RunOnHostOnly bool `envconfig:"RUN_ON_HOST_ONLY"`
2021
}
2122

2223
Server struct {

engine/docker/docker.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,10 @@ func (e *Docker) Destroy(ctx context.Context, pipelineConfig *spec.PipelineConfi
208208
}
209209

210210
// cleanup the network
211-
if err := e.client.NetworkRemove(ctx, pipelineConfig.Network.ID); err != nil {
212-
logrus.WithField("network", pipelineConfig.Network.ID).WithField("error", err).Warnln("failed to remove network")
211+
if e.IsDockerEnabled(pipelineConfig) {
212+
if err := e.client.NetworkRemove(ctx, pipelineConfig.Network.ID); err != nil {
213+
logrus.WithField("network", pipelineConfig.Network.ID).WithField("error", err).Warnln("failed to remove network")
214+
}
213215
}
214216

215217
e.mu.Lock()
@@ -223,6 +225,13 @@ func (e *Docker) Destroy(ctx context.Context, pipelineConfig *spec.PipelineConfi
223225
return nil
224226
}
225227

228+
func (e *Docker) IsDockerEnabled(pipelineConfig *spec.PipelineConfig) bool {
229+
if pipelineConfig.EnableDockerSetup == nil || *pipelineConfig.EnableDockerSetup {
230+
return true
231+
}
232+
return false
233+
}
234+
226235
// Run runs the pipeline step.
227236
func (e *Docker) Run(ctx context.Context, pipelineConfig *spec.PipelineConfig, step *spec.Step,
228237
output io.Writer) (*runtime.State, error) {

engine/engine.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func (e *Engine) Setup(ctx context.Context, pipelineConfig *spec.PipelineConfig)
7070
e.pipelineConfig = pipelineConfig
7171
e.mu.Unlock()
7272
// required to support m1 where docker isn't installed.
73-
if e.pipelineConfig.EnableDockerSetup == nil || *e.pipelineConfig.EnableDockerSetup {
73+
if e.docker.IsDockerEnabled(e.pipelineConfig) {
7474
return e.docker.Setup(ctx, pipelineConfig)
7575
}
7676
return nil

handler/health.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func HandleHealth() http.HandlerFunc {
2525
DockerInstalled: dockerOK,
2626
GitInstalled: gitOK,
2727
LiteEngineLog: setup.GetLiteEngineLog(instanceInfo),
28-
OK: dockerOK && gitOK,
28+
OK: true,
2929
}
3030
WriteJSON(w, response, http.StatusOK)
3131
}

handler/setup.go

+16
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,13 @@ func HandleSetup(config *config.Config) http.HandlerFunc {
4848
return
4949
}
5050
id := s.ID
51+
if config.Runner.RunOnHostOnly {
52+
mountDockerSocket := false
53+
s.MountDockerSocket = &mountDockerSocket
54+
}
5155

5256
updateVolumes(s)
57+
s.Envs["WORKSPACE"] = getWorkSpacePath(s)
5358

5459
// Add ti volume where all the TI related data (CG, Agent logs, config) will be stored
5560
// Add this dir to TIConfig for uploading the data
@@ -162,6 +167,17 @@ func updateVolumes(r api.SetupRequest) {
162167
}
163168
}
164169

170+
func getWorkSpacePath(r api.SetupRequest) string {
171+
for _, v := range r.Volumes {
172+
if v.HostPath != nil {
173+
if v.HostPath.ID == "harness" {
174+
return v.HostPath.Path
175+
}
176+
}
177+
}
178+
return ""
179+
}
180+
165181
func getSharedVolume() *spec.Volume {
166182
return &spec.Volume{
167183
HostPath: &spec.VolumeHostPath{

handler/step.go

+5
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ func HandleStartStep(config *config.Config) http.HandlerFunc {
3838
return
3939
}
4040

41+
if config.Runner.RunOnHostOnly {
42+
mountDockerSocket := false
43+
s.MountDockerSocket = &mountDockerSocket
44+
}
45+
4146
if s.MountDockerSocket == nil || *s.MountDockerSocket { // required to support m1 where docker isn't installed.
4247
s.Volumes = append(s.Volumes, getDockerSockVolumeMount())
4348
}

setup/setup.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"os/exec"
1010
"runtime"
1111

12+
"github.com/harness/harness-docker-runner/config"
1213
"github.com/sirupsen/logrus"
1314
)
1415

@@ -21,12 +22,12 @@ func GetInstanceInfo() InstanceInfo {
2122
return InstanceInfo{osType: osType}
2223
}
2324

24-
func PrepareSystem() {
25+
func PrepareSystem(c *config.Config) {
2526
instanceInfo := GetInstanceInfo()
2627
if !GitInstalled(instanceInfo) {
2728
installGit(instanceInfo)
2829
}
29-
if !DockerInstalled(instanceInfo) {
30+
if !c.Runner.RunOnHostOnly && !DockerInstalled(instanceInfo) {
3031
installDocker(instanceInfo)
3132
}
3233
}

0 commit comments

Comments
 (0)