-
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
connectors-ci: make source-file testable in airbyte-ci #27107
connectors-ci: make source-file testable in airbyte-ci #27107
Conversation
Before Merging a Connector Pull RequestWow! What a great pull request you have here! 🎉 To merge this PR, ensure the following has been done/considered for each connector added or updated:
If the checklist is complete, but the CI check is failing,
|
### WARNING ### | ||
# This Dockerfile will soon be deprecated. | ||
# It is not used to build the connector image we publish to DockerHub. | ||
# The new logic to build the connector image is declared with Dagger here: | ||
# https://github.com/airbytehq/airbyte/blob/master/tools/ci_connector_ops/ci_connector_ops/pipelines/actions/environments.py#L771 | ||
|
||
# If you need to add a custom logic to build your connector image, you can do it by adding a finalize_build.sh or finalize_build.py script in the connector folder. | ||
# Please reach out to the Connectors Operations team if you have any question. |
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.
source-file-secure
is now fully built from Dagger. As source-file
needs to be mounted at build time it was easier to accomplish it with Dagger.
@@ -1,3 +1,2 @@ | |||
-e ../../bases/connector-acceptance-test | |||
-e ../source-file |
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.
source-file
dependency is now explicitly defined in setup.py
.
|
||
from setuptools import find_packages, setup | ||
|
||
|
||
def local_dependency(name: str) -> str: |
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.
Compute the absolute path to the local dependencies. In dagger pipelines we mount local dependencies to /local_dependencies
.
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.
Oh dear python!
I like this solution.
My only reservations are having
- Dagger relying on
file://
to mark relative dependencies, or pip -e as this isnt always the case (example) - our connector setup.py's relying on knowing how dagger works under the hood.
So I want to ask a question for #1 and propose a possible idea for 2
-
I dont think we can do away with this, but how come we dont mount the relative import to the same relative location in the dagger file tree?
-
What if, in the dagger machine, we symlinked the local host path to the dagger
/local_dependencies
version? Would remove the need for havingDAGGER_BUILD
in our connectors folder.
try: | ||
import source_file.source | ||
except ModuleNotFoundError: | ||
current_dir = os.path.dirname(os.path.abspath(__file__)) | ||
parent_source_local = os.path.join(current_dir, "../../source-file") | ||
if os.path.isdir(parent_source_local): | ||
sys.path.append(parent_source_local) | ||
else: | ||
raise RuntimeError("not found parent source folder") | ||
import source_file.source |
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.
This is not required anymore as the source file connector is installed as a normal python deps with pip install.
Affected Connector ReportThe latest commit has removed all connector-related changes. There are no more dependent connectors for this PR. |
/test connector=connectors/source-file
Build PassedTest summary info:
|
/test connector=connectors/source-file-secure
Build FailedTest summary info:
|
While out of scope for this PR, I have the opinion that using local docker containers for testing connectors is bad for a number of reasons:
To that end, I would propose that we work to remove all test containers like this, and set up persistent test hosts for all connectors |
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.
👍 from me, mainly about explicit dependencies!
I'd wait for the other reviews on the 🐍 code before merging
|
||
# If you need to add a custom logic to build your connector image, you can do it by adding a finalize_build.sh or finalize_build.py script in the connector folder. | ||
# Please reach out to the Connectors Operations team if you have any question. | ||
FROM airbyte/source-file:0.3.10 |
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.
Nice.
@@ -21,8 +32,10 @@ | |||
"xlrd==2.0.1", | |||
"openpyxl==3.0.10", | |||
"pyxlsb==1.0.9", | |||
local_dependency("source-file"), |
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.
👍
@@ -24,7 +24,7 @@ | |||
"pyxlsb==1.0.9", | |||
] | |||
|
|||
TEST_REQUIREMENTS = ["pytest~=6.2", "pytest-docker~=1.0.0", "pytest-mock~=3.6.1"] | |||
TEST_REQUIREMENTS = ["pytest~=6.2", "pytest-docker~=1.0.0", "pytest-mock~=3.6.1", "docker-compose"] |
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.
Is this a python package to work with docker?
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.
The source-file integration test use docker-compose without specifying it as a test dependency. I added this so that our pipeline installs it within the test environment, that does not have docker-compose
by default.
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.
Great work here @alafanechere
This must have been annoying to work through
I had one alternative idea, but Im not positive it would work and in the spirit of "done not perfect"
|
||
from setuptools import find_packages, setup | ||
|
||
|
||
def local_dependency(name: str) -> str: |
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.
Oh dear python!
I like this solution.
My only reservations are having
- Dagger relying on
file://
to mark relative dependencies, or pip -e as this isnt always the case (example) - our connector setup.py's relying on knowing how dagger works under the hood.
So I want to ask a question for #1 and propose a possible idea for 2
-
I dont think we can do away with this, but how come we dont mount the relative import to the same relative location in the dagger file tree?
-
What if, in the dagger machine, we symlinked the local host path to the dagger
/local_dependencies
version? Would remove the need for havingDAGGER_BUILD
in our connectors folder.
if await get_file_contents(container, "setup.py"): | ||
container_with_egg_info = container.with_exec(["python", "setup.py", "egg_info"]) | ||
egg_info_output = await container_with_egg_info.stdout() | ||
for line in egg_info_output.split("\n"): |
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.
This must ahve been painful, well done
|
||
if await get_file_contents(container, "setup.py"): | ||
container = container.with_exec(install_connector_package_cmd) | ||
if await get_file_contents(container, "requirements.txt"): |
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.
Nit: We likely will need on for pyproject.toml at some point.
I believe there's indeed a cleaner solution I'd like to tackle later:
Then we'll have a same base container on top of which we can:
I did not take this approach right now because it was too much refacto, and as we still rely on dockerfiles for python connectors (except source-file-secure) we still have a different container for unit/integration tests (dynamically built with dagger) and one for build and publish based on the Dockerfile. This is definitely something we'll tackle when we'll want to remove dockerfiles for Python connectors. |
/test connector=connectors/source-file-secure
Build FailedTest summary info:
|
/test connector=connectors/source-file-secure
Build PassedTest summary info:
|
What
Relates to #25053
Fixing
source-file
source-file
integration tests uses docker-compose to spin up a sftp container used for testing.To make the container orchestration and connection work in
airbyte-ci
we should bind python integration test to the global docker host.The docker host should also have access to the file we want to mount of sftp, to do so we move them to the /tmp folder so that both the container under test, docker host have access to it and the docker host can mount them to the
sftp
containers.Fixing
source-file-secure
source-file-secure has an implicit dependency to source-file: its docker image is based on source-file docker image in which the source-file package was installed.
But, outside of the dockerized execution, executing
import source_file
in python insource-file-secure
fails because our pipeline did not handle installing other connector package.To fix this problem:
setup.py
(@evantahler we previously chatted about the benefits of explicitely variants dependencies insetup.py
)python setup.py egg_ingo
source-file-secure
in the test environment.source-file-secure
docker image we mount and install the same dependencies.