Skip to content

Commit 9a6f844

Browse files
author
maxime.c
committed
set sha256 for 7.0.0 image and update tag in metadata
1 parent 734139a commit 9a6f844

File tree

1 file changed

+65
-5
lines changed

1 file changed

+65
-5
lines changed

bin/v7_migration.py

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
# * Create the PR
77
# * Find and replace `[TBD](https://github.com/airbytehq/airbyte/pull/TBD)`
88

9-
# TODO
10-
# * Set the hash for the source-declarative-manifest docker image (hardcoded as "<TBD>" for now)
11-
129

1310
import argparse
1411
import re
@@ -349,16 +346,19 @@ def is_eligible_for_migration(self) -> bool:
349346
and not self.has_custom_retriever()
350347
and not self.has_custom_partition_router()
351348
and not self.imports_deprecated_class()
349+
and not self.has_pyproject_toml()
352350
)
353351

354-
def migrate_to_cdk_v7(self, sha256_hash: str = "<TBD>") -> bool:
352+
def migrate_to_cdk_v7(self, sha256_hash: str = "af8807056f8218ecf0d4ec6b6ee717cdf20251fee5d2c1c77b5723771363b9b0") -> bool:
355353
"""
356354
Migrate the connector to CDK version 7.
357355
358356
This handles two cases:
359357
1. If the connector uses source-declarative-manifest, updates the metadata.yaml
360358
to use baseImage: docker.io/airbyte/source-declarative-manifest:7.0.0@sha256:<TBD>
361359
2. If the connector is Python, sets the version in pyproject.toml to ^7
360+
361+
For both cases, it also increments the dockerImageTag in metadata.yaml.
362362
363363
Args:
364364
sha256_hash: The SHA256 hash for the v7.0.0 base image (default: "<TBD>")
@@ -428,10 +428,17 @@ def _migrate_declarative_manifest_to_v7(self, sha256_hash: str) -> bool:
428428

429429
updated_content = re.sub(base_image_pattern, replacement, metadata_content)
430430

431-
# Write back the updated metadata
431+
# Write back the updated metadata with the new base image
432432
with open(metadata_file, "w") as f:
433433
f.write(updated_content)
434434

435+
# Update dockerImageTag in metadata.yaml
436+
metadata_updated = self._update_docker_image_tag()
437+
if not metadata_updated:
438+
print(
439+
f"Warning: dockerImageTag update failed for {self.name}, but baseImage was updated successfully"
440+
)
441+
435442
print(f"Successfully migrated {self.name} to use CDK v7 declarative manifest")
436443
return True
437444

@@ -486,6 +493,13 @@ def _migrate_python_connector_to_v7(self) -> bool:
486493
f"Warning: poetry lock failed for {self.name}, but pyproject.toml was updated successfully"
487494
)
488495

496+
# Update dockerImageTag in metadata.yaml
497+
metadata_updated = self._update_docker_image_tag()
498+
if not metadata_updated:
499+
print(
500+
f"Warning: dockerImageTag update failed for {self.name}, but pyproject.toml was updated successfully"
501+
)
502+
489503
print(f"Successfully migrated {self.name} to use CDK v7 in pyproject.toml")
490504
return True
491505
else:
@@ -496,6 +510,52 @@ def _migrate_python_connector_to_v7(self) -> bool:
496510
print(f"Error migrating Python connector {self.name}: {e}")
497511
return False
498512

513+
def _update_docker_image_tag(self) -> bool:
514+
"""
515+
Update the dockerImageTag field in metadata.yaml by incrementing the version.
516+
517+
Returns:
518+
True if update was successful, False otherwise
519+
"""
520+
try:
521+
metadata_file = self.path / "metadata.yaml"
522+
523+
if not metadata_file.exists():
524+
print(f"No metadata.yaml found for {self.name}")
525+
return False
526+
527+
# Load the current metadata
528+
with open(metadata_file, "r") as f:
529+
metadata_content = f.read()
530+
531+
# Update the dockerImageTag field by incrementing the version
532+
docker_tag_pattern = r"(dockerImageTag:\s*)([^\n\r]+)"
533+
docker_tag_match = re.search(docker_tag_pattern, metadata_content)
534+
535+
if docker_tag_match:
536+
current_tag = docker_tag_match.group(2).strip()
537+
new_tag = self._increment_version(current_tag)
538+
539+
updated_content = re.sub(
540+
docker_tag_pattern,
541+
rf"\g<1>{new_tag}",
542+
metadata_content
543+
)
544+
545+
# Write back the updated metadata
546+
with open(metadata_file, "w") as f:
547+
f.write(updated_content)
548+
549+
print(f"Updated dockerImageTag from {current_tag} to {new_tag} for {self.name}")
550+
return True
551+
else:
552+
print(f"Warning: dockerImageTag not found in metadata.yaml for {self.name}")
553+
return False
554+
555+
except Exception as e:
556+
print(f"Error updating dockerImageTag for {self.name}: {e}")
557+
return False
558+
499559
def _run_poetry_lock(self) -> bool:
500560
"""
501561
Run poetry lock to update the lock file after dependency changes.

0 commit comments

Comments
 (0)