Skip to content
Merged
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 cmd/internal/agentworkspace/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (cmd *BuildCmd) Run(ctx context.Context) error {
}()
}

runner, err := CreateRunner(workspaceInfo)
runner, err := CreateRunner(cancelCtx, workspaceInfo)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/internal/agentworkspace/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func removeContainer(
removeVolumes bool,
) error {
log.Debugf("removing Devsy container from server: workspaceId=%s", workspaceInfo.Workspace.ID)
runner, err := CreateRunner(workspaceInfo)
runner, err := CreateRunner(ctx, workspaceInfo)
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions cmd/internal/agentworkspace/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func (cmd *LogsCmd) Run(ctx context.Context) error {
}

runner, err := devcontainer.NewRunner(
ctx,
config.ContainerDevsyHelperLocation,
config.DefaultAgentDownloadURL(),
workspaceInfo,
Expand Down
2 changes: 1 addition & 1 deletion cmd/internal/agentworkspace/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (cmd *StatusCmd) Run(ctx context.Context) error {
}

// create runner
runner, err := CreateRunner(workspaceInfo)
runner, err := CreateRunner(ctx, workspaceInfo)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/internal/agentworkspace/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func stopContainer(
workspaceInfo *provider2.AgentWorkspaceInfo,
) error {
log.Debugf("stopping Devsy container")
runner, err := CreateRunner(workspaceInfo)
runner, err := CreateRunner(ctx, workspaceInfo)
if err != nil {
return err
}
Expand Down
4 changes: 3 additions & 1 deletion cmd/internal/agentworkspace/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (cmd *UpCmd) devsyUp(
ctx context.Context,
workspaceInfo *provider.AgentWorkspaceInfo,
) (*config2.Result, error) {
runner, err := CreateRunner(workspaceInfo)
runner, err := CreateRunner(ctx, workspaceInfo)
if err != nil {
return nil, err
}
Expand All @@ -209,9 +209,11 @@ func (cmd *UpCmd) devsyUp(
}

func CreateRunner(
ctx context.Context,
workspaceInfo *provider.AgentWorkspaceInfo,
) (devcontainer.Runner, error) {
return devcontainer.NewRunner(
ctx,
config.ContainerDevsyHelperLocation,
config.DefaultAgentDownloadURL(),
workspaceInfo,
Expand Down
2 changes: 1 addition & 1 deletion cmd/internal/container_tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (cmd *ContainerTunnelCmd) Run(ctx context.Context) error {
}

// create runner
runner, err := agentworkspace.CreateRunner(workspaceInfo)
runner, err := agentworkspace.CreateRunner(ctx, workspaceInfo)
if err != nil {
return err
}
Expand Down
12 changes: 9 additions & 3 deletions cmd/internal/runusercommands.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,10 @@ func (cmd *RunUserCommandsCmd) resolveContainer(
}

workspaceConfig := client.WorkspaceConfig()
runtime := workspace2.NewDockerRuntime(workspaceConfig, cmd.DockerPath)
runtime, err := workspace2.NewContainerRuntime(workspaceConfig, cmd.DockerPath)
if err != nil {
return nil, nil, err
}

containerDetails, err := runtime.FindRunning(
ctx, devcontainer.GetRunnerIDFromWorkspace(workspaceConfig), cmd.IDLabels,
Expand Down Expand Up @@ -393,8 +396,11 @@ func (cmd *RunUserCommandsCmd) resolveContainer(
envArgs = append(envArgs, cmd.buildCLIRemoteEnvArgs()...)

params := &workspace.LifecycleExecParams{
Ctx: ctx,
Helper: &docker.DockerHelper{DockerCommand: runtime.DockerCommand()},
Ctx: ctx,
Helper: &docker.DockerHelper{
DockerCommand: runtime.Command(),
Environment: runtime.Environment(),
},
ContainerID: containerDetails.ID,
EnvArgs: envArgs,
Workdir: workspace2.ResolveExecWorkdir(result, client.Workspace()),
Expand Down
14 changes: 10 additions & 4 deletions cmd/workspace/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,10 @@ func (cmd *ExecCmd) Run(ctx context.Context, args []string) error {
}

workspaceConfig := client.WorkspaceConfig()
runtime := workspace2.NewDockerRuntime(workspaceConfig, cmd.DockerPath)
runtime, err := workspace2.NewContainerRuntime(workspaceConfig, cmd.DockerPath)
if err != nil {
return err
}

containerDetails, err := runtime.FindRunning(
ctx, devcontainer.GetRunnerIDFromWorkspace(workspaceConfig), cmd.IDLabels,
Expand Down Expand Up @@ -180,7 +183,8 @@ func (cmd *ExecCmd) Run(ctx context.Context, args []string) error {
emitJSON := mode == output.ModeJSON

err = cmd.execInContainer(ctx, execOpts{
dockerCmd: runtime.DockerCommand(),
dockerCmd: runtime.Command(),
Comment thread
coderabbitai[bot] marked this conversation as resolved.
dockerEnv: runtime.Environment(),
target: target,
workdir: workdir,
envMap: envMap,
Expand Down Expand Up @@ -240,7 +244,8 @@ func (cmd *ExecCmd) runWithContainerID(ctx context.Context, args []string) error
emitJSON := mode == output.ModeJSON

err = cmd.execInContainer(ctx, execOpts{
dockerCmd: runtime.DockerCommand(),
dockerCmd: runtime.Command(),
dockerEnv: runtime.Environment(),
target: target,
workdir: workdir,
envMap: envMap,
Expand Down Expand Up @@ -304,6 +309,7 @@ func resolveUserEnvProbe(result *devcconfig.Result, cliOverride string) string {

type execOpts struct {
dockerCmd string
dockerEnv []string
target workspace2.ContainerTarget
workdir string
envMap map[string]string
Expand All @@ -329,7 +335,7 @@ func (cmd *ExecCmd) execInContainer(ctx context.Context, opts execOpts, args []s
redacted := strings.Join(redactExecArgs(execArgs), " ")
log.Debugf("Executing in container: %s %s", opts.dockerCmd, redacted)

helper := &docker.DockerHelper{DockerCommand: opts.dockerCmd}
helper := &docker.DockerHelper{DockerCommand: opts.dockerCmd, Environment: opts.dockerEnv}
return helper.Run(ctx, execArgs, docker.Streams{
Stdin: os.Stdin,
Stdout: os.Stdout,
Expand Down
3 changes: 3 additions & 0 deletions desktop/src/renderer/public/icons/providers/apple.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ let { name, class: className = "size-8" }: { name: string; class?: string } =
const ICON_MAP: Record<string, string> = {
docker: "./icons/providers/docker.svg",
podman: "./icons/providers/podman.svg",
apple: "./icons/providers/apple.svg",
aws: "./icons/providers/aws.svg",
amazon: "./icons/providers/aws.svg",
gcloud: "./icons/providers/gcp.svg",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import type { UnlistenFn } from "$lib/ipc/types.js"
const PRESETS = [
{ name: "docker", description: "Local Docker containers" },
{ name: "podman", description: "Local Podman containers" },
{ name: "apple", description: "Apple containers (macOS 26+, Apple silicon)" },
{ name: "ssh", description: "Remote SSH machines" },
{ name: "kubernetes", description: "Kubernetes clusters" },
{ name: "aws", description: "Amazon Web Services" },
Expand Down
68 changes: 31 additions & 37 deletions pkg/agent/delivery/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,40 +25,26 @@ type FactoryOptions struct {
}

func NewAgentDelivery(opts FactoryOptions) AgentDelivery {
driverType := opts.WorkspaceConfig.Agent.Driver

switch {
switch driverType := opts.WorkspaceConfig.Agent.Driver; {
case driverType == provider.CustomDriver:
log.Debugf("using legacy shell delivery for custom driver")
log.Warnf(
"legacy shell delivery is deprecated; platform-native delivery will replace this in a future release",
)
return &LegacyShellDelivery{
ExecFunc: opts.ExecFunc,
DownloadURL: "",
}
return legacyShellDelivery(opts, "custom driver")

case driverType == provider.KubernetesDriver:
if opts.PodExec == nil {
log.Debugf("kubernetes pod exec unavailable, using legacy shell delivery")
log.Warnf(
"legacy shell delivery is deprecated; platform-native delivery will replace this in a future release",
)
return &LegacyShellDelivery{
ExecFunc: opts.ExecFunc,
DownloadURL: "",
}
return legacyShellDelivery(opts, "kubernetes pod exec unavailable")
}
log.Debugf("using kubernetes-native delivery (exec stream)")
return &KubernetesDelivery{Exec: opts.PodExec}

case driverType == provider.AppleDriver:
// Shell delivery launches the agent in one exec, which keeps the VM
// alive; it is the supported mechanism here, not a deprecated fallback.
log.Debugf("using shell-based delivery for apple driver")
return &LegacyShellDelivery{ExecFunc: opts.ExecFunc, DownloadURL: ""}

case opts.IsRemoteDocker:
log.Debugf("using remote docker delivery (docker cp)")
return &RemoteDockerDelivery{
DockerCommand: opts.DockerCommand,
Environment: opts.DockerEnv,
ContainerID: opts.ContainerID,
}
return remoteDockerDelivery(opts)

case driverType == "" || driverType == provider.DockerDriver:
if isDockerLocal(opts.DockerCommand) {
Expand All @@ -70,21 +56,29 @@ func NewAgentDelivery(opts FactoryOptions) AgentDelivery {
}
}
log.Debugf("using remote docker delivery for non-local docker daemon")
return &RemoteDockerDelivery{
DockerCommand: opts.DockerCommand,
Environment: opts.DockerEnv,
ContainerID: opts.ContainerID,
}
return remoteDockerDelivery(opts)

default:
log.Debugf("using legacy shell delivery for driver: %s", driverType)
log.Warnf(
"legacy shell delivery is deprecated; platform-native delivery will replace this in a future release",
)
return &LegacyShellDelivery{
ExecFunc: opts.ExecFunc,
DownloadURL: "",
}
return legacyShellDelivery(opts, fmt.Sprintf("driver: %s", driverType))
}
}

func remoteDockerDelivery(opts FactoryOptions) AgentDelivery {
return &RemoteDockerDelivery{
DockerCommand: opts.DockerCommand,
Environment: opts.DockerEnv,
ContainerID: opts.ContainerID,
}
}

func legacyShellDelivery(opts FactoryOptions, reason string) AgentDelivery {
log.Debugf("using legacy shell delivery for %s", reason)
log.Warnf(
"legacy shell delivery is deprecated; platform-native delivery will replace this in a future release",
)
return &LegacyShellDelivery{
ExecFunc: opts.ExecFunc,
DownloadURL: "",
}
}

Expand Down
12 changes: 12 additions & 0 deletions pkg/agent/delivery/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,15 @@ func (m *mockDelivery) DeliverPostStart(_ context.Context, _ PostStartOptions) e
}

func (m *mockDelivery) Cleanup(_ context.Context, _ string) error { return nil }

func TestNewAgentDelivery_AppleUsesShellDelivery(t *testing.T) {
opts := FactoryOptions{
WorkspaceConfig: &provider.AgentWorkspaceInfo{
Agent: provider.ProviderAgentConfig{Driver: provider.AppleDriver},
},
}
d := NewAgentDelivery(opts)
if _, ok := d.(*LegacyShellDelivery); !ok {
t.Fatalf("apple driver must use shell delivery, got %T", d)
}
}
Loading
Loading