This commit is contained in:
Andras Bacsai 2022-07-25 13:53:53 +00:00
parent f672d01777
commit 12273f424e

View File

@ -732,8 +732,8 @@ export async function getPreviews(request: FastifyRequest<OnlyId>) {
const applicationSecrets = secrets.filter((secret) => !secret.isPRMRSecret); const applicationSecrets = secrets.filter((secret) => !secret.isPRMRSecret);
const PRMRSecrets = secrets.filter((secret) => secret.isPRMRSecret); const PRMRSecrets = secrets.filter((secret) => secret.isPRMRSecret);
const application = await prisma.application.findUnique({ where: { id }, include: { destinationDocker: true } }) const application = await prisma.application.findUnique({ where: { id }, include: { destinationDocker: true } });
const { stdout } = await executeDockerCmd({ dockerId: application.destinationDocker.id, command: `docker container ls --filter 'name=${id}-' --format "{{json .}}"` }) const { stdout } = await executeDockerCmd({ dockerId: application.destinationDocker.id, command: `docker container ls --filter 'name=${id}-' --format "{{json .}}"` })
if (stdout === '') { if (stdout === '') {
return { return {
containers: [], containers: [],
@ -741,12 +741,20 @@ export async function getPreviews(request: FastifyRequest<OnlyId>) {
PRMRSecrets: [] PRMRSecrets: []
} }
} }
const jsonStdout = JSON.parse(stdout) const out = stdout.trim().split('\n')
console.log({jsonStdout, stdout}) const jsonStdout = out.map(a => JSON.parse(a))
const containers = jsonStdout.filter((container) => { const containers = jsonStdout.filter((container) => {
const labels = container.Labels.split(',')
let jsonLabels = {}
labels.forEach(l => {
const name = l.split('=')[0]
const value = l.split('=')[1]
jsonLabels = { ...jsonLabels, ...{ [name]: value } }
})
container.Labels = jsonLabels;
return ( return (
container.Labels['coolify.configuration'] && jsonLabels['coolify.configuration'] &&
container.Labels['coolify.type'] === 'standalone-application' jsonLabels['coolify.type'] === 'standalone-application'
); );
}); });
const jsonContainers = containers const jsonContainers = containers
@ -766,6 +774,7 @@ export async function getPreviews(request: FastifyRequest<OnlyId>) {
}) })
} }
} catch ({ status, message }) { } catch ({ status, message }) {
console.log({ status, message })
return errorHandler({ status, message }) return errorHandler({ status, message })
} }
} }