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

airbyte-ci: set user to airbyte on connector build #36545

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions airbyte-ci/connectors/pipelines/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,7 @@ airbyte-ci connectors --language=low-code migrate-to-manifest-only

| Version | PR | Description |
| ------- | ---------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| 4.43.0 | [#36545](https://github.com/airbytehq/airbyte/pull/36545) | Switch to `airbyte` user when available in Python base image. |
| 4.42.2 | [#48404](https://github.com/airbytehq/airbyte/pull/48404) | Include `advanced_auth` in spec migration for manifest-only pipeline |
| 4.42.1 | [#47316](https://github.com/airbytehq/airbyte/pull/47316) | Connector testing: skip incremental acceptance test when the connector is not released. |
| 4.42.0 | [#47386](https://github.com/airbytehq/airbyte/pull/47386) | Version increment check: make sure consecutive RC remain on the same version. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@

from typing import Any

from base_images.bases import AirbyteConnectorBaseImage # type: ignore
from dagger import Container, Platform
from pipelines.airbyte_ci.connectors.build_image.steps import build_customization
from pipelines.airbyte_ci.connectors.build_image.steps.common import BuildConnectorImagesBase
from pipelines.airbyte_ci.connectors.context import ConnectorContext
from pipelines.dagger.actions.python.common import apply_python_development_overrides, with_python_connector_installed
from pipelines.helpers.utils import sh_dash_c
from pipelines.models.steps import StepResult


Expand All @@ -21,6 +23,21 @@ class BuildConnectorImages(BuildConnectorImagesBase):

context: ConnectorContext
PATH_TO_INTEGRATION_CODE = "/airbyte/integration_code"
USER = AirbyteConnectorBaseImage.USER

async def _get_image_user(self, base_container: Container) -> str:
"""If the base image in use has a user named 'airbyte', we will use it as the user for the connector image.

Args:
base_container (Container): The base container to use to build the connector.

Returns:
str: The user to use for the connector image.
"""
users = (await base_container.with_exec(sh_dash_c(["cut -d: -f1 /etc/passwd | sort | uniq"])).stdout()).splitlines()
if self.USER in users:
return self.USER
return "root"

async def _build_connector(self, platform: Platform, *args: Any) -> Container:
if (
Expand Down Expand Up @@ -60,6 +77,7 @@ async def _build_from_base_image(self, platform: Platform) -> Container:
"""
self.logger.info(f"Building connector from base image in metadata for {platform}")
base = self._get_base_container(platform)
user = await self._get_image_user(base)
customized_base = await build_customization.pre_install_hooks(self.context.connector, base, self.logger)
main_file_name = build_customization.get_main_file_name(self.context.connector)

Expand All @@ -73,16 +91,18 @@ async def _build_from_base_image(self, platform: Platform) -> Container:
# copy python dependencies from builder to connector container
customized_base.with_directory("/usr/local", builder.directory("/usr/local"))
.with_workdir(self.PATH_TO_INTEGRATION_CODE)
.with_file(main_file_name, (await self.context.get_connector_dir(include=[main_file_name])).file(main_file_name))
.with_exec(["chown", "-R", f"{user}:{user}", "."])
.with_file(main_file_name, (await self.context.get_connector_dir(include=[main_file_name])).file(main_file_name), owner=user)
.with_directory(
connector_snake_case_name,
(await self.context.get_connector_dir(include=[connector_snake_case_name])).directory(connector_snake_case_name),
owner=user,
)
)

connector_container = build_customization.apply_airbyte_entrypoint(base_connector_container, self.context.connector)
customized_connector = await build_customization.post_install_hooks(self.context.connector, connector_container, self.logger)
return customized_connector
return customized_connector.with_user(user)

async def _build_from_dockerfile(self, platform: Platform) -> Container:
"""Build the connector container using its Dockerfile.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ async def install_testing_environment(
# Install the connector python package in /test_environment with the extra dependencies
await pipelines.dagger.actions.python.common.with_python_connector_installed(
self.context,
# Reset the entrypoint to run non airbyte commands
built_connector_container.with_entrypoint([]),
# Reset the entrypoint to run non airbyte commands and set the user to root to install the dependencies and access secrets
built_connector_container.with_entrypoint([]).with_user("root"),
str(self.context.connector.code_directory),
additional_dependency_groups=extra_dependencies_names,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ async def with_installed_python_package(
Returns:
Container: A python environment container with the python package installed.
"""

container = with_python_package(context, python_environment, package_source_code_path, exclude=exclude, include=include)
local_dependencies = await find_local_python_dependencies(context, package_source_code_path)

Expand Down
2 changes: 1 addition & 1 deletion airbyte-ci/connectors/pipelines/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "pipelines"
version = "4.42.2"
version = "4.43.0"
description = "Packaged maintained by the connector operations team to perform CI for connectors' pipelines"
authors = ["Airbyte <contact@airbyte.io>"]

Expand Down
Loading