@@ -138,7 +138,11 @@ def __copy_environment(
138138 if environment .environment_image_source == models .EnvironmentImageSource .build :
139139 if not environment .build_parameters :
140140 raise errors .ProgrammingError (message = "Environment has no build parameters." )
141+ platforms = [
142+ schemas .BuildPlatformORM (platform = platform ) for platform in environment .build_parameters .platforms
143+ ]
141144 new_build_parameters = schemas .BuildParametersORM (
145+ platforms = platforms ,
142146 builder_variant = environment .build_parameters .builder_variant ,
143147 frontend_variant = environment .build_parameters .frontend_variant ,
144148 repository = environment .build_parameters .repository ,
@@ -164,7 +168,11 @@ def __insert_build_parameters_environment(
164168 raise errors .UnauthorizedError (
165169 message = "You have to be authenticated to insert an environment in the DB." , quiet = True
166170 )
171+ platforms = [
172+ schemas .BuildPlatformORM (platform = platform ) for platform in new_build_parameters_environment .platforms
173+ ]
167174 build_parameters_orm = schemas .BuildParametersORM (
175+ platforms = platforms ,
168176 builder_variant = new_build_parameters_environment .builder_variant ,
169177 frontend_variant = new_build_parameters_environment .frontend_variant ,
170178 repository = new_build_parameters_environment .repository ,
@@ -265,6 +273,10 @@ async def __update_environment_build_parameters(
265273
266274 if build_parameters .repository is not None :
267275 environment .build_parameters .repository = build_parameters .repository
276+ if build_parameters .platforms is not None :
277+ environment .build_parameters .platforms = [
278+ schemas .BuildPlatformORM (platform = platform ) for platform in build_parameters .platforms
279+ ]
268280 if build_parameters .builder_variant is not None :
269281 environment .build_parameters .builder_variant = build_parameters .builder_variant
270282 if build_parameters .frontend_variant is not None :
@@ -418,7 +430,9 @@ async def insert_launcher(
418430 )
419431 session .add (environment_orm )
420432 elif isinstance (launcher .environment , models .UnsavedBuildParameters ):
433+ platforms = [schemas .BuildPlatformORM (platform = platform ) for platform in launcher .environment .platforms ]
421434 build_parameters_orm = schemas .BuildParametersORM (
435+ platforms = platforms ,
422436 builder_variant = launcher .environment .builder_variant ,
423437 frontend_variant = launcher .environment .frontend_variant ,
424438 repository = launcher .environment .repository ,
@@ -718,7 +732,11 @@ async def __update_launcher_environment(
718732 await session .flush ()
719733 case models .UnsavedBuildParameters () as new_custom_built_environment , models .EnvironmentKind .CUSTOM :
720734 # Custom environment with image is replaced by a custom environment with build
735+ platforms = [
736+ schemas .BuildPlatformORM (platform = platform ) for platform in new_custom_built_environment .platforms
737+ ]
721738 build_parameters_orm = schemas .BuildParametersORM (
739+ platforms = platforms ,
722740 builder_variant = new_custom_built_environment .builder_variant ,
723741 frontend_variant = new_custom_built_environment .frontend_variant ,
724742 repository = new_custom_built_environment .repository ,
@@ -884,6 +902,15 @@ async def start_build(self, user: base_models.APIUser, build: models.UnsavedBuil
884902 message = f"Session environment with id '{ build .environment_id } ' already has a build in progress."
885903 )
886904
905+ # We check that we build for a single target platform
906+ if len (build_parameters .platforms ) > 1 :
907+ raise errors .CannotStartBuildError (
908+ message = (
909+ f"Building images can target only one platform at a time. "
910+ f"Current value: { build_parameters .platforms } "
911+ )
912+ )
913+
887914 build_orm = schemas .BuildORM (
888915 environment_id = build .environment_id ,
889916 status = models .BuildStatus .in_progress ,
@@ -1052,6 +1079,9 @@ def _get_buildrun_params(
10521079 git_repository_revision = build_parameters .repository_revision
10531080 context_dir = build_parameters .context_dir
10541081
1082+ builder_image = self .builds_config .build_builder_image or constants .BUILD_DEFAULT_BUILDER_IMAGE
1083+ run_image = self .builds_config .build_run_image or constants .BUILD_DEFAULT_RUN_IMAGE
1084+
10551085 output_image_prefix = (
10561086 self .builds_config .build_output_image_prefix or constants .BUILD_DEFAULT_OUTPUT_IMAGE_PREFIX
10571087 )
@@ -1063,6 +1093,9 @@ def _get_buildrun_params(
10631093 build_strategy_name = self .builds_config .build_strategy_name or constants .BUILD_DEFAULT_BUILD_STRATEGY_NAME
10641094 push_secret_name = self .builds_config .push_secret_name or constants .BUILD_DEFAULT_PUSH_SECRET_NAME
10651095
1096+ node_selector = self .builds_config .node_selector
1097+ tolerations = self .builds_config .tolerations
1098+
10661099 retention_after_failed = (
10671100 self .builds_config .buildrun_retention_after_failed or constants .BUILD_RUN_DEFAULT_RETENTION_AFTER_FAILED
10681101 )
@@ -1083,26 +1116,36 @@ def _get_buildrun_params(
10831116 annotations ["renku.io/launcher_id" ] = str (launcher .id )
10841117 annotations ["renku.io/project_id" ] = str (launcher .project_id )
10851118
1086- return models .ShipwrightBuildRunParams (
1119+ params = models .ShipwrightBuildRunParams (
10871120 name = build .k8s_name ,
10881121 git_repository = git_repository ,
1089- build_image = self . builds_config . build_builder_image or constants . BUILD_DEFAULT_BUILDER_IMAGE ,
1090- run_image = self . builds_config . build_run_image or constants . BUILD_DEFAULT_RUN_IMAGE ,
1122+ builder_image = builder_image ,
1123+ run_image = run_image ,
10911124 output_image = output_image ,
10921125 build_strategy_name = build_strategy_name ,
10931126 push_secret_name = push_secret_name ,
10941127 retention_after_failed = retention_after_failed ,
10951128 retention_after_succeeded = retention_after_succeeded ,
10961129 build_timeout = build_timeout ,
1097- node_selector = self . builds_config . node_selector ,
1098- tolerations = self . builds_config . tolerations ,
1130+ node_selector = node_selector ,
1131+ tolerations = tolerations ,
10991132 labels = labels ,
11001133 annotations = annotations ,
11011134 frontend = build_parameters .frontend_variant ,
11021135 git_repository_revision = git_repository_revision ,
11031136 context_dir = context_dir ,
11041137 )
11051138
1139+ platform = models .Platform .linux_amd64
1140+ if build_parameters .platforms :
1141+ platform = build_parameters .platforms [0 ]
1142+ overrides = None
1143+ if self .builds_config .build_platform_overrides :
1144+ overrides = self .builds_config .build_platform_overrides .get (platform .value )
1145+ params = params .with_overrides (overrides = overrides )
1146+
1147+ return params
1148+
11061149 async def _get_environment_authorization (
11071150 self , session : AsyncSession , user : base_models .APIUser , environment : schemas .EnvironmentORM , scope : Scope
11081151 ) -> bool :
0 commit comments