fix(service): support Compose 2.x dict form for env_file entries#124
Merged
Conversation
The Compose spec allows env_file to be a string, a list of strings, or
a list of {path:, required:} objects. container-compose only handled the
string and [string] forms; the dict form (used by Docker Compose v2
projects) caused a decoding failure.
This change adds a nested Decodable helper (EnvFileEntry) that accepts
both string and dict forms and normalises them to [String] so the rest
of the codebase is unchanged.
Tests cover: plain string, array of strings (regression), single dict
entry, dict with required:, dict without required:, multiple dict entries,
and a mixed array. Test helper updated to use flatMap({ $0 }) when
unwrapping from services[String: Service?].
Cyb3rDudu
approved these changes
Jul 1, 2026
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.
Problem
The Compose spec allows
env_fileto be written in three forms:container-composecurrently only handles forms 1 and 2. Form 3, generated by Docker Compose v2 projects (and required whenrequired: falseis needed), causes a decoding failure.Solution
Add a nested
EnvFileEntryDecodablethat accepts both string and dict forms via Swift'ssingleValueContainer/ keyed-container fallback pattern, then normalise everything to[String]so the rest of the codebase is unchanged.Changes
Sources/Container-Compose/Codable Structs/Service.swift— replace the two-branchenv_filedecoder with a three-way decode viaEnvFileEntryTests/Container-Compose-StaticTests/EnvFileDictFormTests.swift— 7 new tests covering all three forms and a mixed array; regression test for the existing string/array formsTests
All 7 tests pass; existing tests unaffected.