Skip to content

Commit eb8b451

Browse files
committed
feat: add custom driver
1 parent 72e5ab0 commit eb8b451

File tree

24 files changed

+397
-1367
lines changed

24 files changed

+397
-1367
lines changed

cmd/agent/daemon.go

+2-24
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@ import (
44
"bytes"
55
"context"
66
"encoding/json"
7-
"fmt"
87
"os"
98
"path/filepath"
109
"strings"
1110
"time"
1211

1312
"github.com/loft-sh/devpod/cmd/flags"
1413
"github.com/loft-sh/devpod/pkg/agent"
15-
"github.com/loft-sh/devpod/pkg/binaries"
1614
"github.com/loft-sh/devpod/pkg/client/clientimplementation"
15+
"github.com/loft-sh/devpod/pkg/driver/custom"
1716
provider2 "github.com/loft-sh/devpod/pkg/provider"
1817
"github.com/loft-sh/log"
1918
"github.com/sirupsen/logrus"
@@ -145,7 +144,7 @@ func (cmd *DaemonCmd) doOnce(log log.Logger) {
145144

146145
func (cmd *DaemonCmd) runShutdownCommand(workspace *provider2.AgentWorkspaceInfo, log log.Logger) {
147146
// get environ
148-
environ, err := toEnvironWithBinaries(cmd.AgentDir, workspace, log)
147+
environ, err := custom.ToEnvironWithBinaries(workspace, log)
149148
if err != nil {
150149
log.Errorf("%v", err)
151150
return
@@ -170,27 +169,6 @@ func (cmd *DaemonCmd) runShutdownCommand(workspace *provider2.AgentWorkspaceInfo
170169
log.Infof("Successful ran command: %s", buf.String())
171170
}
172171

173-
func toEnvironWithBinaries(agentDir string, workspace *provider2.AgentWorkspaceInfo, log log.Logger) ([]string, error) {
174-
// get binaries dir
175-
binariesDir, err := agent.GetAgentBinariesDir(agentDir, workspace.Workspace.Context, workspace.Workspace.ID)
176-
if err != nil {
177-
return nil, fmt.Errorf("error getting workspace %s binaries dir: %w", workspace.Workspace.ID, err)
178-
}
179-
180-
// download binaries
181-
agentBinaries, err := binaries.DownloadBinaries(workspace.Agent.Binaries, binariesDir, log)
182-
if err != nil {
183-
return nil, fmt.Errorf("error downloading workspace %s binaries: %w", workspace.Workspace.ID, err)
184-
}
185-
186-
// get environ
187-
environ := provider2.ToEnvironment(workspace.Workspace, workspace.Machine, workspace.Options, nil)
188-
for k, v := range agentBinaries {
189-
environ = append(environ, k+"="+v)
190-
}
191-
return environ, nil
192-
}
193-
194172
func (cmd *DaemonCmd) initialTouch(log log.Logger) {
195173
// get base folder
196174
baseFolder, err := agent.FindAgentHomeFolder(cmd.AgentDir)

cmd/agent/workspace/up.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func initWorkspace(ctx context.Context, cancel context.CancelFunc, workspaceInfo
129129
// install docker in background
130130
errChan := make(chan error, 1)
131131
go func() {
132-
if workspaceInfo.Agent.Driver == provider2.KubernetesDriver || workspaceInfo.Agent.Docker.Install == "false" {
132+
if workspaceInfo.Agent.IsDockerDriver() || workspaceInfo.Agent.Docker.Install == "false" {
133133
errChan <- nil
134134
} else {
135135
errChan <- InstallDocker(logger)

e2e/framework/agent_server.go

-33
This file was deleted.

e2e/tests/build/build.go

+11-4
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ var _ = DevPodDescribe("devpod build test suite", func() {
155155
framework.ExpectNoError(err)
156156
})
157157

158-
ginkgo.It("build kubernetes buildkit", func() {
158+
ginkgo.FIt("build kubernetes dockerless", func() {
159159
ctx := context.Background()
160160

161161
f := framework.NewDefaultFramework(initialDir + "/bin")
@@ -166,12 +166,19 @@ var _ = DevPodDescribe("devpod build test suite", func() {
166166
_ = f.DevPodProviderDelete(ctx, "kubernetes")
167167
err = f.DevPodProviderAdd(ctx, "kubernetes")
168168
framework.ExpectNoError(err)
169-
err = f.DevPodProviderUse(context.Background(), "kubernetes", "-o", "BUILD_REPOSITORY=test-repo", "-o", "KUBERNETES_NAMESPACE=devpod")
169+
err = f.DevPodProviderUse(context.Background(), "kubernetes", "-o", "KUBERNETES_NAMESPACE=devpod")
170170
framework.ExpectNoError(err)
171171

172-
// do the build
173-
err = f.DevPodBuild(ctx, tempDir, "--force-build", "--repository", "test-repo", "--skip-push")
172+
ginkgo.DeferCleanup(f.DevPodWorkspaceDelete, context.Background(), tempDir)
173+
174+
// do the up
175+
err = f.DevPodUp(ctx, tempDir)
176+
framework.ExpectNoError(err)
177+
178+
// check if ssh works
179+
out, err := f.DevPodSSH(ctx, tempDir, "echo -n $MY_TEST")
174180
framework.ExpectNoError(err)
181+
framework.ExpectEqual(out, "test456", "should contain my-test")
175182
})
176183
})
177184

Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
FROM alpine
1+
FROM alpine
2+
3+
ENV MY_TEST=test123
4+
5+
FROM ubuntu
6+
7+
ENV MY_TEST=test456
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{
22
"name": "Build Example Kubernetes",
3-
"dockerFile": "Dockerfile"
3+
"build": {
4+
"dockerfile": "Dockerfile"
5+
}
46
}

pkg/agent/workspace.go

+12-7
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,16 @@ func GetAgentWorkspaceContentDir(workspaceDir string) string {
160160
return filepath.Join(workspaceDir, "content")
161161
}
162162

163+
func GetAgentBinariesDirFromWorkspaceDir(workspaceDir string) (string, error) {
164+
// check if it already exists
165+
_, err := os.Stat(workspaceDir)
166+
if err == nil {
167+
return filepath.Join(workspaceDir, "binaries"), nil
168+
}
169+
170+
return "", os.ErrNotExist
171+
}
172+
163173
func GetAgentBinariesDir(agentFolder, context, workspaceID string) (string, error) {
164174
homeFolder, err := FindAgentHomeFolder(agentFolder)
165175
if err != nil {
@@ -172,13 +182,8 @@ func GetAgentBinariesDir(agentFolder, context, workspaceID string) (string, erro
172182
// workspace folder
173183
workspaceDir := filepath.Join(homeFolder, "contexts", context, "workspaces", workspaceID)
174184

175-
// check if it already exists
176-
_, err = os.Stat(workspaceDir)
177-
if err == nil {
178-
return filepath.Join(workspaceDir, "binaries"), nil
179-
}
180-
181-
return "", os.ErrNotExist
185+
// get from workspace folder
186+
return GetAgentBinariesDirFromWorkspaceDir(workspaceDir)
182187
}
183188

184189
func GetAgentWorkspaceDir(agentFolder, context, workspaceID string) (string, error) {

pkg/devcontainer/run.go

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ func (r *Runner) Up(ctx context.Context, options UpOptions) (*config.Result, err
7373
_, isDockerDriver := r.Driver.(driver.DockerDriver)
7474
if options.Recreate && !isDockerDriver {
7575
// TODO: for drivers other than docker and recreate is true, we need to download the complete context here first
76+
return nil, fmt.Errorf("rebuilding the workspace is currently not supported for non-docker drivers")
7677
}
7778

7879
// prepare config

pkg/devcontainer/single.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/pkg/errors"
1414
)
1515

16-
var dockerlessImage = "dockerless"
16+
var dockerlessImage = "ghcr.io/loft-sh/dockerless:0.1"
1717

1818
func (r *Runner) runSingleContainer(ctx context.Context, parsedConfig *config.SubstitutedConfig, options UpOptions) (*config.Result, error) {
1919
containerDetails, err := r.Driver.FindDevContainer(ctx, r.ID)

0 commit comments

Comments
 (0)