diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 53a725f..c41a29a 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -3,7 +3,7 @@ # Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. #------------------------------------------------------------------------------------------------------------- -FROM golang:1.17-stretch +FROM golang:1.17-bullseye # Avoid warnings by switching to noninteractive ENV DEBIAN_FRONTEND=noninteractive diff --git a/go.mod b/go.mod index 1aed690..7d858e7 100644 --- a/go.mod +++ b/go.mod @@ -6,12 +6,12 @@ require ( github.com/blang/semver v3.5.1+incompatible github.com/bradford-hamilton/dora v0.1.1 github.com/kyoh86/richgo v0.3.12 // indirect - github.com/mattn/go-isatty v0.0.18 // indirect + github.com/mattn/go-isatty v0.0.19 // indirect github.com/rhysd/go-github-selfupdate v1.2.2 github.com/spf13/cobra v1.0.0 github.com/spf13/viper v1.4.0 github.com/stretchr/testify v1.8.2 - golang.org/x/sys v0.8.0 // indirect + golang.org/x/sys v0.10.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect ) diff --git a/go.sum b/go.sum index 5856423..f48d0fe 100644 --- a/go.sum +++ b/go.sum @@ -82,6 +82,8 @@ github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPn github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.18 h1:DOKFKCQ7FNG2L1rbrmstDN4QVRdS89Nkh85u68Uwp98= github.com/mattn/go-isatty v0.0.18/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= +github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE= @@ -194,6 +196,8 @@ golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= +golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= diff --git a/internal/pkg/devcontainers/devcontainer.go b/internal/pkg/devcontainers/devcontainer.go new file mode 100644 index 0000000..c7c7fe4 --- /dev/null +++ b/internal/pkg/devcontainers/devcontainer.go @@ -0,0 +1,22 @@ +package devcontainers + +import ( + "fmt" + "os" + "path/filepath" + "strings" +) + +func getDevContainerJsonPath(folderPath string) (string, error) { + pathsToTest := []string{".devcontainer/devcontainer.json", ".devcontainer.json"} + + for _, path := range pathsToTest { + devcontainerJsonPath := filepath.Join(folderPath, path) + devContainerJsonInfo, err := os.Stat(devcontainerJsonPath) + if err == nil && !devContainerJsonInfo.IsDir() { + return devcontainerJsonPath, nil + } + } + + return "", fmt.Errorf("devcontainer.json not found. Looked for %s", strings.Join(pathsToTest, ",")) +} diff --git a/internal/pkg/devcontainers/dockerutils.go b/internal/pkg/devcontainers/dockerutils.go index 6c4ce20..d96b1f2 100644 --- a/internal/pkg/devcontainers/dockerutils.go +++ b/internal/pkg/devcontainers/dockerutils.go @@ -234,7 +234,10 @@ func ExecInDevContainer(containerID string, workDir string, args []string) error localPath := sourceInfo.DevcontainerFolder statusWriter.Printf("Getting user name") - devcontainerJSONPath := path.Join(localPath, ".devcontainer/devcontainer.json") + devcontainerJSONPath, err := getDevContainerJsonPath(localPath) + if err != nil { + return err + } userName, err := GetDevContainerUserName(devcontainerJSONPath) if err != nil { return err diff --git a/internal/pkg/devcontainers/remoteuri.go b/internal/pkg/devcontainers/remoteuri.go index ea016ec..744dc75 100644 --- a/internal/pkg/devcontainers/remoteuri.go +++ b/internal/pkg/devcontainers/remoteuri.go @@ -57,7 +57,10 @@ func GetWorkspaceMountPath(folderPath string) (string, error) { } } - devcontainerDefinitionPath := filepath.Join(folderPath, ".devcontainer/devcontainer.json") + devcontainerDefinitionPath, err := getDevContainerJsonPath(folderPath) + if err != nil { + return "", fmt.Errorf("Error getting devcontainer definition path: %s", err) + } buf, err := ioutil.ReadFile(devcontainerDefinitionPath) if err != nil { return "", fmt.Errorf("Error loading devcontainer definition: %s", err) diff --git a/internal/pkg/devcontainers/snippet.go b/internal/pkg/devcontainers/snippet.go index f06e7a1..96bc848 100644 --- a/internal/pkg/devcontainers/snippet.go +++ b/internal/pkg/devcontainers/snippet.go @@ -320,6 +320,7 @@ func insertDockerfileSnippet(projectFolder string, dockerfileFilename string, sn } content := newContent.String() + // TODO - decide whether to support .devcontainer.json or just remove snippet support values, err := getSubstitutionValuesFromFile(filepath.Join(projectFolder, ".devcontainer/devcontainer.json")) if err != nil { return fmt.Errorf("failed to get dev container values: %s", err) @@ -358,6 +359,7 @@ func mergeJSON(projectFolder string, snippet *DevcontainerSnippet, relativeMerge return err } + // TODO - decide whether to support .devcontainer.json or just remove snippet support values, err := getSubstitutionValuesFromFile(filepath.Join(projectFolder, ".devcontainer/devcontainer.json")) if err != nil { return fmt.Errorf("failed to get dev container values: %s", err) diff --git a/internal/pkg/devcontainers/template.go b/internal/pkg/devcontainers/template.go index bb0f53b..34e08ff 100644 --- a/internal/pkg/devcontainers/template.go +++ b/internal/pkg/devcontainers/template.go @@ -76,6 +76,7 @@ func getTemplatesFromFolder(folder string) ([]DevcontainerTemplate, error) { if !fi.IsDir() { return false } + // TOODO - add support for templates with .devcontainer.json rather than .devcontainer folder devcontainerJsonPath := filepath.Join(parentPath, fi.Name(), ".devcontainer/devcontainer.json") devContainerJsonInfo, err := os.Stat(devcontainerJsonPath) return err == nil && !devContainerJsonInfo.IsDir()