Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion cli/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (c *serverCommand) run(*kingpin.ParseContext) error {
if loadedConfig.Server.SkipPrepareServer {
logrus.Infoln("skipping prepare server eg install docker / git")
} else {
setup.PrepareSystem()
setup.PrepareSystem(&loadedConfig)
}
// starts the http server.
err = serverInstance.Start(ctx)
Expand Down
5 changes: 5 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ type Config struct {
NetworkDriver string `envconfig:"NETWORK_DRIVER"`
}

Docker struct {
Binary string `envconfig:"DOCKER_BIN" default:""`
Socket string `envconfig:"DOCKER_SOCKET" default:""`
}

Server struct {
Bind string `envconfig:"HTTPS_BIND" default:":3000"`
CertFile string `envconfig:"SERVER_CERT_FILE" default:"/tmp/certs/server-cert.pem"` // Server certificate PEM file
Expand Down
2 changes: 1 addition & 1 deletion handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func Handler(config *config.Config, engine *engine.Engine, stepExecutor *runtime
// Health check
r.Mount("/healthz", func() http.Handler {
sr := chi.NewRouter()
sr.Get("/", HandleHealth())
sr.Get("/", HandleHealth(config))
return sr
}())

Expand Down
5 changes: 3 additions & 2 deletions handler/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package handler

import (
"github.com/harness/harness-docker-runner/config"
"net/http"

"github.com/harness/harness-docker-runner/api"
Expand All @@ -13,11 +14,11 @@ import (
"github.com/sirupsen/logrus"
)

func HandleHealth() http.HandlerFunc {
func HandleHealth(config *config.Config) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
logrus.Infoln("handler: HandleHealth()")
instanceInfo := setup.GetInstanceInfo()
dockerOK := setup.DockerInstalled(instanceInfo)
dockerOK := setup.DockerInstalled(instanceInfo, config)
gitOK := setup.GitInstalled(instanceInfo)
version := version.Version
response := api.HealthResponse{
Expand Down
13 changes: 8 additions & 5 deletions handler/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func HandleSetup(config *config.Config) http.HandlerFunc {
logger.FromRequest(r).Traceln("starting the setup process")

if s.MountDockerSocket == nil || *s.MountDockerSocket { // required to support m1 where docker isn't installed.
s.Volumes = append(s.Volumes, getDockerSockVolume())
s.Volumes = append(s.Volumes, getDockerSockVolume(config))
}

// fmt.Printf("setup request config: %+v\n", s.SetupRequestConfig)
Expand Down Expand Up @@ -189,10 +189,13 @@ func sanitize(r string) string {
return strings.ReplaceAll(r, "[-_]", "")
}

func getDockerSockVolume() *spec.Volume {
path := engine.DockerSockUnixPath
if runtime.GOOS == "windows" {
path = engine.DockerSockWinPath
func getDockerSockVolume(config *config.Config) *spec.Volume {
path := config.Docker.Socket
if path == "" {
path = engine.DockerSockUnixPath
if runtime.GOOS == "windows" {
path = engine.DockerSockWinPath
}
}
return &spec.Volume{
HostPath: &spec.VolumeHostPath{
Expand Down
13 changes: 8 additions & 5 deletions handler/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func HandleStartStep(config *config.Config) http.HandlerFunc {
}

if s.MountDockerSocket == nil || *s.MountDockerSocket { // required to support m1 where docker isn't installed.
s.Volumes = append(s.Volumes, getDockerSockVolumeMount())
s.Volumes = append(s.Volumes, getDockerSockVolumeMount(config))
}
ex := executor.GetExecutor()
stageData, err := ex.Get(s.StageRuntimeID)
Expand Down Expand Up @@ -205,10 +205,13 @@ func updateDelegateCapacity(s *api.StartStepRequestConfig) {
}
}

func getDockerSockVolumeMount() *spec.VolumeMount {
path := engine.DockerSockUnixPath
if runtime.GOOS == "windows" {
path = engine.DockerSockWinPath
func getDockerSockVolumeMount(config *config.Config) *spec.VolumeMount {
path := config.Docker.Socket
if path == "" {
path = engine.DockerSockUnixPath
if runtime.GOOS == "windows" {
path = engine.DockerSockWinPath
}
}
return &spec.VolumeMount{
Name: engine.DockerSockVolName,
Expand Down
13 changes: 9 additions & 4 deletions setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package setup

import (
"github.com/harness/harness-docker-runner/config"
"os"
"os/exec"
"runtime"
Expand All @@ -21,12 +22,12 @@ func GetInstanceInfo() InstanceInfo {
return InstanceInfo{osType: osType}
}

func PrepareSystem() {
func PrepareSystem(config *config.Config) {
instanceInfo := GetInstanceInfo()
if !GitInstalled(instanceInfo) {
installGit(instanceInfo)
}
if !DockerInstalled(instanceInfo) {
if !DockerInstalled(instanceInfo, config) {
installDocker(instanceInfo)
}
}
Expand All @@ -48,13 +49,17 @@ func GitInstalled(instanceInfo InstanceInfo) (installed bool) {
return true
}

func DockerInstalled(instanceInfo InstanceInfo) (installed bool) {
func DockerInstalled(instanceInfo InstanceInfo, config *config.Config) (installed bool) {
logrus.Infoln("checking docker is installed")
switch instanceInfo.osType {
case windowsString:
logrus.Infoln("windows: we should check docker installation here")
case osxString:
cmd := exec.Command("/usr/local/bin/docker", "ps")
binPath := config.Docker.Binary
if binPath == "" {
binPath = "/usr/local/bin/docker"
}
cmd := exec.Command(binPath, "ps")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
Expand Down