in src/main/java/com/epam/aidial/service/ConfigService.java [90:141]
public V1Job buildJobConfig(String name, String sources, String runtime) {
String targetImage = registryService.fullImageName(name);
log.info("Target image: {}", targetImage);
AppConfiguration.RuntimeConfiguration runtimeConfig = this.appconfig.getRuntimes().get(runtime);
if (runtimeConfig == null) {
throw new IllegalArgumentException(
"Unsupported runtime: %s. Supported: %s".formatted(runtime, this.appconfig.getRuntimes().keySet()));
}
MappingChain<V1Job> config = new MappingChain<>(this.appconfig.cloneJobConfig());
config.get(JOB_METADATA_FIELD)
.data()
.setName(buildJobName(name));
MappingChain<V1PodSpec> podSpec = config.get(JOB_SPEC_FIELD)
.get(JOB_TEMPLATE_FIELD)
.get(JOB_TEMPLATE_SPEC_FIELD);
MappingChain<V1Container> template = podSpec.getList(POD_INIT_CONTAINERS_FIELD, CONTAINER_NAME)
.getOrDefault(appconfig.getTemplateContainer().getName(), appconfig::cloneTemplateContainer);
ListMapper<V1EnvVar> pullerEnvs = template.getList(CONTAINER_ENV_FIELD, ENV_VAR_NAME);
pullerEnvs.get("SOURCES")
.data()
.setValue(sources);
pullerEnvs.get("PROFILE")
.data()
.setValue(runtimeConfig.getProfile());
String secretName = dialAuthSecretName(name);
template.get(CONTAINER_ENV_FROM_FIELD)
.data()
.add(new V1EnvFromSource().secretRef(new V1SecretEnvSource().name(secretName)));
MappingChain<V1Container> builder = podSpec.getList(POD_CONTAINERS_FIELD, CONTAINER_NAME)
.getOrDefault(appconfig.getBuilderContainer().getName(), appconfig::cloneBuilderContainer);
builder.get(CONTAINER_ARGS_FIELD)
.data()
.addAll(List.of(
"--destination=%s".formatted(targetImage),
"--build-arg=BASE_IMAGE=%s".formatted(runtimeConfig.getImage())));
if (registryService.getAuthScheme() == DockerAuthScheme.BASIC) {
String volumeName = "secret-volume";
podSpec.getList(POD_VOLUMES_FIELD, VOLUME_NAME)
.get(volumeName)
.data()
.setSecret(new V1SecretVolumeSource().secretName(secretName));
V1VolumeMount volumeMount = builder.getList(CONTAINER_VOLUME_MOUNTS_FIELD, VOLUME_MOUNT_PATH)
.get(dockerConfigPath)
.data();
volumeMount.setName(volumeName);
volumeMount.setSubPath(DOCKER_CONFIG_KEY);
}
return config.data();
}