MCPcopy Index your code
hub / github.com/devspace-sh/devspace / install

Method install

pkg/devspace/plugin/plugin.go:98–172  ·  view source on GitHub ↗
(path, version string)

Source from the content-addressed store, hash-verified

96}
97
98func (c *client) install(path, version string) (*Metadata, error) {
99 metadata, err := c.installer.DownloadMetadata(path, version)
100 if err != nil {
101 return nil, errors.Wrap(err, "download metadata")
102 }
103
104 // find binary for system
105 found := false
106 binaryPath := ""
107 for _, binary := range metadata.Binaries {
108 if binary.OS == runtime.GOOS && binary.Arch == runtime.GOARCH {
109 found = true
110 binaryPath = binary.Path
111 break
112 }
113 }
114 if !found {
115 return nil, fmt.Errorf("plugin %s does not support %s/%s", metadata.Name, runtime.GOOS, runtime.GOARCH)
116 }
117
118 // download binary to temp folder and test it
119 tempBinaryName := "./plugin-binary"
120 if runtime.GOOS == "windows" {
121 tempBinaryName += ".exe"
122 }
123 err = c.installer.DownloadBinary(path, version, binaryPath, tempBinaryName)
124 if err != nil {
125 return nil, errors.Wrap(err, "download plugin binary")
126 }
127 _ = os.Chmod(tempBinaryName, 0755)
128
129 // test the binary
130 absolutePath, err := filepath.Abs(tempBinaryName)
131 if err != nil {
132 return nil, err
133 }
134 o, err := exec.Command(absolutePath).Output()
135 if err != nil {
136 _ = os.Remove(absolutePath)
137 return nil, fmt.Errorf("error executing plugin binary, make sure the plugin binary is executable and returns a zero exit code when run without arguments: %s => %v", string(o), err)
138 }
139
140 // create the plugin folder
141 pluginFolder, err := c.PluginFolder()
142 if err != nil {
143 return nil, err
144 }
145
146 pluginFolder = filepath.Join(pluginFolder, Encode(path))
147 err = os.MkdirAll(pluginFolder, 0755)
148 if err != nil {
149 return nil, err
150 }
151
152 out, err := yaml.Marshal(metadata)
153 if err != nil {
154 return nil, err
155 }

Callers 2

AddMethod · 0.95
UpdateMethod · 0.95

Calls 7

PluginFolderMethod · 0.95
EncodeFunction · 0.85
moveFileFunction · 0.85
DownloadMetadataMethod · 0.65
DownloadBinaryMethod · 0.65
RemoveMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected