Skip to content
Draft
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
26 changes: 15 additions & 11 deletions containers-toolkit/Public/NerdctlTools.psm1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
###########################################################################
###########################################################################
# #
# Copyright (c) Microsoft Corporation. All rights reserved. #
# #
Expand All @@ -7,6 +7,7 @@
###########################################################################

using module "..\Private\CommonToolUtilities.psm1"
using module "..\Private\logger.psm1"

$ModuleParentPath = Split-Path -Parent $PSScriptRoot
Import-Module -Name "$ModuleParentPath\Private\CommonToolUtilities.psm1" -Force
Expand Down Expand Up @@ -41,14 +42,18 @@ function Install-NerdctlDependencies {
[string]$OsArch,
[Switch]$Force
)
if (!$Dependencies) {
return
}

[Logger]::Info("Installing nerdctl dependencies: $toinstall")
foreach ($dependency in $Dependencies) {
$InstallCommand = "Install-$dependency"
try {
& $InstallCommand -OSArchitecture $OsArch -Force:$Force -Confirm:$false
}
catch {
Write-Error "Installation failed for $dependency. $_"
[Logger]::Error("Installation failed for $dependency. $_")
}
}
}
Expand Down Expand Up @@ -109,7 +114,7 @@ function Install-Nerdctl {
# Check if nerdctl already exists at specified location
if ($isInstalled) {
$errMsg = "nerdctl already exists at $InstallPath or the directory is not empty"
Write-Warning $errMsg
[Logger]::Warning($errMsg)

# Uninstall if tool exists at specified location. Requires user consent
try {
Expand All @@ -126,7 +131,7 @@ function Install-Nerdctl {
}
$Version = $Version.TrimStart('v')

Write-Output "Downloading and installing nerdctl v$Version at $InstallPath"
[Logger]::Info("Downloading and installing nerdctl v$Version at $InstallPath")

# Download files
$downloadParams = @{
Expand Down Expand Up @@ -159,11 +164,10 @@ function Install-Nerdctl {
}
Install-RequiredFeature @params

Write-Output "nerdctl v$version successfully installed at $InstallPath"
Write-Output "For nerdctl usage: run 'nerdctl -h'`n"
[Logger]::Info("nerdctl v$version successfully installed at $InstallPath")
[Logger]::Info("For nerdctl usage: run 'nerdctl -h'`n")

# Install dependencies
Write-Output "Installing nerdctl dependencies: $toinstall"
Install-NerdctlDependencies -Dependencies $dependencies -OsArch $OSArchitecture -Force:$true
}
else {
Expand Down Expand Up @@ -215,7 +219,7 @@ function Uninstall-Nerdctl {
process {
if ($PSCmdlet.ShouldProcess($env:COMPUTERNAME, $WhatIfMessage)) {
if (Test-EmptyDirectory -Path $path) {
Write-Output "$tool does not exist at $Path or the directory is empty"
[Logger]::Info("$tool does not exist at $Path or the directory is empty")
return
}

Expand All @@ -228,7 +232,7 @@ function Uninstall-Nerdctl {
Throw "$tool uninstallation cancelled."
}

Write-Warning "Uninstalling preinstalled $tool at the path $path"
[Logger]::Warning("Uninstalling preinstalled $tool at the path $path")
try {
Uninstall-NerdctlHelper -Path $path
}
Expand All @@ -252,7 +256,7 @@ function Uninstall-NerdctlHelper {
)

if (Test-EmptyDirectory -Path $Path) {
Write-Error "nerdctl does not exist at $Path or the directory is empty."
[Logger]::Error("nerdctl does not exist at $Path or the directory is empty.")
return
}

Expand All @@ -265,7 +269,7 @@ function Uninstall-NerdctlHelper {
# Remove from env path
Remove-FeatureFromPath -Feature "nerdctl"

Write-Output "Successfully uninstalled nerdctl."
[Logger]::Info("Successfully uninstalled nerdctl.")
}

Export-ModuleMember -Function Get-NerdctlLatestVersion
Expand Down