-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
SAT: verify AIRBYTE_ENTRYPOINT
is defined
#4478
Changes from 19 commits
69aa7a6
fd4db49
1da955d
075a044
9b66d50
ad4274a
472ad1a
b62ae92
62f84d5
a2ba9b6
b143ad5
b74e6ff
076d31e
d5da978
28505cc
7ab4c81
214209b
d4b6d4f
770b508
6f52aed
b9991f1
387493c
36f76f9
c6e2bd4
045c749
64a811b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,103 @@ | ||||||
# | ||||||
# MIT License | ||||||
# | ||||||
# Copyright (c) 2020 Airbyte | ||||||
# | ||||||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
# of this software and associated documentation files (the "Software"), to deal | ||||||
# in the Software without restriction, including without limitation the rights | ||||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||||||
# copies of the Software, and to permit persons to whom the Software is | ||||||
# furnished to do so, subject to the following conditions: | ||||||
# | ||||||
# The above copyright notice and this permission notice shall be included in all | ||||||
# copies or substantial portions of the Software. | ||||||
# | ||||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||||||
# SOFTWARE. | ||||||
# | ||||||
|
||||||
import io | ||||||
|
||||||
import docker | ||||||
import pytest | ||||||
from source_acceptance_test.utils import ConnectorRunner | ||||||
|
||||||
|
||||||
def build_docker_image(text: str, tag: str) -> docker.models.images.Image: | ||||||
""" | ||||||
Really for this test we dont need to remove the image since we access it by a string name | ||||||
and remove it also by a string name. But maybe we wanna use it somewhere | ||||||
""" | ||||||
client = docker.from_env() | ||||||
fileobj = io.BytesIO(bytes(text)) | ||||||
image, iterools_tee = client.images.build(fileobj=fileobj, tag=tag, forcerm=True, rm=True) | ||||||
return image | ||||||
|
||||||
|
||||||
@pytest.fixture | ||||||
def dockerfile_valid(tmp_path): | ||||||
dockerfile_text = b""" | ||||||
FROM scratch | ||||||
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py" | ||||||
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"] | ||||||
""" | ||||||
tag = "my-valid-one" | ||||||
build_docker_image(dockerfile_text, tag) | ||||||
docker_runner = ConnectorRunner(image_name=tag, volume=tmp_path) | ||||||
yield docker_runner | ||||||
client = docker.from_env() | ||||||
client.images.remove(image=tag, force=True) | ||||||
vovavovavovavova marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
|
||||||
@pytest.fixture | ||||||
def dockerfile_no_env(tmp_path): | ||||||
dockerfile_text = b""" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
FROM scratch | ||||||
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"] | ||||||
""" | ||||||
tag = "my-no-env" | ||||||
build_docker_image(dockerfile_text, tag) | ||||||
docker_runner = ConnectorRunner(image_name=tag, volume=tmp_path) | ||||||
yield docker_runner | ||||||
client = docker.from_env() | ||||||
client.images.remove(image=tag, force=True) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||||||
|
||||||
|
||||||
@pytest.fixture | ||||||
def dockerfile_ne_properties(tmp_path): | ||||||
dockerfile_text = b""" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
FROM scratch | ||||||
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py" | ||||||
ENTRYPOINT ["python3", "/airbyte/integration_code/main.py"] | ||||||
""" | ||||||
tag = "my-ne-properties" | ||||||
build_docker_image(dockerfile_text, tag) | ||||||
docker_runner = ConnectorRunner(image_name=tag, volume=tmp_path) | ||||||
yield docker_runner | ||||||
client = docker.from_env() | ||||||
client.images.remove(image=tag, force=True) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||||||
|
||||||
|
||||||
class TestEnvAttributes: | ||||||
def test_build_dockerfile_valid(self, dockerfile_valid): | ||||||
|
||||||
assert dockerfile_valid.env_variables.get("AIRBYTE_ENTRYPOINT"), "AIRBYTE_ENTRYPOINT must be set in dockerfile" | ||||||
assert dockerfile_valid.env_variables.get("AIRBYTE_ENTRYPOINT") == " ".join( | ||||||
dockerfile_valid.entry_point | ||||||
), "env should be equal to space-joined entrypoint" | ||||||
|
||||||
vovavovavovavova marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
def test_build_dockerfile_no_env(self, dockerfile_no_env): | ||||||
assert not dockerfile_no_env.env_variables.get("AIRBYTE_ENTRYPOINT"), "this test should fail if AIRBYTE_ENTRYPOINT defined" | ||||||
|
||||||
def test_build_dockerfile_ne_properties(self, dockerfile_ne_properties): | ||||||
|
||||||
assert dockerfile_ne_properties.env_variables.get("AIRBYTE_ENTRYPOINT"), "AIRBYTE_ENTRYPOINT must be set in dockerfile" | ||||||
assert dockerfile_ne_properties.env_variables.get("AIRBYTE_ENTRYPOINT") != " ".join(dockerfile_ne_properties.entry_point), ( | ||||||
"This test should fail if we have " ".join(ENTRYPOINT)==ENV" | ||||||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dockerfile failing with exception and asking to use BytesIo instead of StringIO. BytesIO this type of file-like object required binary content (or encoding provided to encode the text), so I have to use binary strings in this cases. This case will not work if I pass the normal text