Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion envbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,15 @@ func Run(ctx context.Context, options Options) error {
var (
buildParams *devcontainer.Compiled
scripts devcontainer.LifecycleScripts

devcontainerPath string
)
if options.DockerfilePath == "" {
// Only look for a devcontainer if a Dockerfile wasn't specified.
// devcontainer is a standard, so it's reasonable to be the default.
devcontainerPath, devcontainerDir, err := findDevcontainerJSON(options)
var devcontainerDir string
var err error
devcontainerPath, devcontainerDir, err = findDevcontainerJSON(options)
if err != nil {
options.Logger(notcodersdk.LogLevelError, "Failed to locate devcontainer.json: %s", err.Error())
options.Logger(notcodersdk.LogLevelError, "Falling back to the default image...")
Expand Down Expand Up @@ -661,6 +665,13 @@ func Run(ctx context.Context, options Options) error {
maps.Copy(containerEnv, buildParams.ContainerEnv)
maps.Copy(remoteEnv, buildParams.RemoteEnv)

// Set Envbuilder runtime markers
containerEnv["ENVBUILDER"] = "true"
if devcontainerPath != "" {
containerEnv["DEVCONTAINER"] = "true"
containerEnv["DEVCONTAINER_CONFIG"] = devcontainerPath
}

for _, env := range []map[string]string{containerEnv, remoteEnv} {
envKeys := make([]string, 0, len(env))
for key := range env {
Expand Down
2 changes: 1 addition & 1 deletion envbuilder_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestFindDevcontainerJSON(t *testing.T) {
require.Error(t, err)
})

t.Run("devcontainers.json is missing", func(t *testing.T) {
t.Run("devcontainer.json is missing", func(t *testing.T) {
t.Parallel()

// given
Expand Down
5 changes: 4 additions & 1 deletion integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,10 @@ func TestContainerEnv(t *testing.T) {

output := execContainer(t, ctr, "cat /env")
require.Contains(t, strings.TrimSpace(output),
`FROM_CONTAINER_ENV=bar
`DEVCONTAINER=true
DEVCONTAINER_CONFIG=/workspaces/empty/.devcontainer/devcontainer.json
ENVBUILDER=true
FROM_CONTAINER_ENV=bar
FROM_DOCKERFILE=foo
FROM_REMOTE_ENV=baz
PATH=/usr/local/bin:/bin:/go/bin:/opt
Expand Down