Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Sources/Container-Compose/Codable Structs/Service.swift
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,14 @@ public struct Service: Codable, Hashable {

if let dependsOnString = try? container.decodeIfPresent(String.self, forKey: .depends_on) {
depends_on = [dependsOnString]
} else if let dependsOnArray = try? container.decodeIfPresent([String].self, forKey: .depends_on) {
depends_on = dependsOnArray
} else if let dependsOnMap = try? container.decodeIfPresent([String: [String: String]].self, forKey: .depends_on) {
// Map form: depends_on: { db: { condition: service_healthy } }
// Preserve dependency order; conditions are not applicable to Apple Container.
depends_on = dependsOnMap.keys.sorted()
} else {
depends_on = try container.decodeIfPresent([String].self, forKey: .depends_on)
depends_on = nil
}
user = try container.decodeIfPresent(String.self, forKey: .user)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,32 @@ struct DockerComposeParsingTests {
#expect(compose.services["web"]??.depends_on?.contains("db") == true)
}

@Test("Parse compose with depends_on map form (condition syntax)")
func parseComposeWithDependenciesMapForm() throws {
let yaml = """
version: '3.8'
services:
web:
image: nginx:latest
depends_on:
db:
condition: service_healthy
cache:
condition: service_started
db:
image: postgres:14
cache:
image: redis:7
"""

let decoder = YAMLDecoder()
let compose = try decoder.decode(DockerCompose.self, from: yaml)

#expect(compose.services["web"]??.depends_on?.contains("db") == true)
#expect(compose.services["web"]??.depends_on?.contains("cache") == true)
#expect(compose.services["web"]??.depends_on?.count == 2)
}

@Test("Parse compose with build context")
func parseComposeWithBuild() throws {
let yaml = """
Expand Down