@@ -2,7 +2,7 @@ import { exec } from '@actions/exec'
2
2
import { randomBytes } from 'crypto'
3
3
import { readdir , readFile , stat } from 'fs/promises'
4
4
import JSZip from 'jszip'
5
- import { join , relative } from 'path'
5
+ import path , { join , relative } from 'path'
6
6
import postgres from 'postgres'
7
7
8
8
import { createClient } from './client/client/client.js'
@@ -132,11 +132,24 @@ export default class Coolify {
132
132
timeout_seconds ?: number
133
133
} ) {
134
134
const client = this . client
135
+ if ( serviceUUID ) {
136
+ console . log ( `Waiting for service ${ serviceUUID } to be ready` )
137
+ } else if ( appUUID ) {
138
+ console . log ( `Waiting for app ${ appUUID } to be ready` )
139
+ } else {
140
+ throw new Error ( 'No service or app UUID provided' )
141
+ }
135
142
return new Promise ( ( resolve , reject ) => {
136
143
const timeout = timeout_seconds ?? 600
137
144
const expirationTimeout = setTimeout ( ( ) => {
138
145
clearInterval ( interval )
139
- reject ( new Error ( 'Timeout waiting for service or app to be ready' ) )
146
+ reject (
147
+ new Error (
148
+ serviceUUID
149
+ ? `Timeout waiting for service ${ serviceUUID } to be ready`
150
+ : `Timeout waiting for app ${ appUUID } to be ready`
151
+ )
152
+ )
140
153
} , timeout * 1000 )
141
154
async function checkStatus ( ) {
142
155
if ( serviceUUID ) {
@@ -147,8 +160,6 @@ export default class Coolify {
147
160
}
148
161
} )
149
162
if ( serviceStatus . data && 'status' in serviceStatus . data ) {
150
- console . log ( 'Service status:' )
151
- console . log ( serviceStatus . data [ 'status' ] )
152
163
if ( serviceStatus . data [ 'status' ] === 'running:healthy' ) {
153
164
clearInterval ( interval )
154
165
clearTimeout ( expirationTimeout )
@@ -191,6 +202,7 @@ export default class Coolify {
191
202
192
203
private async getServerUUID ( ) {
193
204
const servers = await listServers ( { client : this . client } )
205
+ console . log ( servers )
194
206
if ( ! servers . data || servers . data . length === 0 || ! servers . data [ 0 ] . uuid ) {
195
207
throw new Error ( 'No servers found' )
196
208
}
@@ -215,7 +227,11 @@ export default class Coolify {
215
227
console . log ( `Creating new supabase service ${ supabaseComponentName } ` )
216
228
createdNewSupabaseService = true
217
229
const updatedDockerCompose = await readFile (
218
- './supabase-pawtograder.yml' ,
230
+ path . join (
231
+ path . dirname ( new URL ( import . meta. url ) . pathname ) ,
232
+ '../' ,
233
+ 'supabase-pawtograder.yml'
234
+ ) ,
219
235
'utf-8'
220
236
)
221
237
//Create backend service
@@ -414,7 +430,7 @@ export default class Coolify {
414
430
await this . pushMigrations ( {
415
431
serviceUUID : backendServiceUUID ,
416
432
deployToken : deploymentKey ,
417
- checkedOutSupabaseDir : checkedOutProjectDir ,
433
+ checkedOutProjectDir,
418
434
resetDb : true ,
419
435
postgresPassword : postgres_password
420
436
} )
@@ -514,13 +530,13 @@ export default class Coolify {
514
530
async pushMigrations ( {
515
531
serviceUUID,
516
532
deployToken,
517
- checkedOutSupabaseDir ,
533
+ checkedOutProjectDir ,
518
534
postgresPassword,
519
535
resetDb
520
536
} : {
521
537
serviceUUID : string
522
538
deployToken : string
523
- checkedOutSupabaseDir : string
539
+ checkedOutProjectDir : string
524
540
postgresPassword : string
525
541
resetDb ?: boolean
526
542
} ) {
@@ -535,7 +551,7 @@ export default class Coolify {
535
551
console . log ( 'Tunnel connected' )
536
552
let command = ''
537
553
if ( ! resetDb )
538
- command = `supabase db push --include-all --db-url postgres://postgres:${ postgresPassword } @localhost:${ localPort } /postgres`
554
+ command = `./node_modules/.bin/ supabase db push --include-all --db-url postgres://postgres:${ postgresPassword } @localhost:${ localPort } /postgres`
539
555
else {
540
556
const sql = postgres (
541
557
`postgres://postgres:${ postgresPassword } @localhost:${ localPort } /postgres`
@@ -544,10 +560,10 @@ export default class Coolify {
544
560
await sql `TRUNCATE TABLE storage.objects CASCADE`
545
561
await sql `TRUNCATE TABLE vault.secrets CASCADE`
546
562
await sql . end ( )
547
- command = `supabase db reset --db-url postgres://postgres:${ postgresPassword } @localhost:${ localPort } /postgres`
563
+ command = `./node_modules/.bin/ supabase db reset --db-url postgres://postgres:${ postgresPassword } @localhost:${ localPort } /postgres`
548
564
}
549
565
await exec ( command , undefined , {
550
- cwd : checkedOutSupabaseDir ,
566
+ cwd : checkedOutProjectDir ,
551
567
input : Buffer . from ( 'y' )
552
568
} )
553
569
console . log ( 'Migrations pushed' )
0 commit comments