@@ -243,14 +243,15 @@ func Run(ctx context.Context, options Options) error {
243
243
Depth : options .GitCloneDepth ,
244
244
CABundle : caBundle ,
245
245
})
246
- if err ! = nil {
247
- return err
248
- }
249
-
250
- if cloned {
251
- endStage ( "📦 Cloned repository!" )
246
+ if err = = nil {
247
+ if cloned {
248
+ endStage ( "📦 Cloned repository!" )
249
+ } else {
250
+ endStage ( "📦 The repository already exists!" )
251
+ }
252
252
} else {
253
- endStage ("📦 The repository already exists!" )
253
+ logf (codersdk .LogLevelError , "Failed to clone repository: %s" , err .Error ())
254
+ logf (codersdk .LogLevelError , "Falling back to the default image..." )
254
255
}
255
256
}
256
257
@@ -452,6 +453,17 @@ func Run(ctx context.Context, options Options) error {
452
453
}
453
454
os .Setenv ("HOME" , user .HomeDir )
454
455
456
+ environ , err := os .ReadFile ("/etc/environment" )
457
+ if err == nil {
458
+ for _ , env := range strings .Split (string (environ ), "\n " ) {
459
+ pair := strings .SplitN (env , "=" , 2 )
460
+ if len (pair ) != 2 {
461
+ continue
462
+ }
463
+ os .Setenv (pair [0 ], pair [1 ])
464
+ }
465
+ }
466
+
455
467
// It must be set in this parent process otherwise nothing will be found!
456
468
for _ , env := range configFile .Config .Env {
457
469
pair := strings .SplitN (env , "=" , 2 )
@@ -495,6 +507,11 @@ func Run(ctx context.Context, options Options) error {
495
507
return fmt .Errorf ("remove docker config: %w" , err )
496
508
}
497
509
510
+ err = os .MkdirAll (options .WorkspaceFolder , 0755 )
511
+ if err != nil {
512
+ return fmt .Errorf ("create workspace folder: %w" , err )
513
+ }
514
+
498
515
logf (codersdk .LogLevelInfo , "=== Running the init command %q as the %q user..." , options .InitScript , user .Username )
499
516
cmd := exec .CommandContext (ctx , "/bin/sh" , "-c" , options .InitScript )
500
517
cmd .Env = os .Environ ()
@@ -520,7 +537,13 @@ func Run(ctx context.Context, options Options) error {
520<
104D5
/code>
537
cmd .Stderr = & buf
521
538
}
522
539
523
- return cmd .Run ()
540
+ err = cmd .Run ()
541
+ if err != nil {
542
+ fmt .Printf ("FAILED! %s\n " , err )
543
+ time .Sleep (time .Hour )
544
+ return fmt .Errorf ("run init script: %w" , err )
545
+ }
546
+ return nil
524
547
}
525
548
526
549
// DefaultWorkspaceFolder returns the default workspace folder
0 commit comments