fix(compose): forward published ports (#19) and accept -f before subcommand (#21)#22
Merged
Conversation
buildRunArguments never emitted -p/--publish; port forwarding relied on a user-space PortProxy started only when `container inspect` already reported an IP. Right after `container run -d` the guest IP is unassigned, so the proxy never started and the error was swallowed by `try?` — every published port returned ECONNREFUSED. Emit native `-p host:container/proto` (Apple's container CLI supports it) and drop the proxy start; portProxy.stop is kept on stop/remove to clean up any proxies left by older versions. PortMapping.parse now also accepts the ip:host:container and bare-container forms found in real compose files. This fixes `mocker compose up` and `mocker run -p`, which shared the path. Closes #19
`mocker compose -f a.yaml -f b.yaml pull` failed with "Unknown option '-f'": ComposeOptions is an @OptionGroup on each subcommand, so swift-argument-parser only accepts -f/-p after the subcommand token, while Docker places them before it. -f was also single-valued, so multiple compose files were unsupported. Add ComposeArgNormalizer to relocate pre-subcommand -f/--file/-p/--project-name after the subcommand (invoked from a custom MockerCLI.main before parsing), change file: String? to files: [String], and add ComposeFile.merge for ordered multi-file overlay (later files override earlier; environment/labels field-merge). Flags after the subcommand and single-file usage keep working unchanged. Closes #21
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes two independent, verified compose bugs. Plan was produced and adversarially reviewed via a multi-agent loop; both root causes confirmed against source.
#19 —
compose upnever forwards published ports (ECONNREFUSED)buildRunArgumentsnever emitted-p/--publish. Forwarding relied on a user-spacePortProxythat only started whencontainer inspectalready reported an IP — but right aftercontainer run -dthe guest IP is unassigned, so the proxy never started and the failure was swallowed bytry?. Every published port returnedECONNREFUSED.Fix: emit native
-p host:container/proto(Apple'scontainerCLI supports[host-ip:]host-port:container-port[/protocol], verified on 0.12.3) and stop relying on the proxy.portProxy.stopis retained on stop/remove to clean up proxies left by older versions.PortMapping.parsenow also acceptsip:host:containerand bare-containerforms. Also fixesmocker run -p, which shared the same path.#21 —
compose -f a.yaml -f b.yaml pull→ "Unknown option '-f'"ComposeOptionsis an@OptionGroupon each subcommand, so swift-argument-parser only accepts-f/-pafter the subcommand token, while Docker places them before it.-fwas also single-valued.Fix:
ComposeArgNormalizerrelocates pre-subcommand-f/--file/-p/--project-nameto after the subcommand (invoked from a customMockerCLI.mainbefore parsing);file: String?→files: [String]; newComposeFile.mergefor ordered multi-file overlay (later overrides earlier;environment/labelsfield-merge). Flags after the subcommand and single-file usage are unchanged.Verification
swift build+swift test: 99/99 pass (new unit tests for-pemission, port grammar, argv reordering, and multi-file merge).mocker compose -f base.yaml -f dev.yaml confignow works and correctly merges (overlay image wins, base ports preserved, env merged) — previously errored.container run -pis host-reachable; unit test confirms mocker now emits exactly that.Closes #19
Closes #21