Skip to content

Commit

Permalink
Add env var which points to ko app
Browse files Browse the repository at this point in the history
  • Loading branch information
creydr committed Sep 11, 2023
1 parent b9ad37d commit 7f2546f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/build/gobuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -908,13 +908,15 @@ func (g *gobuild) buildOne(ctx context.Context, refStr string, base v1.Image, pl

updatePath(cfg, `C:\ko-app`)
cfg.Config.Env = append(cfg.Config.Env, `KO_DATA_PATH=C:\var\run\ko`)
cfg.Config.Env = append(cfg.Config.Env, `KO_APP_PATH=C:\ko-app\`+appFileName)
} else {
if !g.disableEntrypointOverwrite {
cfg.Config.Entrypoint = []string{appPath}
}

updatePath(cfg, appDir)
cfg.Config.Env = append(cfg.Config.Env, "KO_DATA_PATH="+kodataRoot)
cfg.Config.Env = append(cfg.Config.Env, "KO_APP_PATH="+appPath)
}
cfg.Author = "github.com/ko-build/ko"

Expand Down
17 changes: 17 additions & 0 deletions pkg/build/gobuild_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,23 @@ func validateImage(t *testing.T, img oci.SignedImage, baseLayers int64, creation
}
})

// Check that the environment contains the KO_APP_PATH environment variable.
t.Run("check KO_APP_PATH env var", func(t *testing.T) {
cfg, err := img.ConfigFile()
if err != nil {
t.Errorf("ConfigFile() = %v", err)
}
found := false
for _, entry := range cfg.Config.Env {
if entry == "KO_APP_PATH=/ko-app/ko" {
found = true
}
}
if !found {
t.Error("Didn't find KO_APP_PATH.")
}
})

// Check that PATH contains the directory of the produced binary.
t.Run("check PATH env var", func(t *testing.T) {
cfg, err := img.ConfigFile()
Expand Down

0 comments on commit 7f2546f

Please sign in to comment.