toContainerSpec method

ContainerSpec? toContainerSpec({
  1. required Map<String, String> values,
})

Implementation

ContainerSpec? toContainerSpec({required Map<String, String> values}) {
  // Build env map with {var} expansion.
  final env = <EnvironmentVariable>[];
  if (environment != null) {
    for (final e in environment!) {
      env.add(EnvironmentVariable(name: e.name, value: e.value.formatWith(values)));
    }
  }

  // Image is required on ServiceSpec; enforce like Pydantic would.
  final img = image;
  if (img == null || img.isEmpty) {
    throw ArgumentError('ServiceTemplateSpec.image is required to build a ServiceSpec');
  }
  return ContainerSpec(
    command: command,
    image: img,
    environment: env,
    storage:
        storage == null
            ? null
            : ServiceStorageMountsSpec(
              room: storage!.room,
              // If you later add `project` to ServiceTemplateMountSpec, map it here:
              // project: storage!.project,
            ),
  );
}