Skip to content
Open
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
16 changes: 8 additions & 8 deletions apps/dokploy/__test__/server/mechanizeDockerContainer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const { inspectMock, getServiceMock, createServiceMock, getRemoteDockerMock } =
const inspect = vi.fn<() => Promise<never>>();
const getService = vi.fn(() => ({ inspect }));
const createService = vi.fn<
(opts: MockCreateServiceOptions) => Promise<void>
(authconfig: unknown, opts: MockCreateServiceOptions) => Promise<void>
>(async () => undefined);
const getRemoteDocker = vi.fn(async () => ({
getService,
Expand Down Expand Up @@ -83,12 +83,12 @@ describe("mechanizeDockerContainer", () => {

expect(createServiceMock).toHaveBeenCalledTimes(1);
const call = createServiceMock.mock.calls[0] as
| [MockCreateServiceOptions]
| [unknown, MockCreateServiceOptions]
| undefined;
if (!call) {
throw new Error("createServiceMock should have been called once");
}
const [settings] = call;
const [, settings] = call;
expect(settings.TaskTemplate?.ContainerSpec?.StopGracePeriod).toBe(0);
expect(typeof settings.TaskTemplate?.ContainerSpec?.StopGracePeriod).toBe(
"number",
Expand All @@ -102,12 +102,12 @@ describe("mechanizeDockerContainer", () => {

expect(createServiceMock).toHaveBeenCalledTimes(1);
const call = createServiceMock.mock.calls[0] as
| [MockCreateServiceOptions]
| [unknown, MockCreateServiceOptions]
| undefined;
if (!call) {
throw new Error("createServiceMock should have been called once");
}
const [settings] = call;
const [, settings] = call;
expect(settings.TaskTemplate?.ContainerSpec).not.toHaveProperty(
"StopGracePeriod",
);
Expand All @@ -127,7 +127,7 @@ describe("mechanizeDockerContainer", () => {
if (!call) {
throw new Error("createServiceMock should have been called once");
}
const [settings] = call;
const [, settings] = call;
expect(settings.TaskTemplate?.ContainerSpec?.Ulimits).toEqual(ulimits);
});

Expand All @@ -141,7 +141,7 @@ describe("mechanizeDockerContainer", () => {
if (!call) {
throw new Error("createServiceMock should have been called once");
}
const [settings] = call;
const [, settings] = call;
expect(settings.TaskTemplate?.ContainerSpec).not.toHaveProperty("Ulimits");
});

Expand All @@ -155,7 +155,7 @@ describe("mechanizeDockerContainer", () => {
if (!call) {
throw new Error("createServiceMock should have been called once");
}
const [settings] = call;
const [, settings] = call;
expect(settings.TaskTemplate?.ContainerSpec).not.toHaveProperty("Ulimits");
});
});
15 changes: 10 additions & 5 deletions packages/server/src/services/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,10 +419,13 @@ export const deployPreviewApplication = async ({
application.buildArgs = `${application.previewBuildArgs}\nDOKPLOY_DEPLOY_URL=${previewDeployment?.domain?.host}`;
application.buildSecrets = `${application.previewBuildSecrets}\nDOKPLOY_DEPLOY_URL=${previewDeployment?.domain?.host}`;
application.rollbackActive = false;
application.buildRegistry = null;
if (!application.buildServerId || application.buildServerId === application.serverId) {
application.buildRegistry = null;
}
application.rollbackRegistry = null;
application.registry = null;

const buildServerId = application.buildServerId || application.serverId;
let command = "set -e;";
if (application.sourceType === "github") {
command += await cloneGithubRepository({
Expand All @@ -433,8 +436,8 @@ export const deployPreviewApplication = async ({
command += await getBuildCommand(application);

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 @@ -538,11 +541,13 @@ export const rebuildPreviewApplication = async ({
application.buildArgs = `${application.previewBuildArgs}\nDOKPLOY_DEPLOY_URL=${previewDeployment?.domain?.host}`;
application.buildSecrets = `${application.previewBuildSecrets}\nDOKPLOY_DEPLOY_URL=${previewDeployment?.domain?.host}`;
application.rollbackActive = false;
application.buildRegistry = null;
if (!application.buildServerId || application.buildServerId === application.serverId) {
application.buildRegistry = null;
}
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
11 changes: 5 additions & 6 deletions packages/server/src/services/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,22 +162,21 @@ export const createDeploymentPreview = async (
deployment.previewDeploymentId,
);
try {
const buildServerId = previewDeployment?.application?.buildServerId || previewDeployment?.application?.serverId;
await removeLastTenDeployments(
deployment.previewDeploymentId,
"previewDeployment",
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 Down
2 changes: 1 addition & 1 deletion packages/server/src/utils/builders/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export const mechanizeDockerContainer = async (
});
} catch (error) {
console.log(error);
await docker.createService(settings);
await docker.createService(settings.authconfig, settings);
}
};

Expand Down