@@ -54,95 +54,106 @@ import { eq } from "drizzle-orm";
54
54
import { encodeBase64 } from "../utils/docker/utils" ;
55
55
import { paths } from "@dokploy/server/constants" ;
56
56
import { join } from "node:path" ;
57
- import { execAsync , execAsyncRemote } from "@dokploy/server/utils/process/execAsync" ;
57
+ import {
58
+ execAsync ,
59
+ execAsyncRemote ,
60
+ } from "@dokploy/server/utils/process/execAsync" ;
58
61
import { getDokployUrl } from "./admin" ;
59
- import { createDeploymentCompose , updateDeployment , updateDeploymentStatus } from "./deployment" ;
62
+ import {
63
+ createDeploymentCompose ,
64
+ updateDeployment ,
65
+ updateDeploymentStatus ,
66
+ } from "./deployment" ;
60
67
import { validUniqueServerAppName } from "./project" ;
61
68
62
69
export type Compose = typeof compose . $inferSelect ;
63
70
64
71
const tryUpdateWithGitInfoLocal = async (
65
- composeEntity : Compose & { appName : string ; env : string | null } ,
66
- deploymentId : string ,
67
- defaultTitle : string ,
68
- defaultDescription : string ,
72
+ composeEntity : Compose & { appName : string ; env : string | null } ,
73
+ deploymentId : string ,
74
+ defaultTitle : string ,
75
+ defaultDescription : string ,
69
76
) => {
70
- try {
71
- const { COMPOSE_PATH } = paths ( ) ;
72
- const codePath = join ( COMPOSE_PATH , composeEntity . appName , "code" ) ;
73
- const { stdout : hashStdout } = await execAsync (
74
- `git -C ${ codePath } rev-parse HEAD` ,
75
- ) ;
76
- const gitHash = hashStdout . trim ( ) ;
77
- const { stdout : msgStdout } = await execAsync (
78
- `git -C ${ codePath } log -1 --pretty=%B` ,
79
- ) ;
80
- const gitMessage = msgStdout . trim ( ) ;
81
-
82
- if ( gitHash ) {
83
- const current = composeEntity . env || "" ;
84
- const withoutOld = current
85
- . split ( "\n" )
86
- . filter ( ( l ) => l . trim ( ) && ! l . startsWith ( "GIT_HASH=" ) )
87
- . join ( "\n" ) ;
88
- const newEnv = `${ withoutOld } ${ withoutOld ? "\n" : "" } GIT_HASH=${ gitHash } ` ;
89
-
90
- // Update the database immediately
91
- await updateCompose ( composeEntity . composeId as string , { env : newEnv } ) ;
92
-
93
- // Update the local entity for consistency
94
- composeEntity . env = newEnv ;
95
- }
96
- await updateDeployment ( deploymentId , {
97
- title : gitMessage || defaultTitle ,
98
- description : gitHash ? `Hash: ${ gitHash } ` : defaultDescription ,
99
- } ) ;
100
- } catch ( error ) {
101
- // ignore if git data can't be fetched
102
- }
77
+ try {
78
+ const { COMPOSE_PATH } = paths ( ) ;
79
+ const codePath = join ( COMPOSE_PATH , composeEntity . appName , "code" ) ;
80
+ const { stdout : hashStdout } = await execAsync (
81
+ `git -C ${ codePath } rev-parse HEAD` ,
82
+ ) ;
83
+ const gitHash = hashStdout . trim ( ) ;
84
+ const { stdout : msgStdout } = await execAsync (
85
+ `git -C ${ codePath } log -1 --pretty=%B` ,
86
+ ) ;
87
+ const gitMessage = msgStdout . trim ( ) ;
88
+
89
+ if ( gitHash ) {
90
+ const current = composeEntity . env || "" ;
91
+ const withoutOld = current
92
+ . split ( "\n" )
93
+ . filter ( ( l ) => l . trim ( ) && ! l . startsWith ( "GIT_HASH=" ) )
94
+ . join ( "\n" ) ;
95
+ const newEnv = `${ withoutOld } ${ withoutOld ? "\n" : "" } GIT_HASH=${ gitHash } ` ;
96
+
97
+ // Update the database immediately
98
+ await updateCompose ( composeEntity . composeId as string , { env : newEnv } ) ;
99
+
100
+ // Update the local entity for consistency
101
+ composeEntity . env = newEnv ;
102
+ }
103
+ await updateDeployment ( deploymentId , {
104
+ title : gitMessage || defaultTitle ,
105
+ description : gitHash ? `Hash: ${ gitHash } ` : defaultDescription ,
106
+ } ) ;
107
+ } catch ( error ) {
108
+ // ignore if git data can't be fetched
109
+ }
103
110
} ;
104
111
105
112
const tryUpdateWithGitInfoRemote = async (
106
- composeEntity : Compose & { appName : string ; env : string | null ; serverId : string } ,
107
- deploymentId : string ,
108
- defaultTitle : string ,
109
- defaultDescription : string ,
113
+ composeEntity : Compose & {
114
+ appName : string ;
115
+ env : string | null ;
116
+ serverId : string ;
117
+ } ,
118
+ deploymentId : string ,
119
+ defaultTitle : string ,
120
+ defaultDescription : string ,
110
121
) => {
111
- try {
112
- const { COMPOSE_PATH } = paths ( true ) ;
113
- const codePath = join ( COMPOSE_PATH , composeEntity . appName , "code" ) ;
114
- const { stdout : hashStdout } = await execAsyncRemote (
115
- composeEntity . serverId ,
116
- `git -C ${ codePath } rev-parse HEAD | tr -d '\n'` ,
117
- ) ;
118
- const gitHash = ( hashStdout || "" ) . trim ( ) ;
119
- const { stdout : msgStdout } = await execAsyncRemote (
120
- composeEntity . serverId ,
121
- `git -C ${ codePath } log -1 --pretty=%B` ,
122
- ) ;
123
- const gitMessage = ( msgStdout || "" ) . trim ( ) ;
124
-
125
- if ( gitHash ) {
126
- const current = composeEntity . env || "" ;
127
- const withoutOld = current
128
- . split ( "\n" )
129
- . filter ( ( l ) => l . trim ( ) && ! l . startsWith ( "GIT_HASH=" ) )
130
- . join ( "\n" ) ;
131
- const newEnv = `${ withoutOld } ${ withoutOld ? "\n" : "" } GIT_HASH=${ gitHash } ` ;
132
-
133
- // Update the database
134
- await updateCompose ( composeEntity . composeId as string , { env : newEnv } ) ;
135
-
136
- // Update the local entity for consistency
137
- composeEntity . env = newEnv ;
138
- }
139
- await updateDeployment ( deploymentId , {
140
- title : gitMessage || defaultTitle ,
141
- description : gitHash ? `Hash: ${ gitHash } ` : defaultDescription ,
142
- } ) ;
143
- } catch ( error ) {
144
- // ignore if git data can't be fetched
145
- }
122
+ try {
123
+ const { COMPOSE_PATH } = paths ( true ) ;
124
+ const codePath = join ( COMPOSE_PATH , composeEntity . appName , "code" ) ;
125
+ const { stdout : hashStdout } = await execAsyncRemote (
126
+ composeEntity . serverId ,
127
+ `git -C ${ codePath } rev-parse HEAD | tr -d '\n'` ,
128
+ ) ;
129
+ const gitHash = ( hashStdout || "" ) . trim ( ) ;
130
+ const { stdout : msgStdout } = await execAsyncRemote (
131
+ composeEntity . serverId ,
132
+ `git -C ${ codePath } log -1 --pretty=%B` ,
133
+ ) ;
134
+ const gitMessage = ( msgStdout || "" ) . trim ( ) ;
135
+
136
+ if ( gitHash ) {
137
+ const current = composeEntity . env || "" ;
138
+ const withoutOld = current
139
+ . split ( "\n" )
140
+ . filter ( ( l ) => l . trim ( ) && ! l . startsWith ( "GIT_HASH=" ) )
141
+ . join ( "\n" ) ;
142
+ const newEnv = `${ withoutOld } ${ withoutOld ? "\n" : "" } GIT_HASH=${ gitHash } ` ;
143
+
144
+ // Update the database
145
+ await updateCompose ( composeEntity . composeId as string , { env : newEnv } ) ;
146
+
147
+ // Update the local entity for consistency
148
+ composeEntity . env = newEnv ;
149
+ }
150
+ await updateDeployment ( deploymentId , {
151
+ title : gitMessage || defaultTitle ,
152
+ description : gitHash ? `Hash: ${ gitHash } ` : defaultDescription ,
153
+ } ) ;
154
+ } catch ( error ) {
155
+ // ignore if git data can't be fetched
156
+ }
146
157
} ;
147
158
148
159
export const createCompose = async ( input : typeof apiCreateCompose . _type ) => {
@@ -370,14 +381,14 @@ export const deployCompose = async ({
370
381
} else if ( compose . sourceType === "raw" ) {
371
382
await createComposeFile ( compose , deployment . logPath ) ;
372
383
}
373
-
384
+
374
385
// Refresh compose object from database to get updated environment variables
375
386
const updatedCompose = await findComposeById ( composeId ) ;
376
387
await buildCompose ( updatedCompose , deployment . logPath ) ;
377
-
388
+
378
389
// Ensure environment update is completed before marking deployment as done
379
- await new Promise ( resolve => setTimeout ( resolve , 100 ) ) ;
380
-
390
+ await new Promise ( ( resolve ) => setTimeout ( resolve , 100 ) ) ;
391
+
381
392
await updateDeploymentStatus ( deployment . deploymentId , "done" ) ;
382
393
await updateCompose ( composeId , {
383
394
composeStatus : "done" ,
@@ -438,7 +449,7 @@ export const rebuildCompose = async ({
438
449
descriptionLog ,
439
450
) ;
440
451
}
441
-
452
+
442
453
// Refresh compose object from database to get updated environment variables
443
454
const updatedCompose = await findComposeById ( composeId ) ;
444
455
await buildCompose ( updatedCompose , deployment . logPath ) ;
@@ -518,7 +529,7 @@ export const deployRemoteCompose = async ({
518
529
}
519
530
520
531
await execAsyncRemote ( compose . serverId , command ) ;
521
-
532
+
522
533
// Update with git info for git-based source types
523
534
if ( compose . sourceType !== "raw" ) {
524
535
await tryUpdateWithGitInfoRemote (
@@ -528,7 +539,7 @@ export const deployRemoteCompose = async ({
528
539
descriptionLog ,
529
540
) ;
530
541
}
531
-
542
+
532
543
// Refresh compose object from database to get updated environment variables
533
544
const updatedCompose = await findComposeById ( composeId ) ;
534
545
await getBuildComposeCommand ( updatedCompose , deployment . logPath ) ;
0 commit comments