Skip to content

Commit 2e702dc

Browse files
authored
Merge pull request #2952 from spacewaterbear/add_env_in_notifications
feat: display environnement in notification
2 parents 6413fa5 + 766f924 commit 2e702dc

File tree

4 files changed

+52
-2
lines changed

4 files changed

+52
-2
lines changed

packages/server/src/emails/emails/build-success.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export type TemplateProps = {
1919
applicationType: string;
2020
buildLink: string;
2121
date: string;
22+
environmentName: string;
2223
};
2324

2425
export const BuildSuccessEmail = ({
@@ -27,6 +28,7 @@ export const BuildSuccessEmail = ({
2728
applicationType = "application",
2829
buildLink = "https://dokploy.com/projects/dokploy-test/applications/dokploy-test",
2930
date = "2023-05-01T00:00:00.000Z",
31+
environmentName = "production",
3032
}: TemplateProps) => {
3133
const previewText = `Build success for ${applicationName}`;
3234
return (
@@ -74,6 +76,9 @@ export const BuildSuccessEmail = ({
7476
<Text className="!leading-3">
7577
Application Name: <strong>{applicationName}</strong>
7678
</Text>
79+
<Text className="!leading-3">
80+
Environment: <strong>{environmentName}</strong>
81+
</Text>
7782
<Text className="!leading-3">
7883
Application Type: <strong>{applicationType}</strong>
7984
</Text>

packages/server/src/services/application.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ export const deployApplication = async ({
225225
buildLink,
226226
organizationId: application.environment.project.organizationId,
227227
domains: application.domains,
228+
environmentName: application.environment.name,
228229
});
229230
} catch (error) {
230231
const command = `echo "Error occurred ❌, check the logs for details." >> ${deployment.logPath};`;
@@ -273,6 +274,7 @@ export const rebuildApplication = async ({
273274
descriptionLog: string;
274275
}) => {
275276
const application = await findApplicationById(applicationId);
277+
const buildLink = `${await getDokployUrl()}/dashboard/project/${application.environment.projectId}/environment/${application.environmentId}/services/application/${application.applicationId}?tab=deployments`;
276278

277279
const deployment = await createDeployment({
278280
applicationId: applicationId,
@@ -293,6 +295,27 @@ export const rebuildApplication = async ({
293295
await mechanizeDockerContainer(application);
294296
await updateDeploymentStatus(deployment.deploymentId, "done");
295297
await updateApplicationStatus(applicationId, "done");
298+
299+
if (application.rollbackActive) {
300+
const tagImage =
301+
application.sourceType === "docker"
302+
? application.dockerImage
303+
: application.appName;
304+
await createRollback({
305+
appName: tagImage || "",
306+
deploymentId: deployment.deploymentId,
307+
});
308+
}
309+
310+
await sendBuildSuccessNotifications({
311+
projectName: application.environment.project.name,
312+
applicationName: application.name,
313+
applicationType: "application",
314+
buildLink,
315+
organizationId: application.environment.project.organizationId,
316+
domains: application.domains,
317+
environmentName: application.environment.name,
318+
});
296319
} catch (error) {
297320
await updateDeploymentStatus(deployment.deploymentId, "error");
298321
await updateApplicationStatus(applicationId, "error");

packages/server/src/services/compose.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ export const deployCompose = async ({
267267
buildLink,
268268
organizationId: compose.environment.project.organizationId,
269269
domains: compose.domains,
270+
environmentName: compose.environment.name,
270271
});
271272
} catch (error) {
272273
await updateDeploymentStatus(deployment.deploymentId, "error");

packages/server/src/utils/notifications/build-success.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ interface Props {
2222
buildLink: string;
2323
organizationId: string;
2424
domains: Domain[];
25+
environmentName: string;
2526
}
2627

2728
export const sendBuildSuccessNotifications = async ({
@@ -31,6 +32,7 @@ export const sendBuildSuccessNotifications = async ({
3132
buildLink,
3233
organizationId,
3334
domains,
35+
environmentName,
3436
}: Props) => {
3537
const date = new Date();
3638
const unixDate = ~~(Number(date) / 1000);
@@ -62,6 +64,7 @@ export const sendBuildSuccessNotifications = async ({
6264
applicationType,
6365
buildLink,
6466
date: date.toLocaleString(),
67+
environmentName,
6568
}),
6669
).catch();
6770
await sendEmailNotification(email, "Build success for dokploy", template);
@@ -72,7 +75,7 @@ export const sendBuildSuccessNotifications = async ({
7275
`${discord.decoration ? decoration : ""} ${text}`.trim();
7376

7477
await sendDiscordNotification(discord, {
75-
title: decorate(">", "`✅` Build Success"),
78+
title: decorate(">", "`✅` Build Successes"),
7679
color: 0x57f287,
7780
fields: [
7881
{
@@ -85,6 +88,11 @@ export const sendBuildSuccessNotifications = async ({
8588
value: applicationName,
8689
inline: true,
8790
},
91+
{
92+
name: decorate("`🌍`", "Environment"),
93+
value: environmentName,
94+
inline: true,
95+
},
8896
{
8997
name: decorate("`❔`", "Type"),
9098
value: applicationType,
@@ -125,6 +133,7 @@ export const sendBuildSuccessNotifications = async ({
125133
decorate("✅", "Build Success"),
126134
`${decorate("🛠️", `Project: ${projectName}`)}` +
127135
`${decorate("⚙️", `Application: ${applicationName}`)}` +
136+
`${decorate("🌍", `Environment: ${environmentName}`)}` +
128137
`${decorate("❔", `Type: ${applicationType}`)}` +
129138
`${decorate("🕒", `Date: ${date.toLocaleString()}`)}` +
130139
`${decorate("🔗", `Build details:\n${buildLink}`)}`,
@@ -139,6 +148,7 @@ export const sendBuildSuccessNotifications = async ({
139148
`view, Build details, ${buildLink}, clear=true;`,
140149
`🛠Project: ${projectName}\n` +
141150
`⚙️Application: ${applicationName}\n` +
151+
`🌍Environment: ${environmentName}\n` +
142152
`❔Type: ${applicationType}\n` +
143153
`🕒Date: ${date.toLocaleString()}`,
144154
);
@@ -167,7 +177,7 @@ export const sendBuildSuccessNotifications = async ({
167177

168178
await sendTelegramNotification(
169179
telegram,
170-
`<b>✅ Build Success</b>\n\n<b>Project:</b> ${projectName}\n<b>Application:</b> ${applicationName}\n<b>Type:</b> ${applicationType}\n<b>Date:</b> ${format(date, "PP")}\n<b>Time:</b> ${format(date, "pp")}`,
180+
`<b>✅ Build Success</b>\n\n<b>Project:</b> ${projectName}\n<b>Application:</b> ${applicationName}\n<b>Environment:</b> ${environmentName}\n<b>Type:</b> ${applicationType}\n<b>Date:</b> ${format(date, "PP")}\n<b>Time:</b> ${format(date, "pp")}`,
171181
inlineButton,
172182
);
173183
}
@@ -191,6 +201,11 @@ export const sendBuildSuccessNotifications = async ({
191201
value: applicationName,
192202
short: true,
193203
},
204+
{
205+
title: "Environment",
206+
value: environmentName,
207+
short: true,
208+
},
194209
{
195210
title: "Type",
196211
value: applicationType,
@@ -260,6 +275,12 @@ export const sendBuildSuccessNotifications = async ({
260275
text_align: "left",
261276
text_size: "normal_v2",
262277
},
278+
{
279+
tag: "markdown",
280+
content: `**Environment:**\n${environmentName}`,
281+
text_align: "left",
282+
text_size: "normal_v2",
283+
},
263284
{
264285
tag: "markdown",
265286
content: `**Type:**\n${applicationType}`,

0 commit comments

Comments
 (0)