Skip to content

Commit be75a5d

Browse files
committed
Support content initializer as env var
1 parent 31a9057 commit be75a5d

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

components/supervisor/pkg/supervisor/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,9 @@ type WorkspaceConfig struct {
331331

332332
WorkspaceLinuxUID uint32 `env:"GITPOD_WORKSPACE_LINUX_UID,default=33333"`
333333
WorkspaceLinuxGID uint32 `env:"GITPOD_WORKSPACE_LINUX_GID,default=33333"`
334+
335+
// ContentInitializer - if set - will run the content initializer instead of waiting for the ready file
336+
ContentInitializer string `env:"SUPERVISOR_CONTENT_INITIALIZER"`
334337
}
335338

336339
// WorkspaceGitpodToken is a list of tokens that should be added to supervisor's token service.

components/supervisor/pkg/supervisor/supervisor.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package supervisor
66

77
import (
8+
"bytes"
89
"context"
910
"crypto/rand"
1011
"crypto/rsa"
@@ -1490,14 +1491,15 @@ func startContentInit(ctx context.Context, cfg *Config, wg *sync.WaitGroup, cst
14901491
fn := "/workspace/.gitpod/content.json"
14911492
fnReady := "/workspace/.gitpod/ready"
14921493

1493-
contentFile, err := os.Open(fn)
1494-
if err != nil {
1495-
if !os.IsNotExist(err) {
1496-
log.WithError(err).Error("cannot open init descriptor")
1497-
return
1498-
}
1499-
1500-
log.Infof("%s does not exist, going to wait for %s", fn, fnReady)
1494+
contentFile, err := os.ReadFile(fn)
1495+
if os.IsNotExist(err) {
1496+
contentFile = []byte(cfg.ContentInitializer)
1497+
} else if err != nil {
1498+
log.WithError(err).Error("cannot open init descriptor")
1499+
return
1500+
}
1501+
if len(contentFile) == 0 {
1502+
log.Infof("no content initializer provided, waiting for %s", fnReady)
15011503

15021504
// If there is no content descriptor the content must have come from somewhere (i.e. a layer or ws-daemon).
15031505
// Let's wait for that to happen.
@@ -1529,11 +1531,9 @@ func startContentInit(ctx context.Context, cfg *Config, wg *sync.WaitGroup, cst
15291531
return
15301532
}
15311533

1532-
defer contentFile.Close()
1533-
15341534
log.Info("supervisor: running content service executor with content descriptor")
15351535
var src csapi.WorkspaceInitSource
1536-
src, err = executor.Execute(ctx, "/workspace", contentFile, true)
1536+
src, err = executor.Execute(ctx, "/workspace", bytes.NewReader(contentFile), true)
15371537
if err != nil {
15381538
return
15391539
}

0 commit comments

Comments
 (0)