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

Update cmd #2333

Merged
merged 6 commits into from
Dec 10, 2024
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
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ WORKDIR /
# Copy the executables into the container
COPY --from=builder /build/bin/avalanche .
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
RUN /avalanche config update disable
ENTRYPOINT [ "./avalanche" ]
1 change: 1 addition & 0 deletions Dockerfile.release
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM debian:11-slim
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
COPY avalanche /
RUN /avalanche config update disable
ENTRYPOINT [ "/avalanche" ]
1 change: 1 addition & 0 deletions cmd/configcmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func NewCmd(injectedApp *application.Avalanche) *cobra.Command {
app = injectedApp
// set user metrics collection preferences cmd
cmd.AddCommand(newMetricsCmd())
cmd.AddCommand(newUpdateCmd())
cmd.AddCommand(newMigrateCmd())
cmd.AddCommand(newAuthorizeCloudAccessCmd())
cmd.AddCommand(newSnapshotsAutoSaveCmd())
Expand Down
49 changes: 49 additions & 0 deletions cmd/configcmd/update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (C) 2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package configcmd

import (
"errors"

"github.com/ava-labs/avalanche-cli/pkg/cobrautils"
"github.com/ava-labs/avalanche-cli/pkg/constants"
"github.com/ava-labs/avalanche-cli/pkg/ux"
"github.com/spf13/cobra"
)

// avalanche config metrics command
func newUpdateCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "update [enable | disable]",
Short: "opt in or out of update check",
Long: "set user preference between update check or not",
RunE: handleUpdateSettings,
Args: cobrautils.ExactArgs(1),
}

return cmd
}

func handleUpdateSettings(_ *cobra.Command, args []string) error {
switch args[0] {
case constants.Enable:
ux.Logger.PrintToUser("Thank you for opting in Avalanche CLI automated update check")
err := saveUpdateDisabledPreferences(false)
if err != nil {
return err
}
case constants.Disable:
ux.Logger.PrintToUser("Avalanche CLI automated update check will no longer be performed")
err := saveUpdateDisabledPreferences(true)
if err != nil {
return err
}
default:
return errors.New("Invalid update argument '" + args[0] + "'")
}
return nil
}

func saveUpdateDisabledPreferences(disableUpdate bool) error {
return app.Conf.SetConfigValue(constants.ConfigUpdatesDisabledKey, disableUpdate)
}
12 changes: 12 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,25 @@ func createApp(cmd *cobra.Command, _ []string) error {
return nil
}

func UpdateCheckDisabled(app *application.Avalanche) bool {
// returns true obly if explicitly disabled in the config
if app.Conf.ConfigFileExists() {
return app.Conf.GetConfigBoolValue(constants.ConfigUpdatesDisabledKey)
}
return false
}

// checkForUpdates evaluates first if the user is maybe wanting to skip the update check
// if there's no skip, it runs the update check
func checkForUpdates(cmd *cobra.Command, app *application.Avalanche) error {
var (
lastActs *application.LastActions
err error
)
// check if update check is skipped
if UpdateCheckDisabled(app) {
return nil
}
// we store a timestamp of the last skip check in a file
lastActs, err = app.ReadLastActionsFile()
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ const (
ConfigAPMAdminAPIEndpointKey = "admin-api-endpoint"
ConfigNodeConfigKey = "node-config"
ConfigMetricsEnabledKey = "MetricsEnabled"
ConfigUpdatesDisabledKey = "UpdatesDisabled"
ConfigAuthorizeCloudAccessKey = "AuthorizeCloudAccess"
ConfigSnapshotsAutoSaveKey = "SnapshotsAutoSaveEnabled"
OldConfigFileName = ".avalanche-cli.json"
Expand Down
Loading