-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(CLI): Download midi-ssh instead of the built-in one (#73)
* feat: Move ssh into cache Signed-off-by: Ce Gao <cegao@tensorchord.ai> * fix: Simplify the build progress logging Signed-off-by: Ce Gao <cegao@tensorchord.ai>
- Loading branch information
Showing
8 changed files
with
99 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package home | ||
|
||
import ( | ||
"io" | ||
"net/http" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/cockroachdb/errors" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
func (m generalManager) SSHBinaryFile() string { | ||
return "midi-ssh" | ||
} | ||
|
||
func (m generalManager) DownloadOrCacheSSHBinary(url string) error { | ||
//TODO(gaocegege): Check the checksums.txt first. | ||
// https://github.com/tensorchord/MIDI/releases/download/v0.0.1-alpha.1/checksums.txt | ||
|
||
filename := filepath.Join(m.CacheDir(), m.SSHBinaryFile()) | ||
logger := logrus.WithFields(logrus.Fields{ | ||
"url": url, | ||
"filename": filename, | ||
}) | ||
out, err := os.Create(filename) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
defer out.Close() | ||
|
||
resp, err := http.Get(url) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to download ssh binary") | ||
} | ||
logger.Debugf("downloading %s", filename) | ||
|
||
defer resp.Body.Close() | ||
_, err = io.Copy(out, resp.Body) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to download ssh binary") | ||
} | ||
|
||
if err := os.Chmod(filename, 0755); err != nil { | ||
return errors.Wrap(err, "failed to chmod ssh binary") | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters