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: use the base image to build java connectors #49832

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
7 changes: 4 additions & 3 deletions airbyte-ci/connectors/pipelines/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -853,9 +853,10 @@ airbyte-ci connectors --language=low-code migrate-to-manifest-only
## Changelog

| Version | PR | Description |
|---------|------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------|
| 4.46.5 | [#49835](https://github.com/airbytehq/airbyte/pull/49835) | Fix connector language discovery for projects with Kotlin Gradle build scripts. |
| 4.46.4 | [#49462](https://github.com/airbytehq/airbyte/pull/49462) | Support Kotlin Gradle build scripts in connectors. |
| ------- | ---------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| 4.47.0 | [#49832](https://github.com/airbytehq/airbyte/pull/49462) | Build java connectors from the base image declared in `metadata.yaml`. |
| 4.46.5 | [#49835](https://github.com/airbytehq/airbyte/pull/49835) | Fix connector language discovery for projects with Kotlin Gradle build scripts. |
| 4.46.4 | [#49462](https://github.com/airbytehq/airbyte/pull/49462) | Support Kotlin Gradle build scripts in connectors. |
| 4.46.3 | [#49465](https://github.com/airbytehq/airbyte/pull/49465) | Fix `--use-local-cdk` on rootless connectors. |
| 4.46.2 | [#49136](https://github.com/airbytehq/airbyte/pull/49136) | Fix failed install of python components due to non-root permissions. |
| 4.46.1 | [#49146](https://github.com/airbytehq/airbyte/pull/49146) | Update `crane` image address as the one we were using has been deleted by the maintainer. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
from pipelines.consts import AMAZONCORRETTO_IMAGE
from pipelines.dagger.actions.connector.hooks import finalize_build
from pipelines.dagger.actions.connector.normalization import DESTINATION_NORMALIZATION_BUILD_CONFIGURATION, with_normalization
from pipelines.helpers.utils import sh_dash_c
from pipelines.helpers.utils import deprecated, sh_dash_c


@deprecated("This function is deprecated. Please declare an explicit base image to use in the java connector metadata.")
def with_integration_base(context: PipelineContext, build_platform: Platform) -> Container:
return (
context.dagger_client.container(platform=build_platform)
Expand All @@ -24,6 +25,7 @@ def with_integration_base(context: PipelineContext, build_platform: Platform) ->
)


@deprecated("This function is deprecated. Please declare an explicit base image to use in the java connector metadata.")
def with_integration_base_java(context: PipelineContext, build_platform: Platform) -> Container:
integration_base = with_integration_base(context, build_platform)
yum_packages_to_install = [
Expand Down Expand Up @@ -72,6 +74,7 @@ def with_integration_base_java(context: PipelineContext, build_platform: Platfor
)


@deprecated("This function is deprecated. Please declare an explicit base image to use in the java connector metadata.")
def with_integration_base_java_and_normalization(context: ConnectorContext, build_platform: Platform) -> Container:
yum_packages_to_install = [
"python3",
Expand Down Expand Up @@ -158,22 +161,31 @@ async def with_airbyte_java_connector(context: ConnectorContext, connector_java_
)
)
)

if (
# TODO: remove the condition below once all connectors have a base image declared in their metadata.
if "connectorBuildOptions" in context.connector.metadata and "baseImage" in context.connector.metadata["connectorBuildOptions"]:
base_image_address = context.connector.metadata["connectorBuildOptions"]["baseImage"]
context.logger.info(f"Using base image {base_image_address} from connector metadata to build connector.")
base = context.dagger_client.container(platform=build_platform).from_(base_image_address)
elif (
context.connector.supports_normalization
and DESTINATION_NORMALIZATION_BUILD_CONFIGURATION[context.connector.technical_name]["supports_in_connector_normalization"]
):
base = with_integration_base_java_and_normalization(context, build_platform)
entrypoint = ["/airbyte/run_with_normalization.sh"]
context.logger.warn(
f"Connector {context.connector.technical_name} has in-connector normalization enabled. This is supposed to be deprecated. "
f"Please declare a base image address in the connector metadata.yaml file (connectorBuildOptions.baseImage)."
)
base = with_integration_base_java_and_normalization(context, build_platform).with_entrypoint(["/airbyte/run_with_normalization.sh"])
else:
base = with_integration_base_java(context, build_platform)
entrypoint = ["/airbyte/base.sh"]
context.logger.warn(
f"Connector {context.connector.technical_name} does not declare a base image in its connector metadata. "
f"Please declare a base image address in the connector metadata.yaml file (connectorBuildOptions.baseImage)."
)
base = with_integration_base_java(context, build_platform).with_entrypoint(["/airbyte/base.sh"])

connector_container = (
base.with_workdir("/airbyte")
.with_env_variable("APPLICATION", application)
.with_mounted_directory("built_artifacts", build_stage.directory("/airbyte"))
.with_exec(sh_dash_c(["mv built_artifacts/* ."]))
.with_entrypoint(entrypoint)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just checking: this is safe to remove? I don't actually know

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it it, I set it in the base image. And if the base image code path is not taken I added the entrypoint explicitely on line 177 and 183

)
return await finalize_build(context, connector_container)
14 changes: 14 additions & 0 deletions airbyte-ci/connectors/pipelines/pipelines/helpers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@

import contextlib
import datetime
import functools
import os
import re
import sys
import unicodedata
import warnings
import xml.sax.saxutils
from io import TextIOWrapper
from pathlib import Path
Expand Down Expand Up @@ -388,3 +390,15 @@ async def raise_if_not_user(container: Container, expected_user: str) -> None:
assert (
actual_user == expected_user
), f"Container is not running as the expected user '{expected_user}', it is running as '{actual_user}'."


def deprecated(reason: str) -> Callable:
def decorator(func: Callable) -> Callable:
@functools.wraps(func)
def wrapper(*args: Any, **kwargs: Any) -> Any:
warnings.warn(f"{func.__name__} is deprecated: {reason}", DeprecationWarning, stacklevel=2)
return func(*args, **kwargs)

return wrapper

return decorator
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

til!

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.46.5"
version = "4.47.0"
description = "Packaged maintained by the connector operations team to perform CI for connectors' pipelines"
authors = ["Airbyte <[email protected]>"]

Expand Down
Loading