Skip to content

Commit

Permalink
feat: docker requirement handling (#41)
Browse files Browse the repository at this point in the history
Signed-off-by: Philip-21 <[email protected]>
  • Loading branch information
Philip-21 authored Nov 22, 2024
1 parent 3153c4d commit a381259
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions pkg/provider/provider.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package provider

import (
"context"
"errors"
"fmt"
"io"
Expand All @@ -23,6 +24,7 @@ import (
"github.com/daytonaio/daytona/pkg/ssh"
"github.com/daytonaio/daytona/pkg/workspace"
"github.com/daytonaio/daytona/pkg/workspace/project"
docker_sdk "github.com/docker/docker/client"
)

type DockerProvider struct {
Expand Down Expand Up @@ -283,6 +285,44 @@ func (p DockerProvider) getClient(targetOptionsJson string) (docker.IDockerClien
}), nil
}

func (p DockerProvider) CheckRequirements() (*[]provider.RequirementStatus, error) {
var results []provider.RequirementStatus
ctx := context.Background()

cli, err := docker_sdk.NewClientWithOpts(docker_sdk.FromEnv, docker_sdk.WithAPIVersionNegotiation())
if err != nil {
results = append(results, provider.RequirementStatus{
Name: "Docker installed",
Met: false,
Reason: "Docker is not installed",
})
return &results, nil
} else {
results = append(results, provider.RequirementStatus{
Name: "Docker installed",
Met: true,
Reason: "Docker is installed",
})
}

// Check if Docker is running by fetching Docker info
_, err = cli.Info(ctx)
if err != nil {
results = append(results, provider.RequirementStatus{
Name: "Docker running",
Met: false,
Reason: "Docker is not running. Error: " + err.Error(),
})
} else {
results = append(results, provider.RequirementStatus{
Name: "Docker running",
Met: true,
Reason: "Docker is running",
})
}
return &results, nil
}

// If the project is running locally, we override the env vars to use the host.docker.internal address
func (p DockerProvider) setLocalEnvOverride(project *project.Project) {
project.EnvVars["DAYTONA_SERVER_URL"] = fmt.Sprintf("http://host.docker.internal:%d", *p.ServerPort)
Expand Down

0 comments on commit a381259

Please sign in to comment.