Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: daytona update command with elevated perms #1713

Merged
merged 4 commits into from
Jan 20, 2025
Merged
Changes from 3 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
33 changes: 22 additions & 11 deletions pkg/cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/daytonaio/daytona/internal"
"github.com/inconshreveable/go-update"
"github.com/spf13/cobra"
"golang.org/x/mod/semver"
"net/http"
"net/url"
"regexp"
"runtime"
"strings"

"github.com/daytonaio/daytona/internal"
"github.com/inconshreveable/go-update"
"github.com/spf13/cobra"
"golang.org/x/mod/semver"
)

const (
Expand Down Expand Up @@ -88,10 +89,13 @@ var updateCmd = &cobra.Command{
}

fmt.Println("Updating to version", version, "from", currentVersion)
fmt.Print("\nChangelog:\n\n")
fmt.Println(changelog)

return updateToVersion(version)
err = updateToVersion(version, changelog)
if err != nil {
return err
}

return nil
},
}

Expand Down Expand Up @@ -146,7 +150,7 @@ func fetchVersionRelease(version string) (*GitHubRelease, error) {
return nil, fmt.Errorf("version %s not found", version)
}

func updateToVersion(version string) error {
func updateToVersion(version, changelog string) error {

url, err := getBinaryUrl(version)
if err != nil {
Expand All @@ -165,18 +169,25 @@ func updateToVersion(version string) error {
}

err = update.Apply(resp.Body, update.Options{})

if err != nil {
fmt.Println("Failed to update binary")
if rollbackErr := update.RollbackError(err); rollbackErr != nil {
return fmt.Errorf("failed to rollback: %w", rollbackErr)
}

return fmt.Errorf("failed to update binary: %w", err)
}
if strings.Contains(err.Error(), "permission") {
if runtime.GOOS == "windows" {
return fmt.Errorf("%w\nPlease run 'daytona update' as administrator", err)
}

return fmt.Errorf("%w\nPlease run the command with `sudo`", err)
}
}
fmt.Print("\nChangelog:\n\n")
fmt.Println(changelog)
fmt.Println("\nSuccessfully updated to version", version)
fmt.Println("If your Server is running, you need to restart it for the changes to take effect.")

return nil
}

Expand Down
Loading