Skip to content

fix(parsing): accept list-form environment (- KEY=value) alongside map form#83

Open
Cyb3rDudu wants to merge 2 commits intoMcrich23:mainfrom
Cyb3rDudu:fix/environment-list-form
Open

fix(parsing): accept list-form environment (- KEY=value) alongside map form#83
Cyb3rDudu wants to merge 2 commits intoMcrich23:mainfrom
Cyb3rDudu:fix/environment-list-form

Conversation

@Cyb3rDudu
Copy link
Copy Markdown
Contributor

@Cyb3rDudu Cyb3rDudu commented May 4, 2026

Compose files using the list form of environment: fail to parse. Reporter's case from #2:

services:
  registry:
    image: registry:2
    environment:
      - REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY=/data
      - REGISTRY_STORAGE_DELETE_ENABLED=true

The Compose spec allows both shapes for services.<svc>.environment:

environment:                      environment:
  KEY: value                        - KEY=value
  OTHER: value     equivalent       - OTHER=value
                                    - INHERIT_FROM_HOST

Service.swift decodes only the map form ([String: String]?), so the list form throws DecodingError.typeMismatch and the whole compose file fails to load. List form is the older docker-classic style still used by Docker Registry, Sentry, GitLab, and many other official examples — comment thread on #2 has multiple users hitting it.

Fix tries the map form first (no behavior change for existing users), falls back to a small parser:

  • KEY=value splits on first = (later = chars stay in the value, so DSN-style postgres://u:p@h/db?sslmode=require round-trips)
  • Bare KEY reads from ProcessInfo.processInfo.environment[KEY], falling back to empty string when unset (Compose's "inherit from host" shorthand)

Tests: 11 static cases covering both decode paths end-to-end (map form regression, list form, mixed forms across services, env key absent) plus targeted unit tests on the parseEnvironmentList helper (first-= split, DSN-style values, bare-key inheritance, duplicates, empty list).

Fixes #2. Fixes #65.

Cyb3rDudu added 2 commits May 4, 2026 12:38
…p form

Compose spec allows both shapes for `services.<svc>.environment`:

  environment:                      environment:
    KEY: value                        - KEY=value
    OTHER: value      equivalent      - OTHER=value
                                      - INHERIT_FROM_HOST

Current decode is typed strictly as `[String: String]?` and throws
`DecodingError.typeMismatch` on the list form, failing the whole compose
file. List form is the older docker-classic style still used by Docker
Registry, Sentry, GitLab and many official examples.

Tries the map form first (no behavior change for existing users), falls
back to a small parser:
  - `KEY=value` splits on first `=` (later `=` chars stay in the value)
  - bare `KEY` reads from `ProcessInfo.processInfo.environment[KEY]`,
    falling back to empty string when unset

Fixes Mcrich23#2.
… helper

11 cases:
- Map form decodes (regression — already-working path)
- List form decodes (the issue Mcrich23#2 case)
- Mixed forms across services in the same file
- environment key absent decodes as nil
- Helper: KEY=value splits at first =
- Helper: only the first = splits, rest stays in value (DSN/URL values)
- Helper: empty value after = decodes as empty string
- Helper: bare key inherits from process env when set
- Helper: bare key with no host env value decodes as empty string
- Helper: empty list returns empty dict
- Helper: duplicate keys — last wins
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

container-compose does not like Docker Compose-style environment config Add Environment Support

1 participant