From 7cfe98d988348e952ac0337f2076f1c82ad4e233 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Tue, 18 Apr 2023 14:32:29 +0200 Subject: [PATCH] fix: fail build if no application found. --- apps/api/src/jobs/deployApplication.ts | 82 +++++++++++++++++--------- 1 file changed, 53 insertions(+), 29 deletions(-) diff --git a/apps/api/src/jobs/deployApplication.ts b/apps/api/src/jobs/deployApplication.ts index 28b6e1b1f..93dd3b761 100644 --- a/apps/api/src/jobs/deployApplication.ts +++ b/apps/api/src/jobs/deployApplication.ts @@ -69,7 +69,15 @@ import * as buildpacks from '../lib/buildPacks'; teams: true } }); - + if (!application) { + await prisma.build.update({ + where: { id: queueBuild.id }, + data: { + status: 'failed' + } + }); + throw new Error('Application not found'); + } let { id: buildId, type, @@ -111,7 +119,7 @@ import * as buildpacks from '../lib/buildPacks'; .replace('-app', '')}:${storage.path}`; } if (storage.hostPath) { - return `${storage.hostPath}:${storage.path}` + return `${storage.hostPath}:${storage.path}`; } return `${applicationId}${storage.path.replace(/\//gi, '-')}:${storage.path}`; }) || []; @@ -163,17 +171,24 @@ import * as buildpacks from '../lib/buildPacks'; port: exposePort ? `${exposePort}:${port}` : port }); try { - const composeVolumes = volumes.filter(v => { - if (!v.startsWith('.') && !v.startsWith('..') && !v.startsWith('/') && !v.startsWith('~')) { - return v; - } - }).map((volume) => { - return { - [`${volume.split(':')[0]}`]: { - name: volume.split(':')[0] + const composeVolumes = volumes + .filter((v) => { + if ( + !v.startsWith('.') && + !v.startsWith('..') && + !v.startsWith('/') && + !v.startsWith('~') + ) { + return v; } - }; - }); + }) + .map((volume) => { + return { + [`${volume.split(':')[0]}`]: { + name: volume.split(':')[0] + } + }; + }); const composeFile = { version: '3.8', services: { @@ -389,14 +404,14 @@ import * as buildpacks from '../lib/buildPacks'; .replace('-app', '')}:${storage.path}`; } if (storage.hostPath) { - return `${storage.hostPath}:${storage.path}` + return `${storage.hostPath}:${storage.path}`; } return `${applicationId}${storage.path.replace(/\//gi, '-')}:${storage.path}`; }) || []; try { dockerComposeConfiguration = JSON.parse(dockerComposeConfiguration); - } catch (error) { } + } catch (error) {} let deployNeeded = true; let destinationType; @@ -463,7 +478,7 @@ import * as buildpacks from '../lib/buildPacks'; try { await prisma.build.update({ where: { id: buildId }, data: { commit } }); - } catch (err) { } + } catch (err) {} if (!pullmergeRequestId) { if (configHash !== currentHash) { @@ -504,8 +519,9 @@ import * as buildpacks from '../lib/buildPacks'; try { await executeCommand({ dockerId: destinationDocker.id, - command: `docker ${location ? `--config ${location}` : '' - } pull ${imageName}:${customTag}` + command: `docker ${ + location ? `--config ${location}` : '' + } pull ${imageName}:${customTag}` }); imageFoundRemotely = true; } catch (error) { @@ -668,8 +684,9 @@ import * as buildpacks from '../lib/buildPacks'; try { const { stdout: containers } = await executeCommand({ dockerId: destinationDockerId, - command: `docker ps -a --filter 'label=com.docker.compose.service=${pullmergeRequestId ? imageId : applicationId - }' --format {{.ID}}` + command: `docker ps -a --filter 'label=com.docker.compose.service=${ + pullmergeRequestId ? imageId : applicationId + }' --format {{.ID}}` }); if (containers) { const containerArray = containers.split('\n'); @@ -701,17 +718,24 @@ import * as buildpacks from '../lib/buildPacks'; await saveDockerRegistryCredentials({ url, username, password, workdir }); } try { - const composeVolumes = volumes.filter(v => { - if (!v.startsWith('.') && !v.startsWith('..') && !v.startsWith('/') && !v.startsWith('~')) { - return v; - } - }).map((volume) => { - return { - [`${volume.split(':')[0]}`]: { - name: volume.split(':')[0] + const composeVolumes = volumes + .filter((v) => { + if ( + !v.startsWith('.') && + !v.startsWith('..') && + !v.startsWith('/') && + !v.startsWith('~') + ) { + return v; } - }; - }); + }) + .map((volume) => { + return { + [`${volume.split(':')[0]}`]: { + name: volume.split(':')[0] + } + }; + }); const composeFile = { version: '3.8', services: {