Skip to content
Closed
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
8 changes: 5 additions & 3 deletions packages/server/src/services/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,11 @@ export const deployPreviewApplication = async ({
});
command += await getBuildCommand(application);

const buildServerId =
application.buildServerId || application.serverId;
const commandWithLog = `(${command}) >> ${deployment.logPath} 2>&1`;
if (application.serverId) {
await execAsyncRemote(application.serverId, commandWithLog);
if (buildServerId) {
await execAsyncRemote(buildServerId, commandWithLog);
} else {
await execAsync(commandWithLog);
}
Expand Down Expand Up @@ -541,7 +543,7 @@ export const rebuildPreviewApplication = async ({
application.rollbackRegistry = null;
application.registry = null;

const serverId = application.serverId;
const serverId = application.buildServerId || application.serverId;
let command = "set -e;";
// Only rebuild, don't clone repository
command += await getBuildCommand(application);
Expand Down
16 changes: 11 additions & 5 deletions packages/server/src/services/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,22 +161,24 @@ export const createDeploymentPreview = async (
deployment.previewDeploymentId,
);
try {
const buildServerId =
previewDeployment?.application?.buildServerId ||
previewDeployment?.application?.serverId;

await removeLastTenDeployments(
deployment.previewDeploymentId,
"previewDeployment",
previewDeployment?.application?.serverId,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should use buildServerId instead of serverId for consistency

old logs will be cleaned up from the wrong server if buildServerId is different from serverId

Suggested change
previewDeployment?.application?.serverId,
buildServerId,

);

const appName = `${previewDeployment.appName}`;
const { LOGS_PATH } = paths(!!previewDeployment?.application?.serverId);
const { LOGS_PATH } = paths(!!buildServerId);
const formattedDateTime = format(new Date(), "yyyy-MM-dd:HH:mm:ss");
const fileName = `${appName}-${formattedDateTime}.log`;
const logFilePath = path.join(LOGS_PATH, appName, fileName);

if (previewDeployment?.application?.serverId) {
const server = await findServerById(
previewDeployment?.application?.serverId,
);
if (buildServerId) {
const server = await findServerById(buildServerId);

const command = `
mkdir -p ${LOGS_PATH}/${appName};
Expand All @@ -200,6 +202,10 @@ export const createDeploymentPreview = async (
description: deployment.description || "",
previewDeploymentId: deployment.previewDeploymentId,
startedAt: new Date().toISOString(),
...(previewDeployment?.application?.buildServerId && {
buildServerId:
previewDeployment.application.buildServerId,
}),
})
.returning();
if (deploymentCreate.length === 0 || !deploymentCreate[0]) {
Expand Down