Skip to content

Commit 8e22427

Browse files
authored
feat: expose runtime markers (#223)
1 parent ab86184 commit 8e22427

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

envbuilder.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,15 @@ func Run(ctx context.Context, options Options) error {
259259
var (
260260
buildParams *devcontainer.Compiled
261261
scripts devcontainer.LifecycleScripts
262+
263+
devcontainerPath string
262264
)
263265
if options.DockerfilePath == "" {
264266
// Only look for a devcontainer if a Dockerfile wasn't specified.
265267
// devcontainer is a standard, so it's reasonable to be the default.
266-
devcontainerPath, devcontainerDir, err := findDevcontainerJSON(options)
268+
var devcontainerDir string
269+
var err error
270+
devcontainerPath, devcontainerDir, err = findDevcontainerJSON(options)
267271
if err != nil {
268272
options.Logger(notcodersdk.LogLevelError, "Failed to locate devcontainer.json: %s", err.Error())
269273
options.Logger(notcodersdk.LogLevelError, "Falling back to the default image...")
@@ -661,6 +665,13 @@ func Run(ctx context.Context, options Options) error {
661665
maps.Copy(containerEnv, buildParams.ContainerEnv)
662666
maps.Copy(remoteEnv, buildParams.RemoteEnv)
663667

668+
// Set Envbuilder runtime markers
669+
containerEnv["ENVBUILDER"] = "true"
670+
if devcontainerPath != "" {
671+
containerEnv["DEVCONTAINER"] = "true"
672+
containerEnv["DEVCONTAINER_CONFIG"] = devcontainerPath
673+
}
674+
664675
for _, env := range []map[string]string{containerEnv, remoteEnv} {
665676
envKeys := make([]string, 0, len(env))
666677
for key := range env {

envbuilder_internal_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestFindDevcontainerJSON(t *testing.T) {
2727
require.Error(t, err)
2828
})
2929

30-
t.Run("devcontainers.json is missing", func(t *testing.T) {
30+
t.Run("devcontainer.json is missing", func(t *testing.T) {
3131
t.Parallel()
3232

3333
// given

integration/integration_test.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,10 @@ func TestContainerEnv(t *testing.T) {
680680

681681
output := execContainer(t, ctr, "cat /env")
682682
require.Contains(t, strings.TrimSpace(output),
683-
`FROM_CONTAINER_ENV=bar
683+
`DEVCONTAINER=true
684+
DEVCONTAINER_CONFIG=/workspaces/empty/.devcontainer/devcontainer.json
685+
ENVBUILDER=true
686+
FROM_CONTAINER_ENV=bar
684687
FROM_DOCKERFILE=foo
685688
FROM_REMOTE_ENV=baz
686689
PATH=/usr/local/bin:/bin:/go/bin:/opt

0 commit comments

Comments
 (0)