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
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
22 changes: 22 additions & 0 deletions internal/pkg/devcontainers/devcontainer.go
Original file line number Diff line number Diff line change
@@ -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, ","))
}
5 changes: 4 additions & 1 deletion internal/pkg/devcontainers/dockerutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion internal/pkg/devcontainers/remoteuri.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions internal/pkg/devcontainers/snippet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/devcontainers/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down