fix: tolerate env-var placeholders and quoted scalars in deploy.replicas decoding#129
Open
mvanhorn wants to merge 1 commit into
Open
Conversation
…cas decoding Fixes Mcrich23#95
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.
Summary
Give
Deploya custominit(from:)following the lenient-decoding precedent already established inService.init(from:)(Service.swift, which uses try-Int/try-String fallbacks formem_limit,command,entrypoint, etc.). Add an explicitCodingKeysenum formode,replicas,resources,restart_policy. Decodereplicasby first attemptingInt; on failure, decode theStringscalar, trim whitespace and surrounding quotes, and parse it withInt(_:)so quoted numerics like"2"still yield an integer.Why this matters
Running
container-compose up --env-file .env -f compose.ymlfails withDecodingError.typeMismatch: expected value of type Int ... Expected to decode Int but found Scalar insteadwhen a compose file uses an environment variable fordeploy.replicas(e.g.replicas: ${CORES}withCORES=1in.env). The root cause is decode ordering:ComposeUpdecodes the YAML intoDockerCompose(ComposeUp.swift line 164) before the env file is even loaded (line 167), and env-var interpolation happens per-field viaresolveVariableafter decoding.See #95.
Testing
deploy: {mode: replicated, replicas: 3}still decodes withreplicas == 3(no regression on plain Int scalars). - Quoted numeric:replicas: "2"decodes withreplicas == 2instead of throwing typeMismatch. - Exact issue repro: the snippet from issue Got error "Expected to decode Int but found Scalar instead." if i use an env var in an assignment to "replicas" #95 (mode: replicated,replicas: ${CORES}) decodes successfully;replicasis nil andreplicasExpression == "${CORES}", and sibling fields (mode,resources) are unaffected. - Error path: a structurally invalidreplicasvalue that is neither Int nor String scalar (e.g.Fixes #95