|
16 | 16 | exit |
17 | 17 | } |
18 | 18 |
|
19 | | -# Perform Docker cleanup to prevent accumulation of old containers and images |
20 | | -Write-Host "`nCleaning up old containers and images..." |
21 | | -try { |
22 | | - # Stop and remove only containers related to this specific image |
23 | | - $containers = docker ps -a --filter "ancestor=ghcr.io/jonathanalgar/customcode-analyzer-generator" --format "{{.ID}}" |
24 | | - if ($containers) { |
25 | | - Write-Host "Removing old containers from customcode-analyzer-generator..." |
26 | | - docker rm -f $containers |
27 | | - } else { |
28 | | - Write-Host "No old containers from customcode-analyzer-generator found." |
29 | | - } |
30 | | - |
31 | | - # Remove only dangling images related to this specific repository |
32 | | - # This is much safer than a broad prune |
33 | | - $danglingImages = docker images --filter "dangling=true" --filter "reference=ghcr.io/jonathanalgar/customcode-analyzer-generator*" --format "{{.ID}}" |
34 | | - if ($danglingImages) { |
35 | | - Write-Host "Removing dangling images from customcode-analyzer-generator..." |
36 | | - docker rmi $danglingImages |
37 | | - } else { |
38 | | - Write-Host "No dangling images from customcode-analyzer-generator found." |
39 | | - } |
40 | | - |
41 | | - # Remove old versions of the image (keep the latest) |
42 | | - $images = docker images "ghcr.io/jonathanalgar/customcode-analyzer-generator" --format "{{.ID}}" | Select-Object -Skip 1 |
43 | | - if ($images) { |
44 | | - Write-Host "Removing old image versions of customcode-analyzer-generator..." |
45 | | - docker rmi $images |
46 | | - } else { |
47 | | - Write-Host "No old image versions of customcode-analyzer-generator found." |
48 | | - } |
49 | | - |
50 | | - Write-Host "Cleanup completed successfully" -ForegroundColor Green |
51 | | -} catch { |
52 | | - Write-Host "Warning: Cleanup encountered an issue. Continuing with installation..." -ForegroundColor Yellow |
53 | | - Write-Host $_.Exception.Message |
54 | | -} |
55 | | - |
56 | 19 | # Get the current username |
57 | 20 | $username = $env:USERNAME |
58 | 21 |
|
@@ -111,6 +74,42 @@ try { |
111 | 74 | exit |
112 | 75 | } |
113 | 76 |
|
| 77 | +# Perform Docker cleanup to prevent accumulation of old containers and images |
| 78 | +Write-Host "`nCleaning up old containers and images..." |
| 79 | +try { |
| 80 | + # Stop and remove only containers related to this specific image |
| 81 | + $containers = docker ps -a --filter "ancestor=ghcr.io/jonathanalgar/customcode-analyzer-generator" --format "{{.ID}}" |
| 82 | + if ($containers) { |
| 83 | + Write-Host "Removing old containers from customcode-analyzer-generator..." |
| 84 | + docker rm -f $containers |
| 85 | + } else { |
| 86 | + Write-Host "No old containers from customcode-analyzer-generator found." |
| 87 | + } |
| 88 | + |
| 89 | + # Remove only dangling images related to this specific repository |
| 90 | + $danglingImages = docker images --filter "dangling=true" --filter "reference=ghcr.io/jonathanalgar/customcode-analyzer-generator*" --format "{{.ID}}" |
| 91 | + if ($danglingImages) { |
| 92 | + Write-Host "Removing dangling images from customcode-analyzer-generator..." |
| 93 | + docker rmi $danglingImages |
| 94 | + } else { |
| 95 | + Write-Host "No dangling images from customcode-analyzer-generator found." |
| 96 | + } |
| 97 | + |
| 98 | + # Remove old versions of the image (keep the latest) |
| 99 | + $images = docker images "ghcr.io/jonathanalgar/customcode-analyzer-generator" --format "{{.ID}}" | Select-Object -Skip 1 |
| 100 | + if ($images) { |
| 101 | + Write-Host "Removing old image versions of customcode-analyzer-generator..." |
| 102 | + docker rmi $images |
| 103 | + } else { |
| 104 | + Write-Host "No old image versions of customcode-analyzer-generator found." |
| 105 | + } |
| 106 | + |
| 107 | + Write-Host "Cleanup completed successfully" -ForegroundColor Green |
| 108 | +} catch { |
| 109 | + Write-Host "Warning: Cleanup encountered an issue. Continuing..." -ForegroundColor Yellow |
| 110 | + Write-Host $_.Exception.Message |
| 111 | +} |
| 112 | +
|
114 | 113 | $scriptPath = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition |
115 | 114 | Set-Location -Path $scriptPath |
116 | 115 |
|
|
0 commit comments