Commit c5d75a3
fix(apko-as-apk): avoid re-resolving already-installed packages when adding new packages
This fixes a bug where apko-as-apk add would fail when the system had
packages installed from repositories that are no longer accessible.
Problem:
When running `apko-as-apk add <package>` in a container with packages
from private or unavailable repositories (e.g., chainguard-baselayout
from cgr.dev/chainguard-private), the command would fail with:
"failed to resolve world: nothing provides <unavailable-package>"
This occurred because the add command would:
1. Read all packages from /etc/apk/world (including already-installed ones)
2. Add the new package to world
3. Call ResolveWorld() which tried to re-resolve ALL packages
4. Fail when it couldn't find already-installed packages in current repos
Example failure:
docker run cgr.dev/chainguard-private/chainguard-base:latest \
apko-as-apk add grep
# Error: nothing provides "chainguard-baselayout"
Solution:
Modified internal/cli/apkcompat/add.go to:
1. Get the list of already-installed packages before resolving
2. Filter the world file to only include packages NOT already installed
3. Only resolve and install packages that are actually new
4. Call InstallPackages() directly instead of FixateWorld() to avoid
re-resolving the entire world
This matches the behavior of the real `apk` command, which doesn't
attempt to re-resolve packages that are already installed.
Testing:
- Added comprehensive unit tests in add_test.go
- Verified fix works with both chainguard-base and wolfi-base containers
- All existing tests pass
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>1 parent 1b08539 commit c5d75a3
2 files changed
Lines changed: 365 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
160 | 160 | | |
161 | 161 | | |
162 | 162 | | |
163 | | - | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
164 | 177 | | |
165 | 178 | | |
166 | 179 | | |
167 | 180 | | |
168 | 181 | | |
169 | 182 | | |
170 | | - | |
171 | | - | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
172 | 216 | | |
173 | 217 | | |
174 | 218 | | |
| |||
177 | 221 | | |
178 | 222 | | |
179 | 223 | | |
180 | | - | |
| 224 | + | |
181 | 225 | | |
182 | 226 | | |
183 | 227 | | |
184 | 228 | | |
185 | | - | |
186 | | - | |
187 | | - | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
188 | 252 | | |
189 | 253 | | |
190 | 254 | | |
191 | | - | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
192 | 275 | | |
193 | 276 | | |
194 | | - | |
| 277 | + | |
195 | 278 | | |
196 | 279 | | |
197 | 280 | | |
| |||
0 commit comments