Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/api/src/routers/resources/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion packages/workflows/src/compose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 6 additions & 0 deletions tests/api/compose.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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);
});
Expand Down
33 changes: 20 additions & 13 deletions tests/api/template-create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
Loading