@@ -1075,7 +1075,7 @@ func (a *agent) handleManifest(manifestOK *checkpoint) func(ctx context.Context,
1075
1075
//
1076
1076
// An example is VS Code Remote, which must know the directory
1077
1077
// before initializing a connection.
1078
- manifest .Directory , err = expandDirectory (manifest .Directory )
1078
+ manifest .Directory , err = expandPathToAbs (manifest .Directory )
1079
1079
if err != nil {
1080
1080
return xerrors .Errorf ("expand directory: %w" , err )
1081
1081
}
@@ -1119,13 +1119,18 @@ func (a *agent) handleManifest(manifestOK *checkpoint) func(ctx context.Context,
1119
1119
// scripts have completed.
1120
1120
var postStartScripts []codersdk.WorkspaceAgentScript
1121
1121
for _ , dc := range manifest .Devcontainers {
1122
+ dc = expandDevcontainerPaths (a .logger , dc )
1122
1123
// TODO(mafredri): Verify `@devcontainers/cli` presence.
1123
1124
// TODO(mafredri): Verify workspace folder exists.
1124
1125
// TODO(mafredri): If set, verify config path exists.
1125
1126
postStartScripts = append (postStartScripts , agentcontainers .DevcontainerStartupScript (dc ))
1126
1127
}
1127
1128
1128
- err = a .scriptRunner .Init (manifest .Scripts , aAPI .ScriptCompleted , agentscripts .WithPostStartScripts (postStartScripts ... ))
1129
+ err = a .scriptRunner .Init (
1130
+ manifest .Scripts ,
1131
+ aAPI .ScriptCompleted ,
1132
+ agentscripts .WithPostStartScripts (postStartScripts ... ),
1133
+ )
1129
1134
if err != nil {
1130
1135
return xerrors .Errorf ("init script runner: %w" , err )
1131
1136
}
@@ -1864,30 +1869,42 @@ func userHomeDir() (string, error) {
1864
1869
return u .HomeDir , nil
1865
1870
}
1866
1871
1867
- // expandDirectory converts a directory path to an absolute path.
1868
- // It primarily resolves the home directory and any environment
1869
- // variables that may be set
1870
- func expandDirectory (dir string ) (string , error ) {
1871
- if dir == "" {
1872
+ // expandPathToAbs converts a path to an absolute path. It primarily resolves
1873
+ // the home directory and any environment variables that may be set.
1874
+ func expandPathToAbs (path string ) (string , error ) {
1875
+ if path == "" {
1872
1876
return "" , nil
1873
1877
}
1874
- if dir [0 ] == '~' {
1878
+ if path [0 ] == '~' {
1875
1879
home , err := userHomeDir ()
1876
1880
if err != nil {
1877
1881
return "" , err
1878
1882
}
1879
- dir = filepath .Join (home , dir [1 :])
1883
+ path = filepath .Join (home , path [1 :])
1880
1884
}
1881
- dir = os .ExpandEnv (dir )
1885
+ path = os .ExpandEnv (path )
1882
1886
1883
- if ! filepath .IsAbs (dir ) {
1887
+ if ! filepath .IsAbs (path ) {
1884
1888
home , err := userHomeDir ()
1885
1889
if err != nil {
1886
1890
return "" , err
1887
1891
}
1888
- dir = filepath .Join (home , dir )
1892
+ path = filepath .Join (home , path )
1893
+ }
1894
+ return path , nil
1895
+ }
1896
+
1897
+ func expandDevcontainerPaths (logger slog.Logger , dc codersdk.WorkspaceAgentDevcontainer ) codersdk.WorkspaceAgentDevcontainer {
1898
+ var err error
1899
+ if dc .WorkspaceFolder , err = expandPathToAbs (dc .WorkspaceFolder ); err != nil {
1900
+ logger .Warn (context .Background (), "expand devcontainer workspace folder failed" , slog .Error (err ))
1901
+ }
1902
+ if dc .ConfigPath != "" {
1903
+ if dc .ConfigPath , err = expandPathToAbs (dc .ConfigPath ); err != nil {
1904
+ logger .Warn (context .Background (), "expand devcontainer config path failed" , slog .Error (err ))
1905
+ }
1889
1906
}
1890
- return dir , nil
1907
+ return dc
1891
1908
}
1892
1909
1893
1910
// EnvAgentSubsystem is the environment variable used to denote the
0 commit comments