@@ -139,7 +139,11 @@ def __copy_environment(
139139 if environment .environment_image_source == models .EnvironmentImageSource .build :
140140 if not environment .build_parameters :
141141 raise errors .ProgrammingError (message = "Environment has no build parameters." )
142+ platforms = [
143+ schemas .BuildPlatformORM (platform = platform ) for platform in environment .build_parameters .platforms
144+ ]
142145 new_build_parameters = schemas .BuildParametersORM (
146+ platforms = platforms ,
143147 builder_variant = environment .build_parameters .builder_variant ,
144148 frontend_variant = environment .build_parameters .frontend_variant ,
145149 repository = environment .build_parameters .repository ,
@@ -165,7 +169,11 @@ def __insert_build_parameters_environment(
165169 raise errors .UnauthorizedError (
166170 message = "You have to be authenticated to insert an environment in the DB." , quiet = True
167171 )
172+ platforms = [
173+ schemas .BuildPlatformORM (platform = platform ) for platform in new_build_parameters_environment .platforms
174+ ]
168175 build_parameters_orm = schemas .BuildParametersORM (
176+ platforms = platforms ,
169177 builder_variant = new_build_parameters_environment .builder_variant ,
170178 frontend_variant = new_build_parameters_environment .frontend_variant ,
171179 repository = new_build_parameters_environment .repository ,
@@ -266,6 +274,10 @@ async def __update_environment_build_parameters(
266274
267275 if build_parameters .repository is not None :
268276 environment .build_parameters .repository = build_parameters .repository
277+ if build_parameters .platforms is not None :
278+ environment .build_parameters .platforms = [
279+ schemas .BuildPlatformORM (platform = platform ) for platform in build_parameters .platforms
280+ ]
269281 if build_parameters .builder_variant is not None :
270282 environment .build_parameters .builder_variant = build_parameters .builder_variant
271283 if build_parameters .frontend_variant is not None :
@@ -419,7 +431,9 @@ async def insert_launcher(
419431 )
420432 session .add (environment_orm )
421433 elif isinstance (launcher .environment , models .UnsavedBuildParameters ):
434+ platforms = [schemas .BuildPlatformORM (platform = platform ) for platform in launcher .environment .platforms ]
422435 build_parameters_orm = schemas .BuildParametersORM (
436+ platforms = platforms ,
423437 builder_variant = launcher .environment .builder_variant ,
424438 frontend_variant = launcher .environment .frontend_variant ,
425439 repository = launcher .environment .repository ,
@@ -719,7 +733,11 @@ async def __update_launcher_environment(
719733 await session .flush ()
720734 case models .UnsavedBuildParameters () as new_custom_built_environment , models .EnvironmentKind .CUSTOM :
721735 # Custom environment with image is replaced by a custom environment with build
736+ platforms = [
737+ schemas .BuildPlatformORM (platform = platform ) for platform in new_custom_built_environment .platforms
738+ ]
722739 build_parameters_orm = schemas .BuildParametersORM (
740+ platforms = platforms ,
723741 builder_variant = new_custom_built_environment .builder_variant ,
724742 frontend_variant = new_custom_built_environment .frontend_variant ,
725743 repository = new_custom_built_environment .repository ,
@@ -885,6 +903,15 @@ async def start_build(self, user: base_models.APIUser, build: models.UnsavedBuil
885903 message = f"Session environment with id '{ build .environment_id } ' already has a build in progress."
886904 )
887905
906+ # We check that we build for a single target platform
907+ if len (build_parameters .platforms ) > 1 :
908+ raise errors .CannotStartBuildError (
909+ message = (
910+ f"Building images can target only one platform at a time. "
911+ f"Current value: { build_parameters .platforms } "
912+ )
913+ )
914+
888915 build_orm = schemas .BuildORM (
889916 environment_id = build .environment_id ,
890917 status = models .BuildStatus .in_progress ,
@@ -1053,6 +1080,9 @@ def _get_buildrun_params(
10531080 git_repository_revision = build_parameters .repository_revision
10541081 context_dir = build_parameters .context_dir
10551082
1083+ builder_image = self .builds_config .build_builder_image or constants .BUILD_DEFAULT_BUILDER_IMAGE
1084+ run_image = self .builds_config .build_run_image or constants .BUILD_DEFAULT_RUN_IMAGE
1085+
10561086 output_image_prefix = (
10571087 self .builds_config .build_output_image_prefix or constants .BUILD_DEFAULT_OUTPUT_IMAGE_PREFIX
10581088 )
@@ -1064,6 +1094,9 @@ def _get_buildrun_params(
10641094 build_strategy_name = self .builds_config .build_strategy_name or constants .BUILD_DEFAULT_BUILD_STRATEGY_NAME
10651095 push_secret_name = self .builds_config .push_secret_name or constants .BUILD_DEFAULT_PUSH_SECRET_NAME
10661096
1097+ node_selector = self .builds_config .node_selector
1098+ tolerations = self .builds_config .tolerations
1099+
10671100 retention_after_failed = (
10681101 self .builds_config .buildrun_retention_after_failed or constants .BUILD_RUN_DEFAULT_RETENTION_AFTER_FAILED
10691102 )
@@ -1084,26 +1117,36 @@ def _get_buildrun_params(
10841117 annotations ["renku.io/launcher_id" ] = str (launcher .id )
10851118 annotations ["renku.io/project_id" ] = str (launcher .project_id )
10861119
1087- return models .ShipwrightBuildRunParams (
1120+ params = models .ShipwrightBuildRunParams (
10881121 name = build .k8s_name ,
10891122 git_repository = git_repository ,
1090- build_image = self . builds_config . build_builder_image or constants . BUILD_DEFAULT_BUILDER_IMAGE ,
1091- run_image = self . builds_config . build_run_image or constants . BUILD_DEFAULT_RUN_IMAGE ,
1123+ builder_image = builder_image ,
1124+ run_image = run_image ,
10921125 output_image = output_image ,
10931126 build_strategy_name = build_strategy_name ,
10941127 push_secret_name = push_secret_name ,
10951128 retention_after_failed = retention_after_failed ,
10961129 retention_after_succeeded = retention_after_succeeded ,
10971130 build_timeout = build_timeout ,
1098- node_selector = self . builds_config . node_selector ,
1099- tolerations = self . builds_config . tolerations ,
1131+ node_selector = node_selector ,
1132+ tolerations = tolerations ,
11001133 labels = labels ,
11011134 annotations = annotations ,
11021135 frontend = build_parameters .frontend_variant ,
11031136 git_repository_revision = git_repository_revision ,
11041137 context_dir = context_dir ,
11051138 )
11061139
1140+ platform = models .Platform .linux_amd64
1141+ if build_parameters .platforms :
1142+ platform = build_parameters .platforms [0 ]
1143+ overrides = None
1144+ if self .builds_config .build_platform_overrides :
1145+ overrides = self .builds_config .build_platform_overrides .get (platform .value )
1146+ params = params .with_overrides (overrides = overrides )
1147+
1148+ return params
1149+
11071150 async def _get_environment_authorization (
11081151 self , session : AsyncSession , user : base_models .APIUser , environment : schemas .EnvironmentORM , scope : Scope
11091152 ) -> bool :
0 commit comments