Skip to content

Commit 83eaca9

Browse files
enhancement: Improve build process to match airbyte-ci's approach with multi-stage builds
Co-Authored-By: Aaron <AJ> Steers <[email protected]>
1 parent df4b315 commit 83eaca9

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

airbyte_cdk/utils/docker/build.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,13 @@ def build_from_base_image(
258258
) -> str:
259259
"""Build a Docker image for the connector using a base image.
260260
261+
This implementation follows a similar approach to airbyte-ci:
262+
1. Creates a builder stage to install dependencies
263+
2. Copies only necessary build files first
264+
3. Installs dependencies
265+
4. Copies the connector code
266+
5. Sets up the entrypoint
267+
261268
Args:
262269
connector_dir: Path to the connector directory.
263270
metadata: The connector metadata.
@@ -292,14 +299,35 @@ def build_from_base_image(
292299
except subprocess.CalledProcessError:
293300
logger.warning("Pre-install hook failed, continuing with build")
294301

302+
build_files = [
303+
"setup.py",
304+
"pyproject.toml",
305+
"poetry.lock",
306+
"poetry.toml",
307+
"requirements.txt",
308+
"README.md",
309+
"build_customization.py"
310+
]
311+
312+
connector_package_name = connector_dir.name.replace("-", "_")
313+
295314
dockerfile_content = f"""
315+
FROM {base_image} as builder
316+
317+
WORKDIR /airbyte/integration_code
318+
319+
COPY setup.py pyproject.toml poetry.lock poetry.toml requirements.txt README.md build_customization.py ./
320+
COPY {connector_package_name} ./{connector_package_name}
321+
322+
RUN pip install --no-cache-dir .
323+
296324
FROM {base_image}
297325
298326
WORKDIR /airbyte/integration_code
299327
300-
COPY . .
328+
COPY --from=builder /usr/local /usr/local
301329
302-
RUN pip install .
330+
COPY . .
303331
304332
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/{get_main_file_name(connector_dir)}"
305333
ENTRYPOINT ["python", "/airbyte/integration_code/{get_main_file_name(connector_dir)}"]
@@ -310,6 +338,7 @@ def build_from_base_image(
310338

311339
dockerignore_content = """
312340
*
341+
313342
!setup.py
314343
!pyproject.toml
315344
!poetry.lock

0 commit comments

Comments
 (0)