MCPcopy
hub / github.com/Dokploy/dokploy / createDeployment

Function createDeployment

packages/server/src/services/deployment.ts:113–192  ·  view source on GitHub ↗
(
	deployment: Omit<
		z.infer<typeof apiCreateDeployment>,
		"deploymentId" | "createdAt" | "status" | "logPath"
	>,
)

Source from the content-addressed store, hash-verified

111};
112
113export const createDeployment = async (
114 deployment: Omit<
115 z.infer<typeof apiCreateDeployment>,
116 "deploymentId" | "createdAt" | "status" | "logPath"
117 >,
118) => {
119 const application = await findApplicationById(deployment.applicationId);
120 await removeLastTenDeployments(
121 deployment.applicationId,
122 "application",
123 application.serverId,
124 );
125 try {
126 const serverId = application.buildServerId || application.serverId;
127
128 const { LOGS_PATH } = paths(!!serverId);
129 const formattedDateTime = format(new Date(), "yyyy-MM-dd:HH:mm:ss");
130 const fileName = `${application.appName}-${formattedDateTime}.log`;
131 const logFilePath = path.join(LOGS_PATH, application.appName, fileName);
132
133 if (serverId) {
134 const server = await findServerById(serverId);
135
136 const command = `
137 mkdir -p ${LOGS_PATH}/${application.appName};
138 echo "Initializing deployment" >> ${logFilePath};
139 echo "Building on ${serverId ? "Build Server" : "Dokploy Server"}" >> ${logFilePath};
140 `;
141
142 await execAsyncRemote(server.serverId, command);
143 } else {
144 await fsPromises.mkdir(path.join(LOGS_PATH, application.appName), {
145 recursive: true,
146 });
147 await fsPromises.writeFile(logFilePath, "Initializing deployment\n");
148 }
149
150 const deploymentCreate = await db
151 .insert(deployments)
152 .values({
153 applicationId: deployment.applicationId,
154 title: deployment.title || "Deployment",
155 status: "running",
156 logPath: logFilePath,
157 description: deployment.description || "",
158 startedAt: new Date().toISOString(),
159 ...(application.buildServerId && {
160 buildServerId: application.buildServerId,
161 }),
162 })
163 .returning();
164 if (deploymentCreate.length === 0 || !deploymentCreate[0]) {
165 throw new TRPCError({
166 code: "BAD_REQUEST",
167 message: "Error creating the deployment",
168 });
169 }
170 return deploymentCreate[0];

Callers 2

deployApplicationFunction · 0.90
rebuildApplicationFunction · 0.90

Calls 6

findApplicationByIdFunction · 0.90
pathsFunction · 0.90
findServerByIdFunction · 0.90
execAsyncRemoteFunction · 0.90
updateApplicationStatusFunction · 0.90
removeLastTenDeploymentsFunction · 0.85

Tested by

no test coverage detected