@@ -46,7 +46,7 @@ function Install-Buildkit {
4646
4747 [Parameter (ParameterSetName = ' Setup' )]
4848 [Parameter (HelpMessage = " Path to Windows CNI plugin. Defaults to `$ ENV:ProgramFiles\Containerd\cni" )]
49- [string ]$WinCNIPath = " $ENV: ProgramFiles \Containerd\cni" ,
49+ [string ]$WinCNIPath = " $ENV: ProgramFiles \Containerd\cni" ,
5050
5151 [Parameter (ParameterSetName = ' Install' )]
5252 [Parameter (ParameterSetName = ' Setup' )]
@@ -140,7 +140,7 @@ function Install-Buildkit {
140140 }
141141 }
142142 catch {
143- Write-Warning " Failed to registed and start Buildkitd service. $_ "
143+ Write-Warning " Failed to setup Buildkitd service. $_ "
144144 }
145145
146146 if ($showCommands ) {
@@ -213,10 +213,10 @@ function Register-BuildkitdService {
213213 )]
214214 param (
215215 [parameter (HelpMessage = " Windows CNI plugin path. Defaults to `$ ENV:ProgramFiles\Containerd\cni" )]
216- [String ]$WinCNIPath = " $ENV: ProgramFiles \Containerd\cni" ,
216+ [String ]$WinCNIPath = " $ENV: ProgramFiles \Containerd\cni" ,
217217
218218 [parameter (HelpMessage = " Buildkit path. Defaults to `$ ENV:ProgramFiles\Buildkit" )]
219- [String ]$BuildKitPath = " $ENV: ProgramFiles \Buildkit" ,
219+ [String ]$BuildKitPath = " $ENV: ProgramFiles \Buildkit" ,
220220
221221 [parameter (HelpMessage = " Specify to start Buildkitd service after registration is complete" )]
222222 [Switch ]$Start ,
@@ -285,7 +285,7 @@ function Register-BuildkitdService {
285285 Write-Debug " CNI conf path: $cniConfPath "
286286
287287 # Register buildkit service
288- $command = " $buildkitdExecutable --register-service --debug --containerd-worker=true --containerd-cni-config-path=`" $cniConfPath `" --containerd-cni-binary-dir=`" $cniBinDir `" --service-name buildkitd"
288+ $arguments = " --register-service --debug --containerd-worker=true --containerd-cni-config-path=`" $cniConfPath `" --containerd-cni-binary-dir=`" $cniBinDir `" --service-name buildkitd"
289289 if (Test-ConfFileEmpty - Path $cniConfPath ) {
290290
291291 $consent = $force
@@ -295,20 +295,16 @@ function Register-BuildkitdService {
295295
296296 if ($consent ) {
297297 Write-Warning " Containerd conf file not found at $cniConfPath . Buildkit service will be registered without Containerd cni configurations."
298- $command = " $buildkitdExecutable --register-service --debug --containerd-worker=true --service-name buildkitd"
298+ $arguments = " --register-service --debug --containerd-worker=true --service-name buildkitd"
299299 }
300300 else {
301301 Write-Error " Failed to register buildkit service. Containerd conf file not found at $cniConfPath .`n`t 1. Ensure that the required CNI plugins are installed or you can install them using 'Install-WinCNIPlugin'.`n`t 2. Create the file to resolve this issue .`n`t 3. Rerun this command 'Register-BuildkitdService'"
302302 Throw " Failed to register buildkit service. Containerd conf file not found at $cniConfPath ."
303303 }
304304 }
305305
306- # remove the executable extension from the command
307- $escapedPath = [regex ]::Escape($buildkitdExecutable )
308- $arguments = ($command -replace " $escapedPath " , " " ).Trim()
309-
310306 # Register the service
311- $output = Invoke-ExecutableCommand - Executable $buildkitdExecutable - Arguments $arguments
307+ $output = Invoke-ExecutableCommand - Executable " $buildkitdExecutable " - Arguments $arguments
312308 if ($output.ExitCode -ne 0 ) {
313309 Throw " Failed to register buildkitd service. $ ( $output.StandardError.ReadToEnd ()) "
314310 }
@@ -386,10 +382,10 @@ function Uninstall-Buildkit {
386382
387383 process {
388384 if ($PSCmdlet.ShouldProcess ($env: COMPUTERNAME , $WhatIfMessage )) {
389- if (Test-EmptyDirectory - Path " $path " ) {
390- Write-Output " $tool does not exist at '$Path ' or the directory is empty"
391- return
392- }
385+ # if (Test-EmptyDirectory -Path "$path") {
386+ # Write-Output "$tool does not exist at '$Path' or the directory is empty"
387+ # return
388+ # }
393389
394390 $consent = $force
395391 if (! $ENV: PESTER ) {
@@ -426,23 +422,20 @@ function Uninstall-BuildkitHelper {
426422 [Switch ] $Purge
427423 )
428424
429- if (Test-EmptyDirectory - Path " $Path " ) {
430- Write-Error " Buildkit does not exist at ' $Path ' or the directory is empty. "
431- return
432- }
433-
434- try {
435- if ( Test-ServiceRegistered - Service ' Buildkitd ' ) {
436- Stop-BuildkitdService
437- Unregister-Buildkitd - BuildkitPath " $Path "
425+ if (-not ( Test-EmptyDirectory - Path " $Path " ) ) {
426+ try {
427+ if ( Test-ServiceRegistered - Service ' Buildkitd ' ) {
428+ Stop-BuildkitdService
429+ Unregister-Buildkitd - BuildkitPath " $Path "
430+ }
431+ }
432+ catch {
433+ Throw " Could not stop or unregister buildkitd service. $_ "
438434 }
439- }
440- catch {
441- Throw " Could not stop or unregister buildkitd service. $_ "
442- }
443435
444- # Remove the folder where buildkit is installed and related folders
445- Remove-Item - Path " $Path " - Recurse - Force
436+ # Remove the folder where buildkit is installed and related folders
437+ Remove-Item - Path " $Path " - Recurse - Force
438+ }
446439
447440 if ($Purge ) {
448441 Write-Output " Purging Buildkit program data"
@@ -494,10 +487,10 @@ function Unregister-Buildkitd($buildkitPath) {
494487 }
495488
496489 # Unregister buildkit service
497- $buildkitdExecutable = " $buildkitPath \bin\ buildkitd.exe"
490+ $buildkitdExecutable = ( Get-ChildItem - Path " $buildkitPath " - Recurse - Filter " buildkitd.exe" ).FullName | Select-Object - First 1
498491
499- Write-Debug " Buildkitd path: $buildkitdExecutable "
500- $output = Invoke-ExecutableCommand - Executable $buildkitdExecutable - Arguments " --unregister-service"
492+ Write-Debug " Buildkitd path: ' $buildkitdExecutable ' "
493+ $output = Invoke-ExecutableCommand - Executable " $buildkitdExecutable " - Arguments " --unregister-service"
501494 if ($output.ExitCode -ne 0 ) {
502495 Throw " Could not unregister buildkitd service. $ ( $output.StandardError.ReadToEnd ()) "
503496 }
0 commit comments