17 lines
568 B
TypeScript
17 lines
568 B
TypeScript
import { stringify } from "yaml";
|
|
import type { ServiceMetadata } from "./types.ts";
|
|
|
|
/** Build the docker-compose.yml content for a service from its metadata. */
|
|
export function generateComposeFile(meta: ServiceMetadata): string {
|
|
const doc: Record<string, unknown> = {};
|
|
|
|
if (meta.networks && Object.keys(meta.networks).length > 0) {
|
|
doc.networks = meta.networks;
|
|
}
|
|
if (meta.volumes && Object.keys(meta.volumes).length > 0) {
|
|
doc.volumes = meta.volumes;
|
|
}
|
|
doc.services = { [meta.id]: meta.compose };
|
|
|
|
return stringify(doc, { lineWidth: 0 });
|
|
}
|