Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] x-elbv2 throws validation error using environment variable to set Service port #778

Open
dfrank-a opened this issue Sep 3, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@dfrank-a
Copy link

dfrank-a commented Sep 3, 2024

Using docker run and the latest image, the relevant snippet of my docker-compose file is:

x-elbv2:
  testALB:
    Properties:
      Scheme: internal
      Type: application
      LoadBalancerAttributes:
        deletion_protection.enabled: "false"
    MacroParameters:
      Ingress:
        ExtSources:
          - IPv4: 0.0.0.0/0
            Name: ANY
            Description: "ANY"
    Listeners:
      - Port: 80
        Protocol: HTTP
        DefaultActions:
          - Redirect: HTTP_TO_HTTPS
      - Port: 443
        Protocol: HTTPS
        Certificates:
          - CertificateArn: REDACTED
        Targets:
          - name: family:service
            access: service.com/
    Services:
      'family:service': 
        port: ${FAMILY_SERVICE_PORT}
        protocol: HTTP
        healthcheck: ${FAMILY_SERVICE_PORT}:HTTP:7:2:15:5:/health_check/:200

And .env containing:

FAMILY_SERVICE_PORT=8080
2024-09-03 17:53:39 [   ERROR] elbv2.testALB - Definition is not conform to schema.
Traceback (most recent call last):
  File "/usr/local/bin/ecs-compose-x", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.10/site-packages/ecs_composex/cli.py", line 206, in main
    root_stack = generate_full_template(settings)
  File "/usr/local/lib/python3.10/site-packages/ecs_composex/ecs_composex.py", line 248, in generate_full_template
    settings.mod_manager.init_mods_resources(settings)
  File "/usr/local/lib/python3.10/site-packages/ecs_composex/mods_manager.py", line 307, in init_mods_resources
    module.set_resources(settings)
  File "/usr/local/lib/python3.10/site-packages/ecs_composex/mods_manager.py", line 266, in set_resources
    new_definition = self.resource_class(
  File "/usr/local/lib/python3.10/site-packages/ecs_composex/elbv2/elbv2_stack/elbv2.py", line 75, in __init__
    super().__init__(name, definition, module, settings)
  File "/usr/local/lib/python3.10/site-packages/ecs_composex/compose/x_resources/network_x_resources.py", line 37, in __init__
    super().__init__(name, definition, module, settings)
  File "/usr/local/lib/python3.10/site-packages/ecs_composex/compose/x_resources/services_resources.py", line 39, in __init__
    super().__init__(name, definition, module, settings)
  File "/usr/local/lib/python3.10/site-packages/ecs_composex/compose/x_resources/__init__.py", line 79, in __init__
    self.validate_schema(name, definition, module.mod_key)
  File "/usr/local/lib/python3.10/site-packages/ecs_composex/compose/x_resources/__init__.py", line 191, in validate_schema
    _eval.validate(definition)
  File "/usr/local/lib/python3.10/site-packages/jsonschema/validators.py", line 451, in validate
    raise error
jsonschema.exceptions.ValidationError: '8080' is not of type 'integer'
@dfrank-a dfrank-a added the bug Something isn't working label Sep 3, 2024
@dfrank-a
Copy link
Author

dfrank-a commented Sep 4, 2024

This actually seems more broad than just the port. Attempts to use environment variables almost anywhere a number is expected, results in an error, like the following:

    ...
    healthcheck: # https://docs.docker.com/reference/dockerfile/#healthcheck
      test: ["CMD", "netcat", "-vz", "localhost", "8000"]
      interval: "${WEB_HEALTHCHECK_INTERVAL}"
      timeout: "${WEB_HEALTHCHECK_TIMEOUT}"
      retries: "${WEB_HEALTHCHECK_RETRIES}"
      start_period: "${WEB_HEALTHCHECK_START_PERIOD}"
Traceback (most recent call last):
  File "/usr/local/bin/ecs-compose-x", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.10/site-packages/ecs_composex/cli.py", line 194, in main
    settings = ComposeXSettings(**vars(args))
  File "/usr/local/lib/python3.10/site-packages/ecs_composex/common/settings.py", line 177, in __init__
    self.set_content(kwargs, content)
  File "/usr/local/lib/python3.10/site-packages/ecs_composex/common/settings.py", line 526, in set_content
    content_def = ComposeDefinition(files, content)
  File "/usr/local/lib/python3.10/site-packages/compose_x_render/compose_x_render.py", line 324, in __init__
    jsonschema.validate(
  File "/usr/local/lib/python3.10/site-packages/jsonschema/validators.py", line 1332, in validate
    raise error
jsonschema.exceptions.ValidationError: '5' is not of type 'number'

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

On instance['services']['web']['healthcheck']['retries']:
    '5'

@JohnPreston
Copy link
Member

Hello @dfrank-a
Apologies for the late reply, I had forgotten to click "Comment" :/
The reason you are seeing this issue is that your env vars even though look and feel like an int are in fact str and therefore they are not the expected type. I might have a look at trying to soften the schema to allow either only a string of with digits or numbers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants