diff --git a/connect/eaas/core/validation/validators/base.py b/connect/eaas/core/validation/validators/base.py index 80b6064..c3e357f 100644 --- a/connect/eaas/core/validation/validators/base.py +++ b/connect/eaas/core/validation/validators/base.py @@ -224,7 +224,10 @@ def validate_docker_compose_yml(context): # noqa: CCR001 ), ) continue - image = from_cmd[4:].strip() + image = ( + re.sub(r'\s+AS\s+.*', '', from_cmd[4:], flags=re.IGNORECASE) + .strip() + ) # noqa: S5852 if image != runner_image: messages.append( ValidationItem( diff --git a/tests/connect/eaas/core/validation/validators/test_base.py b/tests/connect/eaas/core/validation/validators/test_base.py index 8db1fef..4ecb009 100644 --- a/tests/connect/eaas/core/validation/validators/test_base.py +++ b/tests/connect/eaas/core/validation/validators/test_base.py @@ -566,6 +566,37 @@ def test_validate_docker_compose_yml_invalid_image_dockerfile(mocker): assert item.file == 'fake_dir/Dockerfile' +def test_validate_docker_compose_yml_multistage_image_dockerfile(mocker): + mocker.patch( + 'connect.eaas.core.validation.validators.base.os.path.isfile', + return_value=True, + ) + mocked_open = mocker.MagicMock() + mocked_open.read.return_value = ( + 'FROM cloudblueconnect/connect-extension-runner:0.3 as a-stage-name\n' + ) + mocker.patch( + 'connect.eaas.core.validation.validators.base.open', + side_effect=[None, mocked_open], + ) + mocker.patch( + 'connect.eaas.core.validation.validators.base.yaml.safe_load', + return_value={ + 'services': { + 'dev': { + 'build': {'dockerfile': 'Dockerfile'}, + }, + }, + }, + ) + + result = validate_docker_compose_yml({'project_dir': 'fake_dir', 'runner_version': '0.3'}) + + assert isinstance(result, ValidationResult) + assert result.must_exit is False + assert len(result.items) == 0 + + def test_validate_docker_compose_yml_invalid_image_no_dockerfile(mocker): mocker.patch( 'connect.eaas.core.validation.validators.base.os.path.isfile',