Skip to content

Commit 92d62fa

Browse files
committed
Continue improvement to main
1 parent 8640cb6 commit 92d62fa

File tree

3 files changed

+22
-32
lines changed

3 files changed

+22
-32
lines changed

scripts/release/build_configuration.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,4 @@ class BuildConfiguration:
1818
debug: bool = True
1919

2020
def is_release_step_executed(self) -> bool:
21-
"""
22-
Determines whether release steps should be executed based on build scenario
23-
"""
2421
return self.scenario == BuildScenario.RELEASE

scripts/release/build_context.py

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,7 @@ def infer_scenario_from_environment() -> BuildScenario:
4040

4141
@dataclass
4242
class BuildContext:
43-
"""Holds the context of the current build, detected from the environment."""
44-
45-
ECR_BASE_URL = "268558157000.dkr.ecr.us-east-1.amazonaws.com"
46-
47-
REGISTRY_MAP = {
48-
BuildScenario.RELEASE: f"{ECR_BASE_URL}/julienben/staging-temp", # TODO: replace with real staging repo
49-
BuildScenario.MASTER: f"{ECR_BASE_URL}/dev",
50-
BuildScenario.PATCH: f"{ECR_BASE_URL}/dev",
51-
BuildScenario.DEVELOPMENT: os.environ.get("BASE_REPO_URL"),
52-
}
43+
"""Define build parameters based on the build scenario."""
5344

5445
scenario: BuildScenario
5546
git_tag: Optional[str] = None
@@ -72,26 +63,19 @@ def from_scenario(cls, scenario: BuildScenario) -> "BuildContext":
7263
signing_enabled=signing_enabled,
7364
version=git_tag or patch_id,
7465
)
75-
76-
@classmethod
77-
def from_environment(cls) -> "BuildContext":
78-
"""Auto-detect build context from environment variables."""
79-
scenario = infer_scenario_from_environment()
80-
return cls.from_scenario(scenario)
8166

8267
def get_version(self) -> str:
83-
"""Gets the primary version string for the current build."""
68+
"""Gets the version that will be used to tag the images."""
8469
if self.scenario == BuildScenario.RELEASE:
8570
return self.git_tag
8671
if self.patch_id:
8772
return self.patch_id
8873
return "latest"
8974

9075
def get_base_registry(self) -> str:
91-
"""Get the base registry URL for the current build scenario."""
92-
registry = self.REGISTRY_MAP.get(self.scenario)
93-
if not registry:
94-
raise ValueError(f"No registry defined for scenario {self.scenario}")
95-
logger.info(f"Using registry: {registry}")
96-
return registry
76+
"""Get the base registry URL for the current scenario."""
77+
if self.scenario == BuildScenario.RELEASE:
78+
return os.environ.get("STAGING_REPO_URL")
79+
else:
80+
return os.environ.get("BASE_REPO_URL")
9781

scripts/release/main.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@
4040
BuildScenario,
4141
)
4242

43+
"""
44+
The goal of main.py, build_configuration.py and build_context.py is to provide a single source of truth for the build
45+
configuration. All parameters that depend on the the build environment (local dev, evg, etc) should be resolved here and
46+
not in the pipeline.
47+
"""
48+
4349

4450
def get_builder_function_for_image_name() -> Dict[str, Callable]:
4551
"""Returns a dictionary of image names that can be built."""
@@ -148,6 +154,14 @@ def main():
148154

149155
args = parser.parse_args()
150156

157+
build_config = build_config_from_args(args)
158+
logger.info(f"Building image: {args.image}")
159+
logger.info(f"Build configuration: {build_config}")
160+
161+
build_image(args.image, build_config)
162+
163+
164+
def build_config_from_args(args):
151165
# Validate that the image name is supported
152166
supported_images = get_builder_function_for_image_name().keys()
153167
if args.image not in supported_images:
@@ -172,7 +186,7 @@ def main():
172186
sign = args.sign or build_context.signing_enabled
173187
all_agents = args.all_agents or bool(os.environ.get("all_agents", False))
174188

175-
build_configuration = BuildConfiguration(
189+
return BuildConfiguration(
176190
scenario=scenario,
177191
version=version,
178192
base_registry=registry,
@@ -184,11 +198,6 @@ def main():
184198
parallel_factor=args.parallel_factor,
185199
)
186200

187-
logger.info(f"Building image: {args.image}")
188-
logger.info(f"Build configuration: {build_configuration}")
189-
190-
build_image(args.image, build_configuration)
191-
192201

193202
if __name__ == "__main__":
194203
main()

0 commit comments

Comments
 (0)