diff --git a/packages/api/src/routers/resources/create.ts b/packages/api/src/routers/resources/create.ts index 095c83d..b918b74 100644 --- a/packages/api/src/routers/resources/create.ts +++ b/packages/api/src/routers/resources/create.ts @@ -180,8 +180,8 @@ export const resourceCreateRouter = { }, ); - // Every template starts out in its own group, drawn with its companions on the canvas. - const groupId = template ? randomUUID() : null; + // A template with companions starts out in its own group, drawn around them on the canvas. + const groupId = companions.length ? randomUUID() : null; const created = await db.transaction(async (tx) => { if (groupId) diff --git a/packages/workflows/src/compose.ts b/packages/workflows/src/compose.ts index 34f11c1..b03a219 100644 --- a/packages/workflows/src/compose.ts +++ b/packages/workflows/src/compose.ts @@ -50,7 +50,8 @@ export const internalHostname = (name: string, prefix?: string): string => `${prefixName(name, prefix)}.internal`; const isNamedVolumeSource = (source: string): boolean => { - if (source === "") { + // A `${VAR}` source is unknown until interpolated; deploys interpolate before formatting. + if (source === "" || source.includes("$")) { return false; } diff --git a/tests/api/compose.test.ts b/tests/api/compose.test.ts index c8926bb..633872e 100644 --- a/tests/api/compose.test.ts +++ b/tests/api/compose.test.ts @@ -107,6 +107,10 @@ describe("formatComposeFile", () => { source: /host/config target: /etc/config - /anonymous + - \${MEDIA_PATH}:/media + - type: volume + source: \${LOGS_VOLUME} + target: /logs volumes: postgres_data: logs: @@ -121,6 +125,8 @@ volumes: expect(formatted.yaml).toMatch(/^ {2}a1b2c3d4-e5f6a7b8-logs:/mu); expect(formatted.yaml).toContain("source: /host/config"); expect(formatted.yaml).toContain("- /anonymous"); + expect(formatted.yaml).toContain("- ${MEDIA_PATH}:/media"); + expect(formatted.yaml).toContain("source: ${LOGS_VOLUME}"); expect(formatted.yaml).not.toMatch(/^\s+- postgres_data:/mu); expect(formatted.yaml).not.toMatch(/^ {2}postgres_data:/mu); }); diff --git a/tests/api/template-create.test.ts b/tests/api/template-create.test.ts index 42507c4..60883ee 100644 --- a/tests/api/template-create.test.ts +++ b/tests/api/template-create.test.ts @@ -86,19 +86,26 @@ describe("creating every template (PostgreSQL)", () => { { context }, ); - const [group] = await db - .select() - .from(resourceGroups) - .where(eq(resourceGroups.id, app!.groupId!)); - - expect(group).toMatchObject({ projectId, name: `${appId} ${version}` }); - - const created = await db - .select() - .from(resources) - .where(eq(resources.groupId, app!.groupId!)); - - expect(created).toHaveLength(1 + Object.keys(files.companions).length); + const companionCount = Object.keys(files.companions).length; + let created = [app!]; + + // Only a template with companions gets a group; a lone resource stays ungrouped. + if (companionCount === 0) expect(app!.groupId).toBeNull(); + else { + const [group] = await db + .select() + .from(resourceGroups) + .where(eq(resourceGroups.id, app!.groupId!)); + + expect(group).toMatchObject({ projectId, name: `${appId} ${version}` }); + + created = await db + .select() + .from(resources) + .where(eq(resources.groupId, app!.groupId!)); + + expect(created).toHaveLength(1 + companionCount); + } const empty = await Promise.all( created.map(async (resource) => {