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 cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ go build -o /opt/homebrew/bin/viam cli/viam/main.go

Then afterwards reset your homebrew installation with:
```sh
brew link --overwrite viam
brew unlink viam && brew link --overwrite viam
```
24 changes: 15 additions & 9 deletions cli/module_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ func (c *viamClient) ensureModuleRegisteredInCloud(ctx *cli.Context, moduleID mo
}

// moduleCloudReload triggers a cloud build and then reloads the specified module with that build.
func (c *viamClient) moduleCloudReload(ctx *cli.Context, args reloadModuleArgs, platform string) (string, error) {
func (c *viamClient) moduleCloudReload(ctx *cli.Context, args reloadModuleArgs, platform, partID string) (string, error) {
manifest, err := loadManifest(args.Module)
if err != nil {
return "", err
Expand Down Expand Up @@ -762,13 +762,14 @@ func (c *viamClient) moduleCloudReload(ctx *cli.Context, args reloadModuleArgs,
// Upload a package with the bundled local dev code. Note that "reload" is a sentinel
// value for hot reloading modules. App expects it; don't change without making a
// complimentary update to the app repo
resp, err := c.uploadPackage(org.GetId(), reloadVersion, reloadVersion, "module", archivePath, nil)
reloadSourceVersionFormatted := getReloadVersion(reloadSourceVersionPrefix, partID)
resp, err := c.uploadPackage(org.GetId(), moduleID.name, reloadSourceVersionFormatted, "module", archivePath, nil)
if err != nil {
return "", err
}

// get package URL for downloading purposes
packageURL, err := c.getPackageDownloadURL(org.GetId(), reloadVersion, reloadVersion, "module")
packageURL, err := c.getPackageDownloadURL(org.GetId(), moduleID.name, reloadSourceVersionFormatted, "module")
if err != nil {
return "", err
}
Expand All @@ -785,9 +786,10 @@ func (c *viamClient) moduleCloudReload(ctx *cli.Context, args reloadModuleArgs,
// TODO (RSDK-11692) - passing org ID in the ref field and `resp.Version` (which is actually an object ID)
// in the token field is pretty hacky, let's fix it up
infof(c.c.App.Writer, "Creating a new cloud build and swapping it onto the requested machine part. This may take a few minutes...")
reloadVersionFormatted := getReloadVersion(reloadVersionPrefix, partID)
buildArgs := moduleBuildStartArgs{
Module: args.Module,
Version: reloadVersion,
Version: reloadVersionFormatted,
Workdir: args.Workdir,
Ref: org.GetId(),
Platforms: []string{platform},
Expand Down Expand Up @@ -819,17 +821,17 @@ func (c *viamClient) moduleCloudReload(ctx *cli.Context, args reloadModuleArgs,

downloadArgs := downloadModuleFlags{
ID: id,
Version: reloadVersion,
Version: reloadVersionFormatted,
Platform: platform,
}

// delete the package now that the build is complete
_, err = c.packageClient.DeletePackage(
ctx.Context,
&v1.DeletePackageRequest{Id: resp.GetId(), Version: reloadVersion, Type: v1.PackageType_PACKAGE_TYPE_MODULE},
&v1.DeletePackageRequest{Id: resp.GetId(), Version: reloadSourceVersionFormatted, Type: v1.PackageType_PACKAGE_TYPE_MODULE},
)
if err != nil {
warningf(ctx.App.Writer, "failed to delete package: %s", err.Error())
warningf(ctx.App.Writer, "failed to delete reload source code package: %s", err.Error())
}

// delete the archive we created
Expand Down Expand Up @@ -860,6 +862,10 @@ func ReloadModuleAction(c *cli.Context, args reloadModuleArgs) error {
return reloadModuleAction(c, vc, args, logger)
}

func getReloadVersion(versionPrefix, partID string) string {
return versionPrefix + "-" + partID
}

// reload with cloudbuild was supported starting in 0.90.0
// there are older versions of viam-servet that don't support ~/ file prefix, so lets avoid using them.
var reloadVersionSupported = semver.MustParse("0.90.0")
Expand Down Expand Up @@ -939,7 +945,7 @@ func reloadModuleAction(
err = moduleBuildLocalAction(c, manifest, environment)
buildPath = manifest.Build.Path
} else {
buildPath, err = vc.moduleCloudReload(c, args, platform)
buildPath, err = vc.moduleCloudReload(c, args, platform, partID)
}
if err != nil {
return err
Expand Down Expand Up @@ -970,7 +976,7 @@ func reloadModuleAction(
dest := reloadingDestination(c, manifest)
err = vc.copyFilesToFqdn(
part.Part.Fqdn, globalArgs.Debug, false, false, []string{buildPath},
dest, logging.NewLogger(reloadVersion), args.NoProgress)
dest, logging.NewLogger(reloadVersionPrefix), args.NoProgress)
if err != nil {
if s, ok := status.FromError(err); ok && s.Code() == codes.PermissionDenied {
warningf(c.App.ErrWriter, "RDK couldn't write to the default file copy destination. "+
Expand Down
5 changes: 4 additions & 1 deletion cli/module_reload.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ import (
rutils "go.viam.com/rdk/utils"
)

const reloadVersion = "reload"
const (
reloadVersionPrefix = "reload"
reloadSourceVersionPrefix = "reload-source"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the difference between these two? one is the source tarball that gets fed into cloud build, the other is the binary artifact that is produced?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup that is the difference.

)

// ModuleMap is a type alias to indicate where a map represents a module config.
// We don't convert to rdkConfig.Module because it can get out of date with what's in the db.
Expand Down
Loading