Skip to content

[FR] Try to parse strings as integers when requiring an integer #791

Open
@pindab0ter

Description

@pindab0ter

Is your feature request related to a problem? Please describe.
In an attempt to set up different values for different environments (e.g. staging and production) I'm passing the values as environment variables and using them like so:

services:
  projectname:
    container_name: app
    image: ${IMAGE_ID}
    deploy:
      replicas: ${ECS_REPLICAS}

However, this results in the following error:

Traceback (most recent call last):
  File "/home/runner/work/projectname/venv/bin/ecs-compose-x", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/runner/work/projectname/venv/lib/python3.12/site-packages/ecs_composex/cli.py", line 194, in main
    settings = ComposeXSettings(**vars(args))
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/projectname/venv/lib/python3.12/site-packages/ecs_composex/common/settings.py", line 177, in __init__
    self.set_content(kwargs, content)
  File "/home/runner/work/projectname/venv/lib/python3.12/site-packages/ecs_composex/common/settings.py", line 525, in set_content
    content_def = ComposeDefinition(files, content)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/projectname/venv/lib/python3.12/site-packages/compose_x_render/compose_x_render.py", line 324, in __init__
    jsonschema.validate(
  File "/home/runner/work/projectname/venv/lib/python3.12/site-packages/jsonschema/validators.py", line 1332, in validate
    raise error
jsonschema.exceptions.ValidationError: '1' is not of type 'integer'

Failed validating 'type' in schema['properties']['services']['patternProperties']['^[a-zA-Z0-9._-]+$']['properties']['deploy']['properties']['replicas']:
    {'type': 'integer'}

On instance['services']['projectname']['deploy']['replicas']:
    '1'

Describe the solution you'd like
When requiring an integer, I would like a string to attempt a string to int conversion before discarding the value for not being the correct type.

Describe alternatives you've considered
YAML does not support conditionals, so the values will have to be set outside of the YAML file. When bringing them in they are always treated as strings, for as far as I know. I do not know of a way to mitigate this.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions