Skip to content

Instantly share code, notes, and snippets.

@abserari
Created November 21, 2022 09:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abserari/f7e941e1543b0eb319676a38a09b574e to your computer and use it in GitHub Desktop.
Save abserari/f7e941e1543b0eb319676a38a09b574e to your computer and use it in GitHub Desktop.
Go Install Binary Program in Dapr
// installBinary installs the daprd, placement or dashboard binaries and associated files inside the default dapr bin directory.
func installBinary(version, binaryFilePrefix, githubRepo string, info initInfo) error {
var (
err error
filepath string
)
dir := defaultDaprBinPath()
if isAirGapInit {
filepath = path_filepath.Join(info.fromDir, *info.bundleDet.BinarySubDir, binaryName(binaryFilePrefix))
} else {
filepath, err = downloadBinary(dir, version, binaryFilePrefix, githubRepo)
if err != nil {
return fmt.Errorf("error downloading %s binary: %w", binaryFilePrefix, err)
}
}
extractedFilePath, err := extractFile(filepath, dir, binaryFilePrefix)
if err != nil {
return err
}
// remove downloaded archive from the default dapr bin path.
if !isAirGapInit {
err = os.Remove(filepath)
if err != nil {
return fmt.Errorf("failed to remove archive: %w", err)
}
}
if binaryFilePrefix == "dashboard" {
extractedFilePath, err = moveDashboardFiles(extractedFilePath, dir)
if err != nil {
return err
}
}
binaryPath, err := moveFileToPath(extractedFilePath, dir)
if err != nil {
return fmt.Errorf("error moving %s binary to path: %w", binaryFilePrefix, err)
}
err = makeExecutable(binaryPath)
if err != nil {
return fmt.Errorf("error making %s binary executable: %w", binaryFilePrefix, err)
}
return nil
}
@abserari
Copy link
Author

abserari commented Nov 21, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment