Skip to content

Commit 7de2276

Browse files
committed
optimization
1 parent 4b1e2a6 commit 7de2276

File tree

3 files changed

+136
-43
lines changed

3 files changed

+136
-43
lines changed

dist/index.js

Lines changed: 57 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/coolify.ts

Lines changed: 78 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,53 @@ export default class Coolify {
171171
})
172172
}
173173

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+
174221
public async waitUntilAppIsReady({
175222
appUUID,
176223
sha,
@@ -657,11 +704,6 @@ export default class Coolify {
657704
const existingApplications = await listApplications({
658705
client: this.client
659706
})
660-
console.log(
661-
`Existing applications: ${existingApplications.data
662-
?.map((app) => app.name)
663-
.join(', ')}`
664-
)
665707

666708
console.log('Waiting for backend to start')
667709
await this.waitUntilServiceIsReady({
@@ -791,25 +833,38 @@ export default class Coolify {
791833
})
792834
console.log('Frontend started')
793835
} 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
812840
})
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+
813868
await this.waitUntilAppIsReady({
814869
appUUID: appUUID,
815870
sha: gitCommitSha,

0 commit comments

Comments
 (0)