(
service: &mut dyn Service,
option: &DeploymentOption,
cr_registry: &dyn InteractWithRegistry,
build_platform: &dyn BuildPlatform,
image_retention_time_sec: u3
| 202 | } |
| 203 | |
| 204 | fn build_and_push_service( |
| 205 | service: &mut dyn Service, |
| 206 | option: &DeploymentOption, |
| 207 | cr_registry: &dyn InteractWithRegistry, |
| 208 | build_platform: &dyn BuildPlatform, |
| 209 | image_retention_time_sec: u32, |
| 210 | registry_tags: RegistryTags, |
| 211 | cr_to_engine_error: impl Fn(ContainerRegistryError) -> EngineError, |
| 212 | mk_logger: impl Fn(&dyn Service) -> EnvLogger, |
| 213 | metrics_registry: Arc<dyn MetricsRegistry>, |
| 214 | abort: &dyn Abort, |
| 215 | ) -> Result<(), Box<EngineError>> { |
| 216 | let logger = mk_logger(service); |
| 217 | let build = match service.build_mut() { |
| 218 | Some(build) => build, |
| 219 | None => return Ok(()), // this case should not happen as we filter on buildable services |
| 220 | }; |
| 221 | |
| 222 | // If image already exists in the registry, skip the build |
| 223 | if !option.force_build && cr_registry.image_exists(&build.image) { |
| 224 | let image_name = build.image.full_image_name_with_tag(); |
| 225 | let msg = format!("✅ Container image {image_name} already exists and ready to use"); |
| 226 | logger.send_success(msg); |
| 227 | return Ok(()); |
| 228 | } |
| 229 | |
| 230 | // Be sure that our repository exist before trying to pull/push images from it |
| 231 | logger.send_progress(format!( |
| 232 | "🗂️ Provisioning container repository {}/{}", |
| 233 | build.image.registry_name.as_str(), |
| 234 | build.image.repository_name() |
| 235 | )); |
| 236 | let provision_registry_record = metrics_registry.start_record( |
| 237 | build.image.service_long_id, |
| 238 | StepLabel::Service, |
| 239 | StepName::RegistryCreateRepository, |
| 240 | ); |
| 241 | |
| 242 | match cr_registry.create_repository( |
| 243 | Some(build.image.registry_name.as_str()), |
| 244 | build.image.repository_name(), |
| 245 | image_retention_time_sec, |
| 246 | registry_tags, |
| 247 | ) { |
| 248 | Err(err) => { |
| 249 | provision_registry_record.stop(StepStatus::Error); |
| 250 | return Err(Box::new(cr_to_engine_error(err))); |
| 251 | } |
| 252 | Ok((_repository, repository_info)) => provision_registry_record.stop(if repository_info.created { |
| 253 | StepStatus::Success |
| 254 | } else { |
| 255 | StepStatus::Skip |
| 256 | }), |
| 257 | } |
| 258 | |
| 259 | // Ok now everything is setup, we can try to build the app |
| 260 | let build_result = build_platform.build(build, &logger, metrics_registry.clone(), abort); |
| 261 | let image_name = build.image.full_image_name_with_tag(); // .build() may have modified the image tag |
nothing calls this directly
no test coverage detected