Skip to content

feat(cli): add support for building images for java connectors #522

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

Merged
merged 11 commits into from
Apr 30, 2025

Conversation

aaronsteers
Copy link
Contributor

@aaronsteers aaronsteers commented Apr 30, 2025

This add the ability to build Java connector images.

# Test building from the dev version of the CDK:
poetry run airbyte-cdk image build --connector-directory=../airbyte/airbyte-integrations/connectors/source-mysql

# Future syntax with the prefix (after release):
cd /airbyte/airbyte-integrations/connectors/source-mysql
airbyte-cdk image build

# Prove the image works:
docker run --rm airbyte/source-mysql:dev spec

This does not fully harden the image nor does it test every scenario needed to allow this to (yet) replace the airbyte-ci build and publish process. In future iterations, we would hopefully gain increasing confidence over time until we're ready to turn off the current Dagger-based processes.

Combined with this PR, we'd be able to run FAST tests on any connector via docker, regardless of language:

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • Added support for building and running Java connectors within the Docker build process.
  • Improvements
    • Enhanced verification of connector images by improving JSON output parsing for increased robustness.
    • Updated Dockerfile and ignore rules to optimize Java connector packaging.

@aaronsteers aaronsteers marked this pull request as ready for review April 30, 2025 19:24
@Copilot Copilot AI review requested due to automatic review settings April 30, 2025 19:24
@aaronsteers aaronsteers changed the title add support for building images for java connectors feat(cli): add support for building images for java connectors Apr 30, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for building Docker images for Java connectors by introducing a new Dockerfile template and updating the image build and verification processes.

  • Added a dedicated Java connector Dockerfile template.
  • Updated the build process to run Gradle for creating the connector tar file.
  • Improved JSON parsing in the image verification function to handle multi-line outputs.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
airbyte_cdk/utils/docker_image_templates.py Introduces a Java connector Dockerfile template with custom settings.
airbyte_cdk/utils/docker.py Updates _build_image to build the tar file for Java connectors and adjusts JSON parsing in verify_connector_image.

Copy link
Contributor

coderabbitai bot commented Apr 30, 2025

📝 Walkthrough

Walkthrough

The changes introduce support for Java connectors in the Docker build process within the Airbyte CDK. The build_connector_image function is updated to handle Java connectors by adjusting the build context to the repository root and running a Gradle build step before constructing the Docker image. A new Java-specific Dockerfile template is added and returned by get_dockerfile_template when applicable. The verify_connector_image function is enhanced to parse and validate JSON output from the connector's spec command line-by-line, ensuring a valid "SPEC" object is present and handling errors more robustly.

Changes

File(s) Change Summary
airbyte_cdk/utils/docker.py Updated build_connector_image to support Java connectors by running a Gradle distTar build and adjusting the Docker build context directory. Modified get_dockerfile_template to return a Java-specific Dockerfile template for Java connectors. Enhanced verify_connector_image to parse the connector spec command output line-by-line, validating the presence of a "SPEC" JSON object and improving error handling on JSON parsing failures.
airbyte_cdk/utils/docker_image_templates.py Modified .dockerignore template to ignore all files by default and explicitly allow build/distributions/*.tar. Added a new JAVA_CONNECTOR_DOCKERFILE_TEMPLATE string constant defining a Dockerfile tailored for Java connectors, including base image, system setup, user creation, directory permissions, environment variables for Airbyte commands, and setting the entrypoint and labels.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant BuildScript
    participant Gradle
    participant Docker
    participant Connector

    User->>BuildScript: Initiate Docker build for connector
    BuildScript->>BuildScript: Check connector language
    alt If Java connector
        BuildScript->>Gradle: Run Gradle distTar for connector
        Gradle-->>BuildScript: TAR file produced
        BuildScript->>Docker: Build image using Java Dockerfile template
    else Non-Java connector
        BuildScript->>Docker: Build image using standard template
    end
    Docker-->>BuildScript: Image built

    BuildScript->>Docker: Run connector image with spec command
    Docker->>Connector: Execute spec
    Connector-->>Docker: Output (possibly multi-line JSON)
    Docker-->>BuildScript: Return output
    BuildScript->>BuildScript: Parse each line for valid SPEC JSON
    alt SPEC found
        BuildScript-->>User: Verification successful
    else
        BuildScript-->>User: Verification failed
    end
Loading

Suggested reviewers

  • bnchrch
  • ChristoGrab

Would you like to consider adding a test or example for the new Java Dockerfile template to help future maintainers, wdyt?


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8547527 and 8fb3eeb.

📒 Files selected for processing (2)
  • airbyte_cdk/utils/docker.py (4 hunks)
  • airbyte_cdk/utils/docker_image_templates.py (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • airbyte_cdk/utils/docker_image_templates.py
  • airbyte_cdk/utils/docker.py
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: Check: 'source-pokeapi' (skip=false)
  • GitHub Check: Check: 'source-amplitude' (skip=false)
  • GitHub Check: Check: 'source-shopify' (skip=false)
  • GitHub Check: Check: 'source-hardcoded-records' (skip=false)
  • GitHub Check: Pytest (All, Python 3.11, Ubuntu)
  • GitHub Check: Pytest (All, Python 3.10, Ubuntu)
  • GitHub Check: Pytest (Fast)
  • GitHub Check: SDM Docker Image Build
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (2)
airbyte_cdk/utils/docker_image_templates.py (2)

114-139: Hard-coded YUM commands may fail on future Corretto images

The new template assumes that yum is available in the amazoncorretto:<version> image and uses the AL2023 packaging layout. While this is true today, the Corretto team occasionally rebases to newer AL versions and has switched package managers in the past (e.g. to dnf / microdnf). If that happens every build will break.

Would it be safer to:

  1. Invoke the package manager through the /usr/bin/dnf symlink which exists in both yum and dnf images, or
  2. Delegate the installation to a slimmer “builder” stage and copy only the artefacts you need into the final image?

Happy to draft a small multi-stage alternative if you’d like—wdyt?


165-169: Single-stage image keeps build artefacts & increases size

The connector TAR is extracted in the same stage that becomes the runtime image, so the (possibly large) TAR layer is kept in the final history. A classic Docker optimisation is to:

  1. Run the tar xf … in a builder stage,
  2. COPY --from=builder /airbyte /airbyte into a slim runtime stage.

This can shave off hundreds of MB for large connectors. Worth considering before this pattern gets duplicated—wdyt?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4d04ed5 and 8e23162.

📒 Files selected for processing (2)
  • airbyte_cdk/utils/docker.py (4 hunks)
  • airbyte_cdk/utils/docker_image_templates.py (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
airbyte_cdk/utils/docker.py (2)
airbyte_cdk/sources/types.py (1)
  • data (35-36)
airbyte_cdk/models/connector_metadata.py (2)
  • language (51-65)
  • ConnectorLanguage (12-19)
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: Check: 'source-pokeapi' (skip=false)
  • GitHub Check: Check: 'source-amplitude' (skip=false)
  • GitHub Check: Check: 'source-shopify' (skip=false)
  • GitHub Check: Check: 'source-hardcoded-records' (skip=false)
  • GitHub Check: Pytest (All, Python 3.11, Ubuntu)
  • GitHub Check: Pytest (Fast)
  • GitHub Check: Pytest (All, Python 3.10, Ubuntu)
🔇 Additional comments (2)
airbyte_cdk/utils/docker.py (2)

69-69: Relative “three-levels-up” context is brittle

context_dir = context_dir.parent.parent.parent presumes every Java connector lives exactly at airbyte-integrations/connectors/<name>. If that path ever changes the build will fail silently. Could we derive the repo root with git rev-parse --show-toplevel or a pathlib search instead?


266-268: Nice! Java connectors now return the correct template

The switch to return JAVA_CONNECTOR_DOCKERFILE_TEMPLATE looks perfect and keeps the error handling consistent. 👍

@github-actions github-actions bot added the enhancement New feature or request label Apr 30, 2025
Copy link
Contributor

@edgao edgao left a comment

Choose a reason for hiding this comment

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

seems legit! I didn't review the dockerfile, but the python diff made sense. (I wouldn't be surprised if the dockerignore stuff causes some random weird connector to blow up, but we can deal that if/when it happens)

probably worth also tagging someone from db sources as fyi

@aaronsteers aaronsteers requested a review from rodireich April 30, 2025 22:19
@aaronsteers aaronsteers enabled auto-merge (squash) April 30, 2025 23:20
@aaronsteers aaronsteers merged commit ce2a7bb into main Apr 30, 2025
20 of 28 checks passed
@aaronsteers aaronsteers deleted the aj/feat/cli/add-java-connector-build branch April 30, 2025 23:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants