Skip to content

[BUG] Fails to parse default value syntax (e.g., ${VAR:-default}) in .env File, resulting in invalid configmap #2010

@yuefanxiao

Description

@yuefanxiao

Expected Behavior

When using the env_file attribute in docker-compose.yml to load environment variables:

  1. Default value syntax (e.g., ${VAR:-default}) in the .env file should be parsed and resolved correctly.
  • Example: DOC_ENGINE=${DOC_ENGINE:-elasticsearch} should resolve to DOC_ENGINE=elasticsearch if the variable is unset.
  1. The generated ConfigMap (from the .env file) should contain resolved values, not raw expressions.
  2. References between variables in .env (e.g., COMPOSE_PROFILES=${DOC_ENGINE}) should inherit the resolved value.

Actual Behavior

Kompose does not parse default value syntax in .env files. Instead:

  1. The generated ConfigMap contains malformed values (e.g., :-elasticsearch}), indicating a failure to resolve ${VAR:-default}.
    Example:
apiVersion: v1
data:
  DOC_ENGINE: :-elasticsearch}  # Invalid syntax
  COMPOSE_PROFILES: :-elasticsearch}
kind: ConfigMap
metadata:
  labels:
    io.kompose.service: minio-env
  name: env
  1. Variables referencing unresolved values (e.g., COMPOSE_PROFILES=${DOC_ENGINE}) inherit the malformed syntax, breaking dependent configurations.

Steps To Reproduce

  1. Create docker-compose.yml:
version: '3'
services:
  minio:
    image: quay.io/minio/minio:latest
    env_file: .env  # Load variables from .env
    ports:
      - 9000:9000
 
  1. Create .env file with:
DOC_ENGINE=${DOC_ENGINE:-elasticsearch}
COMPOSE_PROFILES=${DOC_ENGINE}  # Reference the variable with default
  1. Run:
    kompose -f docker-compose.yml convert -c

Kompose Version

1.35.0

Docker-Compose file

version: '3'
services:
  minio:
    image: quay.io/minio/minio:latest
    env_file: .env  # Load variables from .env
    ports:
      - 9000:9000

Anything else?

No response

Metadata

Metadata

Assignees

Labels

kind/bugCategorizes issue or PR as related to a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions