Commit 7dd3bfe
Fix: resolve the container CLI matching the cross-compile method (lambda-build & archive) (#678)
### Problem
Cross-compiling with Apple's `container` CLI did not work — neither via
the new `lambda-build` plugin nor the legacy `archive` plugin. The build
failed with:
```
/usr/local/bin/docker image pull swift:amazonlinux2023
failed to connect to the docker API at unix:///Users/.../docker.sock ...
```
Both plugins **always** resolved the Docker binary (`context.tool(named:
"docker")`) and forwarded it as the container CLI path, regardless of
the selected cross-compilation method. So when `container` was
requested, the plugin generated correct `container`-style arguments
(`image pull …`) but executed them with the **docker** binary, which
then failed.
Tool resolution has to happen in the plugin (the SwiftPM sandbox can
only run tools it resolves up front), so the fix belongs there rather
than in the helper.
### Fix
Both plugins now peek the cross-compilation flag and resolve the
matching tool — `container` when `container` is requested, `docker`
otherwise — before invoking the helper. The original arguments are still
forwarded unchanged.
- **`AWSLambdaBuilder`** (`lambda-build`): honours `--cross-compile`
(and the deprecated `--container-cli` alias).
- **`AWSLambdaPackager`** (`archive`, Swift 6.4 deprecation
passthrough): same bug, same fix; honours both `--cross-compile` and the
legacy `--container-cli`.
### Testing
Verified end-to-end against a sample project for both commands:
- **Default (no flag):** resolves `/usr/local/bin/docker` — unchanged
behaviour.
- **`--cross-compile container` / `--container-cli container`:**
resolves `/usr/local/bin/container`; the plugin now runs
`/usr/local/bin/container image pull …` and the Linux container starts
and builds.
> [!NOTE]
> There is a separate, pre-existing limitation: Apple's `container` CLI
communicates with its daemon over XPC, which the SwiftPM plugin sandbox
blocks (`XPC connection error: Connection invalid`). The same command
succeeds with `--disable-sandbox`. That sandbox issue is out of scope
for this PR (which fixes the tool-resolution bug) and should be tracked
separately.
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>1 parent 4a02a3e commit 7dd3bfe
3 files changed
Lines changed: 44 additions & 7 deletions
File tree
- Plugins
- AWSLambdaBuilder
- AWSLambdaPackager
- Sources/AWSLambdaPluginHelper/lambda-build
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
32 | 31 | | |
33 | 32 | | |
34 | 33 | | |
| |||
39 | 38 | | |
40 | 39 | | |
41 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
42 | 53 | | |
43 | 54 | | |
44 | 55 | | |
| |||
87 | 98 | | |
88 | 99 | | |
89 | 100 | | |
90 | | - | |
| 101 | + | |
91 | 102 | | |
92 | 103 | | |
93 | 104 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
43 | 42 | | |
44 | 43 | | |
45 | 44 | | |
| |||
49 | 48 | | |
50 | 49 | | |
51 | 50 | | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
52 | 62 | | |
53 | 63 | | |
54 | 64 | | |
| |||
100 | 110 | | |
101 | 111 | | |
102 | 112 | | |
103 | | - | |
| 113 | + | |
104 | 114 | | |
105 | 115 | | |
106 | 116 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
450 | 450 | | |
451 | 451 | | |
452 | 452 | | |
453 | | - | |
454 | | - | |
| 453 | + | |
455 | 454 | | |
456 | 455 | | |
457 | 456 | | |
458 | 457 | | |
459 | 458 | | |
460 | 459 | | |
461 | | - | |
| 460 | + | |
462 | 461 | | |
463 | 462 | | |
464 | 463 | | |
465 | 464 | | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
466 | 482 | | |
467 | 483 | | |
468 | 484 | | |
| |||
0 commit comments