Repository navigation
feat: support build.args list form and add build --build-arg flag - #143
OrtegaMatias wants to merge 1 commit into
Conversation
`build.args` in list form (`- KEY=VALUE`) previously threw `DecodingError.typeMismatch` and crashed `up` (Mcrich23#136). It now decodes both the map and list forms, reusing the same shared list parser as `environment:`. Adds a repeatable `--build-arg KEY=VALUE` flag to the `build` subcommand (Mcrich23#69), matching `docker compose build`: CLI values override compose-file args on key conflict, and a bare `KEY` inherits its value from the environment. Closes Mcrich23#136 Closes Mcrich23#69
|
I like this, especially since it addresses both #69 and #136. Can you make invalid argument formats throw instead of silently dropping them? Please also check bare arguments with no environment value so we don't accidentally replace a Dockerfile default with an empty string. A test confirming the arguments reach the builder would be helpful. The shared helper can stay internal. |
Mcrich23
left a comment
There was a problem hiding this comment.
Love the PR, but I’m unsure all of the ways you are handling things are correct. Please take a look at the comments I left.
| public func parseComposeKeyValueList(_ entries: [String]) -> [String: String] { | ||
| var dict: [String: String] = [:] | ||
| for entry in entries { | ||
| if let eqIdx = entry.firstIndex(of: "=") { |
There was a problem hiding this comment.
I love the idea of abstracting this out to a helper function, but this way of parsing is unnecessary because swift has split with a limiter. Can you please take a look at how I’m doing it other places and make this helper the same as that parsing? Then we can easily also move those to this at some point.
| let value = String(entry[entry.index(after: eqIdx)...]) | ||
| dict[key] = value | ||
| } else { | ||
| dict[entry] = ProcessInfo.processInfo.environment[entry] ?? "" |
There was a problem hiding this comment.
This part only makes sense for environment variable parsing and not general parsing. Please move it back to that function in some way?
|
Closing this in favor of #194, which carries build argument lists and CLI overrides forward with validation and builder coverage. The earlier review requests remain outstanding here. #194 is still open, so this is a replacement PR, not a claim that the feature has merged. Thanks for the original work. |
Summary
Completes
build.argssupport end-to-end:build.argsin list form (- KEY=VALUE) threwDecodingError.typeMismatch: expected Mapping ... found Nodeand crashed the entireup.Buildnow decodes both the map form and the list form.--build-arg KEY=VALUEflag to thebuildsubcommand, matchingdocker compose build.Details
#136 — list-form
build.argsBuild.argsonly decoded[String: String](map form), so this valid Compose file crashed at decode time:Buildnow accepts map or list, reusing the exact same list-parsing semanticsenvironment:already uses. To avoid duplicating that logic, the body ofService.parseEnvironmentListis lifted into a sharedparseComposeKeyValueList(_:)helper that bothenvironment:andbuild.args:call — split on the first=(so values keep internal=), and a bareKEYinherits from the environment.#69 —
build --build-argPreviously failed with
Unknown option '--build-arg'. Now, per Docker parity:args:values are interpolated against the environment (unchanged),--build-argvalues are passed through as-is and win on key conflicts,--build-arg KEYinherits its value from the environment.The merge is a small pure function
mergedBuildArgs(fileArgs:cliArgs:), unit-tested independently of the daemon.Testing (TDD)
Written test-first. Full static suite is green locally:
New static tests:
build.argsdecode + the exact DecodingError.typeMismatch in build args #136 repro at theDockerComposelevel=(DSN) round-trips--build-argflag parsing (repeated + default-empty)No changes to the dynamic (daemon) tests.
Scope
--build-argis added only to thebuildsubcommand (parity with Docker).environment:behavior is unchanged (its existing list-form tests still pass after the shared-helper extraction).