({
applicationId,
titleLog = "Manual deployment",
descriptionLog = "",
}: {
applicationId: string;
titleLog: string;
descriptionLog: string;
})
| 162 | }; |
| 163 | |
| 164 | export const deployApplication = async ({ |
| 165 | applicationId, |
| 166 | titleLog = "Manual deployment", |
| 167 | descriptionLog = "", |
| 168 | }: { |
| 169 | applicationId: string; |
| 170 | titleLog: string; |
| 171 | descriptionLog: string; |
| 172 | }) => { |
| 173 | const application = await findApplicationById(applicationId); |
| 174 | const serverId = application.buildServerId || application.serverId; |
| 175 | const applicationEntity = { |
| 176 | ...application, |
| 177 | serverId: serverId, |
| 178 | }; |
| 179 | |
| 180 | const buildLink = `${await getDokployUrl()}/dashboard/project/${application.environment.projectId}/environment/${application.environmentId}/services/application/${application.applicationId}?tab=deployments`; |
| 181 | const deployment = await createDeployment({ |
| 182 | applicationId: applicationId, |
| 183 | title: titleLog, |
| 184 | description: descriptionLog, |
| 185 | }); |
| 186 | |
| 187 | try { |
| 188 | let command = "set -e;"; |
| 189 | if (application.sourceType === "github") { |
| 190 | command += await cloneGithubRepository(applicationEntity); |
| 191 | } else if (application.sourceType === "gitlab") { |
| 192 | command += await cloneGitlabRepository(applicationEntity); |
| 193 | } else if (application.sourceType === "gitea") { |
| 194 | command += await cloneGiteaRepository(applicationEntity); |
| 195 | } else if (application.sourceType === "bitbucket") { |
| 196 | command += await cloneBitbucketRepository(applicationEntity); |
| 197 | } else if (application.sourceType === "git") { |
| 198 | command += await cloneGitRepository(applicationEntity); |
| 199 | } else if (application.sourceType === "docker") { |
| 200 | command += await buildRemoteDocker(application); |
| 201 | } |
| 202 | |
| 203 | if (application.sourceType !== "docker") { |
| 204 | command += await generateApplyPatchesCommand({ |
| 205 | id: application.applicationId, |
| 206 | type: "application", |
| 207 | serverId, |
| 208 | }); |
| 209 | } |
| 210 | |
| 211 | command += await getBuildCommand(application); |
| 212 | |
| 213 | const commandWithLog = `(${command}) >> ${deployment.logPath} 2>&1`; |
| 214 | if (serverId) { |
| 215 | await execAsyncRemote(serverId, commandWithLog); |
| 216 | } else { |
| 217 | await execAsync(commandWithLog); |
| 218 | } |
| 219 | |
| 220 | await mechanizeDockerContainer(application); |
| 221 | await updateDeploymentStatus(deployment.deploymentId, "done"); |
no test coverage detected