fix: fail build if no application found.

This commit is contained in:
Andras Bacsai
2023-04-18 14:32:29 +02:00
parent e2314c350b
commit 7cfe98d988

View File

@@ -69,7 +69,15 @@ import * as buildpacks from '../lib/buildPacks';
teams: true teams: true
} }
}); });
if (!application) {
await prisma.build.update({
where: { id: queueBuild.id },
data: {
status: 'failed'
}
});
throw new Error('Application not found');
}
let { let {
id: buildId, id: buildId,
type, type,
@@ -111,7 +119,7 @@ import * as buildpacks from '../lib/buildPacks';
.replace('-app', '')}:${storage.path}`; .replace('-app', '')}:${storage.path}`;
} }
if (storage.hostPath) { if (storage.hostPath) {
return `${storage.hostPath}:${storage.path}` return `${storage.hostPath}:${storage.path}`;
} }
return `${applicationId}${storage.path.replace(/\//gi, '-')}:${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 port: exposePort ? `${exposePort}:${port}` : port
}); });
try { try {
const composeVolumes = volumes.filter(v => { const composeVolumes = volumes
if (!v.startsWith('.') && !v.startsWith('..') && !v.startsWith('/') && !v.startsWith('~')) { .filter((v) => {
return v; if (
} !v.startsWith('.') &&
}).map((volume) => { !v.startsWith('..') &&
return { !v.startsWith('/') &&
[`${volume.split(':')[0]}`]: { !v.startsWith('~')
name: volume.split(':')[0] ) {
return v;
} }
}; })
}); .map((volume) => {
return {
[`${volume.split(':')[0]}`]: {
name: volume.split(':')[0]
}
};
});
const composeFile = { const composeFile = {
version: '3.8', version: '3.8',
services: { services: {
@@ -389,14 +404,14 @@ import * as buildpacks from '../lib/buildPacks';
.replace('-app', '')}:${storage.path}`; .replace('-app', '')}:${storage.path}`;
} }
if (storage.hostPath) { if (storage.hostPath) {
return `${storage.hostPath}:${storage.path}` return `${storage.hostPath}:${storage.path}`;
} }
return `${applicationId}${storage.path.replace(/\//gi, '-')}:${storage.path}`; return `${applicationId}${storage.path.replace(/\//gi, '-')}:${storage.path}`;
}) || []; }) || [];
try { try {
dockerComposeConfiguration = JSON.parse(dockerComposeConfiguration); dockerComposeConfiguration = JSON.parse(dockerComposeConfiguration);
} catch (error) { } } catch (error) {}
let deployNeeded = true; let deployNeeded = true;
let destinationType; let destinationType;
@@ -463,7 +478,7 @@ import * as buildpacks from '../lib/buildPacks';
try { try {
await prisma.build.update({ where: { id: buildId }, data: { commit } }); await prisma.build.update({ where: { id: buildId }, data: { commit } });
} catch (err) { } } catch (err) {}
if (!pullmergeRequestId) { if (!pullmergeRequestId) {
if (configHash !== currentHash) { if (configHash !== currentHash) {
@@ -504,8 +519,9 @@ import * as buildpacks from '../lib/buildPacks';
try { try {
await executeCommand({ await executeCommand({
dockerId: destinationDocker.id, dockerId: destinationDocker.id,
command: `docker ${location ? `--config ${location}` : '' command: `docker ${
} pull ${imageName}:${customTag}` location ? `--config ${location}` : ''
} pull ${imageName}:${customTag}`
}); });
imageFoundRemotely = true; imageFoundRemotely = true;
} catch (error) { } catch (error) {
@@ -668,8 +684,9 @@ import * as buildpacks from '../lib/buildPacks';
try { try {
const { stdout: containers } = await executeCommand({ const { stdout: containers } = await executeCommand({
dockerId: destinationDockerId, dockerId: destinationDockerId,
command: `docker ps -a --filter 'label=com.docker.compose.service=${pullmergeRequestId ? imageId : applicationId command: `docker ps -a --filter 'label=com.docker.compose.service=${
}' --format {{.ID}}` pullmergeRequestId ? imageId : applicationId
}' --format {{.ID}}`
}); });
if (containers) { if (containers) {
const containerArray = containers.split('\n'); const containerArray = containers.split('\n');
@@ -701,17 +718,24 @@ import * as buildpacks from '../lib/buildPacks';
await saveDockerRegistryCredentials({ url, username, password, workdir }); await saveDockerRegistryCredentials({ url, username, password, workdir });
} }
try { try {
const composeVolumes = volumes.filter(v => { const composeVolumes = volumes
if (!v.startsWith('.') && !v.startsWith('..') && !v.startsWith('/') && !v.startsWith('~')) { .filter((v) => {
return v; if (
} !v.startsWith('.') &&
}).map((volume) => { !v.startsWith('..') &&
return { !v.startsWith('/') &&
[`${volume.split(':')[0]}`]: { !v.startsWith('~')
name: volume.split(':')[0] ) {
return v;
} }
}; })
}); .map((volume) => {
return {
[`${volume.split(':')[0]}`]: {
name: volume.split(':')[0]
}
};
});
const composeFile = { const composeFile = {
version: '3.8', version: '3.8',
services: { services: {