Skip to content

Commit

Permalink
fix: allow multistage Dockerfiles by removing AS <stage name> in vali…
Browse files Browse the repository at this point in the history
…dation

- Modified the validate_docker_compose_yml function to support multistage Dockerfiles.
- Updated the FROM line parsing to remove the AS <stage name> part for case-insensitive comparison.
- This ensures compatibility with Dockerfiles using multistage builds.
  • Loading branch information
Sainomori committed May 28, 2024
1 parent 652e28a commit 6388f0b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion connect/eaas/core/validation/validators/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ 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()
if image != runner_image:
messages.append(
ValidationItem(
Expand Down
31 changes: 31 additions & 0 deletions tests/connect/eaas/core/validation/validators/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 6388f0b

Please sign in to comment.