|
15 | 15 |
|
16 | 16 | def build_ab_images( |
17 | 17 | job_directory: str, |
| 18 | + location_a: str, |
18 | 19 | commit_sha_a: str, |
| 20 | + location_b: str, |
19 | 21 | commit_sha_b: str, |
20 | 22 | docker_client: docker.client.DockerClient | None = None, |
21 | 23 | ) -> tuple[str, str]: |
22 | 24 | """Build Docker images based on 2 commit SHAs. |
23 | 25 |
|
24 | 26 | Args: |
25 | 27 | job_directory: The directory containing all files related to a job. |
| 28 | + location_a: Location of Transmogrifier version 'A' to clone from. |
26 | 29 | commit_sha_a: The SHA of the first commit for comparison. |
| 30 | + location_b: Location of Transmogrifier version 'B' to clone from. |
27 | 31 | commit_sha_b: The SHA of the second commit for comparison. |
28 | 32 | docker_client: A configured Docker client. |
29 | 33 | """ |
30 | 34 | if not docker_client: |
31 | 35 | docker_client = docker.from_env() |
32 | 36 |
|
33 | 37 | image_tags = [] |
34 | | - for commit_sha in [commit_sha_a, commit_sha_b]: |
| 38 | + for location, commit_sha in [(location_a, commit_sha_a), (location_b, commit_sha_b)]: |
35 | 39 | logger.debug(f"Processing commit: {commit_sha}") |
36 | 40 | image_tag = generate_image_name(commit_sha) |
37 | 41 | if docker_image_exists(docker_client, image_tag): |
38 | 42 | logger.debug(f"Docker image already exists with tag: {image_tag}") |
39 | 43 | image_tags.append(image_tag) |
40 | 44 | else: |
41 | | - image = build_image(commit_sha, docker_client) |
| 45 | + image = build_image(location, commit_sha, docker_client) |
42 | 46 | image_tags.append(image.tags[0]) |
43 | 47 | logger.debug(f"Finished processing commit: {commit_sha}") |
44 | 48 |
|
@@ -67,43 +71,44 @@ def docker_image_exists( |
67 | 71 |
|
68 | 72 |
|
69 | 73 | def build_image( |
| 74 | + location: str, |
70 | 75 | commit_sha: str, |
71 | 76 | docker_client: docker.client.DockerClient, |
72 | 77 | ) -> docker.models.images.Image: |
73 | 78 | """Clone repo and build Docker image. |
74 | 79 |
|
75 | 80 | Args: |
76 | | - job_directory: The directory containing all files related to a job. |
| 81 | + location: Location of Transmogrifier to clone from. |
77 | 82 | commit_sha: The SHA of the commit. |
78 | 83 | docker_client: A configured Docker client. |
79 | 84 | """ |
80 | 85 | with tempfile.TemporaryDirectory() as clone_directory: |
81 | 86 | image_tag = generate_image_name(commit_sha) |
82 | | - clone_repo_and_reset_to_commit(clone_directory, commit_sha) |
| 87 | + clone_repo_and_reset_to_commit(location, clone_directory, commit_sha) |
83 | 88 | image, _ = docker_client.images.build(path=clone_directory, tag=image_tag) |
84 | 89 | logger.debug(f"Docker image created with tag: {image}") |
85 | 90 | return image |
86 | 91 |
|
87 | 92 |
|
88 | | -def clone_repo_and_reset_to_commit(clone_directory: str, commit_sha: str) -> None: |
| 93 | +def clone_repo_and_reset_to_commit( |
| 94 | + location: str, |
| 95 | + clone_directory: str, |
| 96 | + commit_sha: str, |
| 97 | +) -> None: |
89 | 98 | """Clone GitHub repo and reset to a specified commit. |
90 | 99 |
|
91 | 100 | Args: |
| 101 | + location: Location of Transmogrifier to clone from. |
92 | 102 | clone_directory: The directory for the cloned repo. |
93 | 103 | commit_sha: The SHA of a repo commit. |
94 | 104 | """ |
95 | | - logger.debug(f"Cloning repo to: {clone_directory}") |
96 | | - transmogrifier_url = "https://github.com/MITLibraries/transmogrifier.git" |
| 105 | + logger.debug(f"Cloning repo from: {location}, to: {clone_directory}") |
97 | 106 | repository = clone_repository( |
98 | | - transmogrifier_url, |
| 107 | + location, |
99 | 108 | clone_directory, |
100 | 109 | ) |
101 | | - logger.debug(f"Cloned repo to: {clone_directory}") |
102 | | - |
103 | 110 | try: |
104 | 111 | repository.reset(commit_sha, ResetMode.HARD) |
105 | 112 | logger.debug(f"Cloned repo reset to commit: {commit_sha}") |
106 | 113 | except KeyError as exception: |
107 | | - raise InvalidRepositoryCommitSHAError( |
108 | | - transmogrifier_url, commit_sha |
109 | | - ) from exception |
| 114 | + raise InvalidRepositoryCommitSHAError(location, commit_sha) from exception |
0 commit comments