Skip to content

Commit 65e3f09

Browse files
[context parser] Check current ref for Docker image existence (#20345)
* [context parser] Check current ref for Docker image existence * Better builder bob errors from supervisor * Gently soft-fail when the Dockerfile isn't found * Add warning to ws metadata when starting workspace * Introduce a magic constant instead of empty strings * Improve supervisor failed reading bob log error * Fixup cloning our special SHA * idk what happened * let workspaces start even on invalid docker refs
1 parent a6a4c50 commit 65e3f09

File tree

21 files changed

+1329
-896
lines changed

21 files changed

+1329
-896
lines changed

components/dashboard/src/workspaces/CreateWorkspacePage.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,11 @@ export function CreateWorkspacePage() {
552552
<span className="text-sm">{warningIde}</span>
553553
</Alert>
554554
)}
555+
{workspaceContext.data?.data.metadata?.warnings.map((warning) => (
556+
<Alert type="warning" key={warning}>
557+
<span className="text-sm">{warning}</span>
558+
</Alert>
559+
)) ?? []}
555560

556561
<InputField>
557562
<RepositoryFinder

components/gitpod-protocol/src/protocol.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,8 @@ export interface WorkspaceContext {
10181018
normalizedContextURL?: string;
10191019
forceCreateNewWorkspace?: boolean;
10201020
forceImageBuild?: boolean;
1021+
// The context can have non-blocking warnings that should be displayed to the user.
1022+
warnings?: string[];
10211023
}
10221024

10231025
export namespace WorkspaceContext {

components/image-builder-bob/cmd/build.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
package cmd
66

77
import (
8+
"errors"
89
"os"
10+
"strings"
911
"time"
1012

1113
"github.com/spf13/cobra"
@@ -32,6 +34,14 @@ var buildCmd = &cobra.Command{
3234

3335
cfg, err := builder.GetConfigFromEnv()
3436
if err != nil {
37+
if errors.Is(err, builder.DockerfilePathNotExists) {
38+
dockerfilePath := strings.TrimPrefix(os.Getenv("BOB_DOCKERFILE_PATH"), "/workspace/")
39+
err = os.WriteFile("/workspace/.gitpod/bob.log", []byte("could not find Dockerfile at \""+dockerfilePath+"\". Please double-check the value specified in image.file in .gitpod.yml"), 0644)
40+
if err != nil {
41+
log.WithError(err).Error("cannot write init message to /workspace/.gitpod/bob.log")
42+
}
43+
}
44+
3545
log.WithError(err).Fatal("cannot get config")
3646
return
3747
}
@@ -43,6 +53,11 @@ var buildCmd = &cobra.Command{
4353
if err != nil {
4454
log.WithError(err).Error("build failed")
4555

56+
err := os.WriteFile("/workspace/.gitpod/bob.log", []byte(err.Error()), 0644)
57+
if err != nil {
58+
log.WithError(err).Error("cannot write error to /workspace/.gitpod/bob.log")
59+
}
60+
4661
// make sure we're running long enough to have our logs read
4762
if dt := time.Since(t0); dt < 5*time.Second {
4863
time.Sleep(10 * time.Second)

components/image-builder-bob/pkg/builder/config.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ type Config struct {
2929
localCacheImport string
3030
}
3131

32+
var DockerfilePathNotExists = xerrors.Errorf("BOB_DOCKERFILE_PATH does not exist or isn't a file")
33+
3234
// GetConfigFromEnv extracts configuration from environment variables
3335
func GetConfigFromEnv() (*Config, error) {
3436
cfg := &Config{
@@ -63,7 +65,7 @@ func GetConfigFromEnv() (*Config, error) {
6365
return nil, xerrors.Errorf("BOB_DOCKERFILE_PATH must begin with /workspace")
6466
}
6567
if stat, err := os.Stat(cfg.Dockerfile); err != nil || stat.IsDir() {
66-
return nil, xerrors.Errorf("BOB_DOCKERFILE_PATH does not exist or isn't a file")
68+
return nil, DockerfilePathNotExists
6769
}
6870
}
6971

components/public-api/gitpod/v1/workspace.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,9 @@ message WorkspaceMetadata {
316316
// original_context_url is the normalized URL from which the workspace was
317317
// created
318318
string original_context_url = 7;
319+
320+
// warnings are user-facing warnings that should be displayed to the user when trying to start the workspace
321+
repeated string warnings = 8;
319322
}
320323

321324
// WorkspaceSpec specifies the configuration of a workspace for a workspace

components/public-api/go/v1/workspace.pb.go

Lines changed: 598 additions & 587 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)