fix: skip ssl cert in case of error

This commit is contained in:
Andras Bacsai
2022-03-22 10:37:33 +01:00
parent 6b89857697
commit 927bf46304

View File

@@ -103,34 +103,38 @@ export async function generateSSLCerts() {
orderBy: { createdAt: 'desc' } orderBy: { createdAt: 'desc' }
}); });
for (const application of applications) { for (const application of applications) {
const { try {
fqdn, const {
id, fqdn,
destinationDocker: { engine, network }, id,
settings: { previews } destinationDocker: { engine, network },
} = application; settings: { previews }
const isRunning = await checkContainer(engine, id); } = application;
const domain = getDomain(fqdn); const isRunning = await checkContainer(engine, id);
const isHttps = fqdn.startsWith('https://'); const domain = getDomain(fqdn);
if (isRunning) { const isHttps = fqdn.startsWith('https://');
if (isHttps) ssls.push({ domain, id, isCoolify: false }); if (isRunning) {
} if (isHttps) ssls.push({ domain, id, isCoolify: false });
if (previews) { }
const host = getEngine(engine); if (previews) {
const { stdout } = await asyncExecShell( const host = getEngine(engine);
`DOCKER_HOST=${host} docker container ls --filter="status=running" --filter="network=${network}" --filter="name=${id}-" --format="{{json .Names}}"` const { stdout } = await asyncExecShell(
); `DOCKER_HOST=${host} docker container ls --filter="status=running" --filter="network=${network}" --filter="name=${id}-" --format="{{json .Names}}"`
const containers = stdout );
.trim() const containers = stdout
.split('\n') .trim()
.filter((a) => a) .split('\n')
.map((c) => c.replace(/"/g, '')); .filter((a) => a)
if (containers.length > 0) { .map((c) => c.replace(/"/g, ''));
for (const container of containers) { if (containers.length > 0) {
let previewDomain = `${container.split('-')[1]}.${domain}`; for (const container of containers) {
if (isHttps) ssls.push({ domain: previewDomain, id, isCoolify: false }); let previewDomain = `${container.split('-')[1]}.${domain}`;
if (isHttps) ssls.push({ domain: previewDomain, id, isCoolify: false });
}
} }
} }
} catch (error) {
console.log(`Error during generateSSLCerts with ${application.fqdn}: ${error}`);
} }
} }
const services = await db.prisma.service.findMany({ const services = await db.prisma.service.findMany({
@@ -145,20 +149,24 @@ export async function generateSSLCerts() {
}); });
for (const service of services) { for (const service of services) {
const { try {
fqdn, const {
id, fqdn,
type, id,
destinationDocker: { engine } type,
} = service; destinationDocker: { engine }
const found = db.supportedServiceTypesAndVersions.find((a) => a.name === type); } = service;
if (found) { const found = db.supportedServiceTypesAndVersions.find((a) => a.name === type);
const domain = getDomain(fqdn); if (found) {
const isHttps = fqdn.startsWith('https://'); const domain = getDomain(fqdn);
const isRunning = await checkContainer(engine, id); const isHttps = fqdn.startsWith('https://');
if (isRunning) { const isRunning = await checkContainer(engine, id);
if (isHttps) ssls.push({ domain, id, isCoolify: false }); if (isRunning) {
if (isHttps) ssls.push({ domain, id, isCoolify: false });
}
} }
} catch (error) {
console.log(`Error during generateSSLCerts with ${service.fqdn}: ${error}`);
} }
} }
const { fqdn } = await db.prisma.setting.findFirst(); const { fqdn } = await db.prisma.setting.findFirst();