@@ -4,7 +4,7 @@ import fs from 'fs/promises';
44import yaml from 'js-yaml' ;
55
66import { copyBaseConfigurationFiles , makeLabelForStandaloneApplication , saveBuildLog , setDefaultConfiguration } from '../lib/buildPacks/common' ;
7- import { createDirectories , decrypt , defaultComposeConfiguration , executeDockerCmd , getDomain , prisma } from '../lib/common' ;
7+ import { createDirectories , decrypt , defaultComposeConfiguration , executeDockerCmd , getDomain , prisma , decryptApplication } from '../lib/common' ;
88import * as importers from '../lib/importers' ;
99import * as buildpacks from '../lib/buildPacks' ;
1010
@@ -27,7 +27,7 @@ import * as buildpacks from '../lib/buildPacks';
2727
2828 const th = throttle ( async ( ) => {
2929 try {
30- const queuedBuilds = await prisma . build . findMany ( { where : { status : 'queued' } , orderBy : { createdAt : 'asc' } } ) ;
30+ const queuedBuilds = await prisma . build . findMany ( { where : { status : { in : [ 'queued' , 'running' ] } } , orderBy : { createdAt : 'asc' } } ) ;
3131 const { concurrentBuilds } = await prisma . setting . findFirst ( { } )
3232 if ( queuedBuilds . length > 0 ) {
3333 parentPort . postMessage ( { deploying : true } ) ;
@@ -37,68 +37,72 @@ import * as buildpacks from '../lib/buildPacks';
3737
3838 for ( const queueBuild of queuedBuilds ) {
3939 actions . push ( async ( ) => {
40- const application = await prisma . application . findUnique ( { where : { id : queueBuild . applicationId } , include : { destinationDocker : true , gitSource : { include : { githubApp : true , gitlabApp : true } } , persistentStorage : true , secrets : true , settings : true , teams : true } } )
41- const { id : buildId , type, sourceBranch = null , pullmergeRequestId = null , forceRebuild } = queueBuild
42- const {
43- id : applicationId ,
44- repository,
45- name,
46- destinationDocker,
47- destinationDockerId,
48- gitSource,
49- configHash,
50- fqdn,
51- projectId,
52- secrets,
53- phpModules,
54- settings,
55- persistentStorage,
56- pythonWSGI,
57- pythonModule,
58- pythonVariable,
59- denoOptions,
60- exposePort,
61- baseImage,
62- baseBuildImage,
63- deploymentType,
64- } = application
65- let {
66- branch,
67- buildPack,
68- port,
69- installCommand,
70- buildCommand,
71- startCommand,
72- baseDirectory,
73- publishDirectory,
74- dockerFileLocation,
75- denoMainFile
76- } = application
77- const currentHash = crypto
78- . createHash ( 'sha256' )
79- . update (
80- JSON . stringify ( {
81- pythonWSGI,
82- pythonModule,
83- pythonVariable,
84- deploymentType,
85- denoOptions,
86- baseImage,
87- baseBuildImage,
88- buildPack,
89- port,
90- exposePort,
91- installCommand,
92- buildCommand,
93- startCommand,
94- secrets,
95- branch,
96- repository,
97- fqdn
98- } )
99- )
100- . digest ( 'hex' ) ;
40+ let application = await prisma . application . findUnique ( { where : { id : queueBuild . applicationId } , include : { destinationDocker : true , gitSource : { include : { githubApp : true , gitlabApp : true } } , persistentStorage : true , secrets : true , settings : true , teams : true } } )
41+ let { id : buildId , type, sourceBranch = null , pullmergeRequestId = null , forceRebuild } = queueBuild
42+ application = decryptApplication ( application )
10143 try {
44+ if ( queueBuild . status === 'running' ) {
45+ await saveBuildLog ( { line : 'Building halted, restarting...' , buildId, applicationId : application . id } ) ;
46+ }
47+ const {
48+ id : applicationId ,
49+ repository,
50+ name,
51+ destinationDocker,
52+ destinationDockerId,
53+ gitSource,
54+ configHash,
55+ fqdn,
56+ projectId,
57+ secrets,
58+ phpModules,
59+ settings,
60+ persistentStorage,
61+ pythonWSGI,
62+ pythonModule,
63+ pythonVariable,
64+ denoOptions,
65+ exposePort,
66+ baseImage,
67+ baseBuildImage,
68+ deploymentType,
69+ } = application
70+ let {
71+ branch,
72+ buildPack,
73+ port,
74+ installCommand,
75+ buildCommand,
76+ startCommand,
77+ baseDirectory,
78+ publishDirectory,
79+ dockerFileLocation,
80+ denoMainFile
81+ } = application
82+ const currentHash = crypto
83+ . createHash ( 'sha256' )
84+ . update (
85+ JSON . stringify ( {
86+ pythonWSGI,
87+ pythonModule,
88+ pythonVariable,
89+ deploymentType,
90+ denoOptions,
91+ baseImage,
92+ baseBuildImage,
93+ buildPack,
94+ port,
95+ exposePort,
96+ installCommand,
97+ buildCommand,
98+ startCommand,
99+ secrets,
100+ branch,
101+ repository,
102+ fqdn
103+ } )
104+ )
105+ . digest ( 'hex' ) ;
102106 const { debug } = settings ;
103107 if ( concurrency === 1 ) {
104108 await prisma . build . updateMany ( {
@@ -258,7 +262,6 @@ import * as buildpacks from '../lib/buildPacks';
258262 ] ;
259263 if ( secrets . length > 0 ) {
260264 secrets . forEach ( ( secret ) => {
261- secret . value = decrypt ( secret . value )
262265 if ( pullmergeRequestId ) {
263266 if ( secret . isPRMRSecret ) {
264267 envs . push ( `${ secret . name } =${ secret . value } ` ) ;
@@ -353,13 +356,16 @@ import * as buildpacks from '../lib/buildPacks';
353356 where : { id : buildId , status : { in : [ 'queued' , 'running' ] } } ,
354357 data : { status : 'failed' }
355358 } ) ;
356- await saveBuildLog ( { line : error , buildId, applicationId } ) ;
359+ await saveBuildLog ( { line : error , buildId, applicationId : application . id } ) ;
357360 }
358361 } ) ;
362+
359363 }
364+
360365 await pAll . default ( actions , { concurrency } )
361366 }
362367 } catch ( error ) {
368+ console . log ( error )
363369 } finally {
364370 }
365371 } )
0 commit comments