@@ -171,6 +171,53 @@ export default class Coolify {
171
171
} )
172
172
}
173
173
174
+ public async checkIfDeploymentUnderway ( {
175
+ appUUID,
176
+ sha
177
+ } : {
178
+ appUUID : string
179
+ sha : string
180
+ } ) : Promise < boolean > {
181
+ const client = this . client
182
+
183
+ try {
184
+ const deployments = ( await listDeploymentsByAppUuid ( {
185
+ client,
186
+ path : {
187
+ uuid : appUUID
188
+ }
189
+ } ) ) as unknown as {
190
+ data : { deployments : { commit : string ; status : string } [ ] }
191
+ }
192
+
193
+ if ( ! deployments . data ) {
194
+ return false
195
+ }
196
+
197
+ const deployment = deployments . data ?. deployments . find (
198
+ ( deployment ) =>
199
+ deployment . commit === sha || deployment . commit === 'HEAD'
200
+ )
201
+
202
+ if ( deployment ) {
203
+ // Check if deployment is in progress or finished (not failed, or cancelled)
204
+ const inProgressStatuses = [
205
+ 'running' ,
206
+ 'queued' ,
207
+ 'in_progress' ,
208
+ 'finished' ,
209
+ 'pending'
210
+ ]
211
+ return inProgressStatuses . includes ( deployment . status )
212
+ }
213
+
214
+ return false
215
+ } catch ( error ) {
216
+ console . warn ( `Error checking deployment status: ${ error } ` )
217
+ return false
218
+ }
219
+ }
220
+
174
221
public async waitUntilAppIsReady ( {
175
222
appUUID,
176
223
sha,
@@ -657,11 +704,6 @@ export default class Coolify {
657
704
const existingApplications = await listApplications ( {
658
705
client : this . client
659
706
} )
660
- console . log (
661
- `Existing applications: ${ existingApplications . data
662
- ?. map ( ( app ) => app . name )
663
- . join ( ', ' ) } `
664
- )
665
707
666
708
console . log ( 'Waiting for backend to start' )
667
709
await this . waitUntilServiceIsReady ( {
@@ -791,25 +833,38 @@ export default class Coolify {
791
833
} )
792
834
console . log ( 'Frontend started' )
793
835
} else {
794
- //Update the commit SHA of the frontend app
795
- await updateApplicationByUuid ( {
796
- client : this . client ,
797
- path : {
798
- uuid : appUUID
799
- } ,
800
- body : {
801
- git_commit_sha : gitCommitSha
802
- }
803
- } )
804
- console . log (
805
- `Deploying frontend app ${ appUUID } with commit ${ gitCommitSha } `
806
- )
807
- await deployByTagOrUuid ( {
808
- client : this . client ,
809
- query : {
810
- uuid : appUUID
811
- }
836
+ // Check if deployment is already underway for this commit
837
+ const deploymentUnderway = await this . checkIfDeploymentUnderway ( {
838
+ appUUID : appUUID ,
839
+ sha : gitCommitSha
812
840
} )
841
+
842
+ if ( deploymentUnderway ) {
843
+ console . log (
844
+ `Deployment already underway for frontend app ${ appUUID } with commit ${ gitCommitSha } , waiting for completion`
845
+ )
846
+ } else {
847
+ //Update the commit SHA of the frontend app
848
+ await updateApplicationByUuid ( {
849
+ client : this . client ,
850
+ path : {
851
+ uuid : appUUID
852
+ } ,
853
+ body : {
854
+ git_commit_sha : gitCommitSha
855
+ }
856
+ } )
857
+ console . log (
858
+ `Deploying frontend app ${ appUUID } with commit ${ gitCommitSha } `
859
+ )
860
+ await deployByTagOrUuid ( {
861
+ client : this . client ,
862
+ query : {
863
+ uuid : appUUID
864
+ }
865
+ } )
866
+ }
867
+
813
868
await this . waitUntilAppIsReady ( {
814
869
appUUID : appUUID ,
815
870
sha : gitCommitSha ,
0 commit comments