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

Stop execution if tool version already installed #49

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

TinaMor
Copy link
Contributor

@TinaMor TinaMor commented Feb 3, 2025

PR description

Background information

When the version of a tool is already installed, the Install-Command uninstalls then reinstalls the tool. To fix this, if the tool version is already installed, the script will stop execution and show the user a warning. If a user must reinstall it, they can pass -Force flag when running the command.

Github issue

#20

Testing information

Check installed buildkit version

> Show-ContainerTools -Latest | Where-Object {$_.Tool -eq 'buildkit'} | Format-List

For unregistered services/daemons, check the tool's help or register the service using
        Register-BuildkitdService, Register-ContainerdService, Start-BuildkitdService, Start-ContainerdService, Stop-BuildkitdService, Stop-ContainerdService

Tool          : buildkit
Installed     : True
Version       : v0.19.0
Daemon        : buildkitd
DaemonStatus  : Stopped
LatestVersion : v0.19.0

Try to install an already installed version

Should show user a warning and stop installation

> Install-Buildkit -Version v0.19.0

Confirm
Are you sure you want to perform this action?
Performing the operation "Buildkit will be uninstalled from and reinstalled at C:\Program Files\Buildkit" on target "COMPUTERNAME".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): Y
WARNING: Buildkit already exists at C:\Program Files\Buildkit or the directory is not empty
WARNING: Installed Buildkit version is the same as the requested version. Please uninstall the existing version using 'Uninstall-Containerd' or use -Force to reinstall.

Force install an already installed version

Should show use a warning, proceed to uninstall the installed version, then re-install the version

> Install-Buildkit -Version v0.19.0 -Force

Confirm
Are you sure you want to perform this action?
Performing the operation "Buildkit will be uninstalled from and reinstalled at C:\Program Files\Buildkit" on target "COMPUTERNAME".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): Y
WARNING: Buildkit already exists at C:\Program Files\Buildkit or the directory is not empty
WARNING: Installed Buildkit version is the same as the requested version. Please uninstall the existing version using 'Uninstall-Containerd' or use -Force to reinstall.
WARNING: Uninstalling preinstalled Buildkit at the path C:\Program Files\Buildkit
Downloading and installing Buildkit v0.19.0 at C:\Program Files\Buildkit
Extracting Buildkit to C:\Program Files\Buildkit
Cleanup to remove downloaded files
Successfully installed Buildkit v0.19.0 at C:\Program Files\Buildkit

Other useful Buildkit commands: Get-BuildkitLatestVersion, Register-BuildkitdService, Start-BuildkitdService, Stop-BuildkitdService, Uninstall-Buildkit.
To learn more about each command, run Get-Help <command-name>, e.g., 'Get-Help "*buildkit*"' or 'Get-Help Register-BuildkitdService'

For buildctl usage: run "buildctl.exe -h"

Checklist

As part of our commitment to engineering excellence, before submitting this PR, please make sure:

  • You've tested this code in both Desktop & Server environments and AMD & ARM64 enviroments (functional testing).
  • You've added unit tests for new code.
  • You've added/updated documentation in the cmdlet docs, command-reference.md and the modules help files.
  • You've reviewed the PR/code best practices defined in the CONTRIBUTING.md.

In addition, after this PR has been reviewed, please agree to:

  • If changes have been made to your PR in the process of addressing comments, please make sure to test again the final version in both AMD and ARM64 environments.
  • Validate your changes have not introduced any regressions.

@TinaMor TinaMor force-pushed the tinamor/fix-reinstall branch 3 times, most recently from feb2285 to ec09670 Compare February 3, 2025 17:45
@TinaMor TinaMor force-pushed the tinamor/fix-reinstall branch from ec09670 to 38108f6 Compare February 5, 2025 10:30
@TinaMor TinaMor marked this pull request as ready for review February 5, 2025 10:45
billywr
billywr previously approved these changes Feb 5, 2025
$blktVersion = ($blktVersion.Split(' ')[2]).TrimStart('v')
Write-Debug "{ User Version: $userVersion, Current Version: $blktVersion }"
if ($userVersion -eq $blktVersion) {
Write-Warning "Installed Buildkit version is the same as the requested version. Please uninstall the existing version using 'Uninstall-Containerd' or use -Force to reinstall."

Choose a reason for hiding this comment

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

Messaging is inconsistent, Uninstall-Containerd in buildkit warning

# Check if tool already exists at specified location
if ($isInstalled) {
$errMsg = "Containerd already exists at $InstallPath or the directory is not empty"
Write-Warning $errMsg

# Check if user wants to install an already installed version
Write-Debug "Containerd executable: $ctrexe"
$cmdOutput = Invoke-ExecutableCommand -Executable "$ctrexe" -Arguments "--version"
Copy link

@iankingori iankingori Feb 5, 2025

Choose a reason for hiding this comment

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

containerd, nerdctl and buildkit version checks look similar, perhaps break this logic out into utilities

@TinaMor TinaMor assigned TinaMor and unassigned TinaMor Feb 5, 2025
@TinaMor TinaMor marked this pull request as draft February 5, 2025 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants