Skip to content

Commit 25a8af0

Browse files
committed
add support for building images for java connectors
1 parent 4d04ed5 commit 25a8af0

File tree

2 files changed

+95
-8
lines changed

2 files changed

+95
-8
lines changed

airbyte_cdk/utils/docker.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from airbyte_cdk.models.connector_metadata import ConnectorLanguage, MetadataFile
1717
from airbyte_cdk.utils.docker_image_templates import (
1818
DOCKERIGNORE_TEMPLATE,
19+
JAVA_CONNECTOR_DOCKERFILE_TEMPLATE,
1920
MANIFEST_ONLY_DOCKERFILE_TEMPLATE,
2021
PYTHON_CONNECTOR_DOCKERFILE_TEMPLATE,
2122
)
@@ -62,6 +63,10 @@ def _build_image(
6263
6364
Raises: ConnectorImageBuildError if the build fails.
6465
"""
66+
if metadata.data.language == ConnectorLanguage.JAVA:
67+
# For Java connectors, the context directory is the repo root.
68+
context_dir = context_dir.parent.parent.parent
69+
6570
docker_args: list[str] = [
6671
"docker",
6772
"build",
@@ -248,10 +253,7 @@ def get_dockerfile_template(
248253
return MANIFEST_ONLY_DOCKERFILE_TEMPLATE
249254

250255
if metadata.data.language == ConnectorLanguage.JAVA:
251-
raise ValueError(
252-
f"Java and Kotlin connectors are not yet supported. "
253-
"Please use airbyte-ci or gradle to build your image."
254-
)
256+
return JAVA_CONNECTOR_DOCKERFILE_TEMPLATE
255257

256258
raise ValueError(
257259
f"Unsupported connector language: {metadata.data.language}. "
@@ -322,10 +324,21 @@ def verify_connector_image(
322324
)
323325
# check that the output is valid JSON
324326
if result.stdout:
325-
try:
326-
json.loads(result.stdout)
327-
except json.JSONDecodeError:
328-
logger.error("Invalid JSON output from spec command.")
327+
found_spec_output = False
328+
for line in result.stdout.split("\n"):
329+
if line.strip():
330+
try:
331+
# Check if the line is a valid JSON object
332+
msg = json.loads(line)
333+
if isinstance(msg, dict) and "type" in msg and msg["type"] == "SPEC":
334+
found_spec_output = True
335+
336+
except json.JSONDecodeError as e:
337+
logger.error(f"Invalid JSON output from spec command: {e}: {line}")
338+
return False
339+
340+
if not found_spec_output:
341+
logger.error("No valid JSON output found for spec command.")
329342
return False
330343
else:
331344
logger.error("No output from spec command.")

airbyte_cdk/utils/docker_image_templates.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,77 @@
9999
ENV AIRBYTE_ENTRYPOINT="python ./main.py"
100100
ENTRYPOINT ["python", "./main.py"]
101101
"""
102+
103+
#########################
104+
# JAVA CONNECTOR IMAGE ##
105+
#########################
106+
107+
JAVA_CONNECTOR_DOCKERFILE_TEMPLATE = """
108+
# Java connector Dockerfile for Airbyte
109+
# This Dockerfile replicates the dagger-based build process for Java connectors
110+
111+
# Build arguments
112+
ARG JDK_VERSION=21-al2023
113+
114+
# Base image - using Amazon Corretto (Amazon's distribution of OpenJDK)
115+
FROM amazoncorretto:${JDK_VERSION}
116+
ARG CONNECTOR_KEBAB_NAME
117+
118+
# Install required packages and set up the non-root user
119+
RUN set -o xtrace && \
120+
yum install -y shadow-utils tar openssl findutils && \
121+
yum update -y --security && \
122+
yum clean all && \
123+
rm -rf /var/cache/yum && \
124+
echo "Creating airbyte user and group..." && \
125+
groupadd --gid 1000 airbyte && \
126+
useradd --uid 1000 --gid airbyte --shell /bin/bash --create-home airbyte && \
127+
echo "Creating directories..." && \
128+
mkdir /secrets && \
129+
mkdir /config && \
130+
mkdir --mode 755 /airbyte && \
131+
mkdir --mode 755 /custom_cache && \
132+
echo "Setting permissions..." && \
133+
chown -R airbyte:airbyte /airbyte && \
134+
chown -R airbyte:airbyte /custom_cache && \
135+
chown -R airbyte:airbyte /secrets && \
136+
chown -R airbyte:airbyte /config && \
137+
chown -R airbyte:airbyte /usr/share/pki/ca-trust-source && \
138+
chown -R airbyte:airbyte /etc/pki/ca-trust && \
139+
chown -R airbyte:airbyte /tmp
140+
141+
# Download required scripts
142+
WORKDIR /airbyte
143+
ADD https://raw.githubusercontent.com/airbytehq/airbyte/6d8a3a2bc4f4ca79f10164447a90fdce5c9ad6f9/airbyte-integrations/bases/base/base.sh /airbyte/base.sh
144+
ADD https://raw.githubusercontent.com/airbytehq/airbyte/6d8a3a2bc4f4ca79f10164447a90fdce5c9ad6f9/airbyte-integrations/bases/base-java/javabase.sh /airbyte/javabase.sh
145+
ADD https://dtdg.co/latest-java-tracer /airbyte/dd-java-agent.jar
146+
147+
# Set permissions for downloaded files
148+
RUN chmod +x /airbyte/base.sh /airbyte/javabase.sh && \
149+
chown airbyte:airbyte /airbyte/base.sh /airbyte/javabase.sh /airbyte/dd-java-agent.jar
150+
151+
# Set environment variables
152+
ENV AIRBYTE_SPEC_CMD="/airbyte/javabase.sh --spec"
153+
ENV AIRBYTE_CHECK_CMD="/airbyte/javabase.sh --check"
154+
ENV AIRBYTE_DISCOVER_CMD="/airbyte/javabase.sh --discover"
155+
ENV AIRBYTE_READ_CMD="/airbyte/javabase.sh --read"
156+
ENV AIRBYTE_WRITE_CMD="/airbyte/javabase.sh --write"
157+
ENV AIRBYTE_ENTRYPOINT="/airbyte/base.sh"
158+
ENV APPLICATION="${CONNECTOR_KEBAB_NAME}"
159+
160+
# Add the connector TAR file and extract it
161+
COPY airbyte-integrations/connectors/${CONNECTOR_KEBAB_NAME}/build/distributions/${CONNECTOR_KEBAB_NAME}.tar /tmp/${CONNECTOR_KEBAB_NAME}.tar
162+
RUN tar xf /tmp/${CONNECTOR_KEBAB_NAME}.tar --strip-components=1 -C /airbyte && \
163+
rm -rf /tmp/${CONNECTOR_KEBAB_NAME}.tar && \
164+
chown -R airbyte:airbyte /airbyte
165+
166+
# Set the non-root user
167+
USER airbyte
168+
169+
# Set entrypoint
170+
ENTRYPOINT ["/airbyte/base.sh"]
171+
172+
# Add labels
173+
LABEL io.airbyte.version="0.1.0"
174+
LABEL io.airbyte.name="airbyte/${CONNECTOR_KEBAB_NAME}"
175+
"""

0 commit comments

Comments
 (0)