Skip to content

Commit

Permalink
dockercompose.json の dockerComposeFile の型不正 を修正。
Browse files Browse the repository at this point in the history
  • Loading branch information
mikoto2000 committed Jun 22, 2024
1 parent f0f23f5 commit 1ac69b2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion devcontainer/DevcontainerJson.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

// devcontainer.json のスキーマ(の一部)
type DevcontainerJSON struct {
DockerComposeFile []string `json:"dockerComposeFile"`
DockerComposeFile interface{} `json:"dockerComposeFile"`
}

func UnmarshalDevcontainerJSON(data []byte) (DevcontainerJSON, error) {
Expand Down
15 changes: 14 additions & 1 deletion devcontainer/devcontainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var devcontainreArgsPrefix = []string{"up"}
// devcontainer でコンテナを立ち上げ、 Vim を転送し、実行する。
// 既存実装の都合上、configFilePath から configDirForDevcontainer を抽出している
func ExecuteDevcontainer(args []string, devcontainerPath string, vimFilePath string, cdrPath, configFilePath string, vimrc string) {

vimFileName := filepath.Base(vimFilePath)

// コマンドライン引数の末尾は `--workspace-folder` の値として使う
Expand Down Expand Up @@ -335,7 +336,19 @@ func findDockerComposeFileDir() (string, error) {
if err != nil {
return "", err
}
dockerComposeFilePath := filepath.Join(devcontainerJSONDir, devcontainerJSON.DockerComposeFile[0])

// string, []string を判別しながら docker-compose.yaml の場所を取得
iDockerComposeFile := devcontainerJSON.DockerComposeFile
var dockerComposeFilePath string
switch v := iDockerComposeFile.(type) {
case string:
dockerComposeFilePath = v
case []interface{}:
vv := v[0].(string)
dockerComposeFilePath = filepath.Join(devcontainerJSONDir, vv)
default:
return "", errors.New("unknown type")
}
dockerComposeFileDir := filepath.Dir(dockerComposeFilePath)

// fmt.Printf("dockerComposeFileDir directory: %s\n", dockerComposeFileDir)
Expand Down

0 comments on commit 1ac69b2

Please sign in to comment.