fix(publish): support short-form port mapping with variable interpolation - #14198
Open
Hoomanghkhani wants to merge 1 commit into
Open
fix(publish): support short-form port mapping with variable interpolation#14198Hoomanghkhani wants to merge 1 commit into
Hoomanghkhani wants to merge 1 commit into
Conversation
…tion
When publishing a Compose project with short-form port syntax containing
environment variable substitutions (e.g. `${PORT:-3000}:3000`), `publish`
previously failed with:
'services[...].ports[0]' expected a map or struct, got "string"
During `preChecks`, `loadUnresolvedFile` loads each file with
`SkipInterpolation = true` to detect raw un-interpolated literals and
secrets. Because variable interpolation is skipped, `types.ParsePortConfig`
cannot parse the non-numeric port strings into `ServicePortConfig`
definitions, leaving them as raw string slices in the canonical dictionary.
When `loader.Transform` attempts to decode this into `types.Project`,
mapstructure fails because `types.ServiceConfig.Ports` expects a slice of
structs, not strings.
Neither `collectEnvCheckFindings` nor `checkForSensitiveData` inspects
service ports (only environment, env_files, extends, and configs are
checked). Load the raw model via `loader.LoadModelWithContext` and strip
`ports` from services before calling `loader.Transform`. Additionally,
have `composeFileAsByteReader` read the raw compose file directly from
disk so all file content is preserved for secret scanning without
unnecessary decoding.
Fixes docker#13672
Signed-off-by: Hooman <hooman.ghkhani@gmail.com>
Hoomanghkhani
force-pushed
the
fix-publish-short-form-ports
branch
from
September 8, 2026 14:04
a85b23a to
f99ca7e
Compare
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.
What I did
Fixed an issue where
docker compose publishfailed with:'services[...].ports[0]' expected a map or struct, got "string"when a service defined short-form port syntax containing variable substitutions (e.g.
${PORT:-3000}:3000).During
preChecks,loadUnresolvedFileruns withoptions.SkipInterpolation = trueto detect uncommitted secrets and suspicious literals. Because interpolation is skipped,types.ParsePortConfigcannot parse un-interpolated port expressions into numeric ports, leaving them as raw string slices. Mapstructure subsequently failed attempting to decode strings intotypes.ServicePortConfigstructs.To fix this:
loadUnresolvedFilenow loads the model vialoader.LoadModelWithContextand deletesportsfrom services before callingloader.Transform. NeithercollectEnvCheckFindingsnorcheckForSensitiveDatainspects ports (only environment, env_files, extends, and configs are checked).composeFileAsByteReadernow reads the compose file directly from disk viaos.ReadFile, guaranteeing the secret scanner examines the exact file bytes to be published without loss of comments or unnecessary decoding.publish_test.goverifyingloadUnresolvedFile,checkForSensitiveData, andcollectEnvCheckFindingswith short-form port syntax containing variable substitutions.Related issue
Fixes #13672