Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(agent): add devcontainer autostart support#17076

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mafredri merged 15 commits intomainfrommafredri/feat-agent-devcontainer-autostart
Mar 27, 2025
Merged
Changes from1 commit
Commits
Show all changes
15 commits
Select commitHold shift + click to select a range
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
PrevPrevious commit
NextNext commit
expand
  • Loading branch information
@mafredri
mafredri committedMar 25, 2025
commit9bfdfaf81dc46020fb152b13032d9fcb12b88000
43 changes: 30 additions & 13 deletionsagent/agent.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1075,7 +1075,7 @@ func (a *agent) handleManifest(manifestOK *checkpoint) func(ctx context.Context,
//
// An example is VS Code Remote, which must know the directory
// before initializing a connection.
manifest.Directory, err =expandDirectory(manifest.Directory)
manifest.Directory, err =expandPathToAbs(manifest.Directory)
if err != nil {
return xerrors.Errorf("expand directory: %w", err)
}
Expand DownExpand Up@@ -1119,13 +1119,18 @@ func (a *agent) handleManifest(manifestOK *checkpoint) func(ctx context.Context,
// scripts have completed.
var postStartScripts []codersdk.WorkspaceAgentScript
for _, dc := range manifest.Devcontainers {
dc = expandDevcontainerPaths(a.logger, dc)
// TODO(mafredri): Verify `@devcontainers/cli` presence.
// TODO(mafredri): Verify workspace folder exists.
// TODO(mafredri): If set, verify config path exists.
postStartScripts = append(postStartScripts, agentcontainers.DevcontainerStartupScript(dc))
}

err = a.scriptRunner.Init(manifest.Scripts, aAPI.ScriptCompleted, agentscripts.WithPostStartScripts(postStartScripts...))
err = a.scriptRunner.Init(
manifest.Scripts,
aAPI.ScriptCompleted,
agentscripts.WithPostStartScripts(postStartScripts...),
)
if err != nil {
return xerrors.Errorf("init script runner: %w", err)
}
Expand DownExpand Up@@ -1864,30 +1869,42 @@ func userHomeDir() (string, error) {
return u.HomeDir, nil
}

// expandDirectory converts a directory path to an absolute path.
// It primarily resolves the home directory and any environment
// variables that may be set
func expandDirectory(dir string) (string, error) {
if dir == "" {
// expandPathToAbs converts a path to an absolute path. It primarily resolves
// the home directory and any environment variables that may be set.
func expandPathToAbs(path string) (string, error) {
if path == "" {
return "", nil
}
ifdir[0] == '~' {
ifpath[0] == '~' {
home, err := userHomeDir()
if err != nil {
return "", err
}
dir = filepath.Join(home,dir[1:])
path = filepath.Join(home,path[1:])
}
dir = os.ExpandEnv(dir)
path = os.ExpandEnv(path)

if !filepath.IsAbs(dir) {
if !filepath.IsAbs(path) {
home, err := userHomeDir()
if err != nil {
return "", err
}
dir = filepath.Join(home, dir)
path = filepath.Join(home, path)
}
return path, nil
}

func expandDevcontainerPaths(logger slog.Logger, dc codersdk.WorkspaceAgentDevcontainer) codersdk.WorkspaceAgentDevcontainer {
var err error
if dc.WorkspaceFolder, err = expandPathToAbs(dc.WorkspaceFolder); err != nil {
logger.Warn(context.Background(), "expand devcontainer workspace folder failed", slog.Error(err))
}
if dc.ConfigPath != "" {
if dc.ConfigPath, err = expandPathToAbs(dc.ConfigPath); err != nil {
logger.Warn(context.Background(), "expand devcontainer config path failed", slog.Error(err))
}
}
returndir, nil
returndc
}

// EnvAgentSubsystem is the environment variable used to denote the
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp