From b990915b7ad879ee0e7db41ef73b162ba2e8dcef Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 14 Feb 2022 15:58:44 +0100 Subject: [PATCH 1/6] fix: Typo --- src/lib/haproxy/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/haproxy/index.ts b/src/lib/haproxy/index.ts index 0a6bbaa22..56b7ce789 100644 --- a/src/lib/haproxy/index.ts +++ b/src/lib/haproxy/index.ts @@ -460,7 +460,7 @@ export async function startCoolifyProxy(engine) { ); const ip = JSON.parse(Config)[0].Gateway; await asyncExecShell( - `DOCKER_HOST="${host}" docker run -e HAPROXY_USERNAME=${proxyUser} -e HAPROXY_PASSWORD=${proxyPassword} --restarts always --add-host 'host.docker.internal:host-gateway' --add-host 'host.docker.internal:${ip}' -v coolify-ssl-certs:/usr/local/etc/haproxy/ssl --network coolify-infra -p "80:80" -p "443:443" -p "8404:8404" -p "5555:5555" -p "5000:5000" --name coolify-haproxy -d coollabsio/${defaultProxyImage}` + `DOCKER_HOST="${host}" docker run -e HAPROXY_USERNAME=${proxyUser} -e HAPROXY_PASSWORD=${proxyPassword} --restart always --add-host 'host.docker.internal:host-gateway' --add-host 'host.docker.internal:${ip}' -v coolify-ssl-certs:/usr/local/etc/haproxy/ssl --network coolify-infra -p "80:80" -p "443:443" -p "8404:8404" -p "5555:5555" -p "5000:5000" --name coolify-haproxy -d coollabsio/${defaultProxyImage}` ); } await configureNetworkCoolifyProxy(engine); From 53e7e8b77ebf316bf91f2b1728597c1f0d3681c0 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 14 Feb 2022 15:59:00 +0100 Subject: [PATCH 2/6] version bump --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0064b3c9d..fecbaeee7 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "coolify", "description": "An open-source & self-hostable Heroku / Netlify alternative.", - "version": "2.0.8", + "version": "2.0.9", "license": "AGPL-3.0", "scripts": { "dev": "docker compose -f docker-compose-dev.yaml up -d && NODE_ENV=development svelte-kit dev --host 0.0.0.0", From 8fc3760eef9bdf5bc94991a4ffae8e98aa2fe23a Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 14 Feb 2022 16:52:00 +0100 Subject: [PATCH 3/6] fix: Error handling --- src/lib/database/common.ts | 8 +-- src/lib/haproxy/index.ts | 57 +++++-------------- src/routes/services/[id]/__layout.svelte | 34 +++++------ src/routes/services/[id]/minio/start.json.ts | 2 + src/routes/services/[id]/nocodb/start.json.ts | 9 ++- .../[id]/plausibleanalytics/start.json.ts | 8 ++- .../services/[id]/vaultwarden/start.json.ts | 8 ++- .../services/[id]/vscodeserver/start.json.ts | 8 ++- .../services/[id]/wordpress/start.json.ts | 8 ++- 9 files changed, 71 insertions(+), 71 deletions(-) diff --git a/src/lib/database/common.ts b/src/lib/database/common.ts index 23b13ba54..cbbc55624 100644 --- a/src/lib/database/common.ts +++ b/src/lib/database/common.ts @@ -41,7 +41,7 @@ export function ErrorHandler(e) { e = new Error(e.toString()); } let truncatedError = e; - if (e.message.includes('docker run')) { + if (e.message?.includes('docker run')) { let truncatedArray = []; truncatedArray = truncatedError.message.split('-').filter((line) => { if (!line.startsWith('e ')) { @@ -50,7 +50,7 @@ export function ErrorHandler(e) { }); truncatedError.message = truncatedArray.join('-'); } - if (e.message.includes('git clone')) { + if (e.message?.includes('git clone')) { truncatedError.message = 'git clone failed'; } sentry.captureException(truncatedError); @@ -61,11 +61,11 @@ export function ErrorHandler(e) { error: truncatedError.error || truncatedError.message } }; - if (truncatedError.name === 'NotFoundError') { + if (truncatedError?.name === 'NotFoundError') { payload.status = 404; } if (truncatedError instanceof P.PrismaClientKnownRequestError) { - if (truncatedError.code === 'P2002') { + if (truncatedError?.code === 'P2002') { payload.body.message = 'Already exists. Choose another name.'; } } diff --git a/src/lib/haproxy/index.ts b/src/lib/haproxy/index.ts index 56b7ce789..48b492d63 100644 --- a/src/lib/haproxy/index.ts +++ b/src/lib/haproxy/index.ts @@ -107,11 +107,7 @@ export async function forceSSLOffApplication({ domain }) { export async function forceSSLOnApplication({ domain }) { if (!dev) { const haproxy = await haproxyInstance(); - try { - await checkHAProxy(haproxy); - } catch (error) { - return; - } + await checkHAProxy(haproxy); const transactionId = await getNextTransactionId(); try { @@ -162,11 +158,7 @@ export async function forceSSLOnApplication({ domain }) { export async function deleteProxy({ id }) { const haproxy = await haproxyInstance(); - try { - await checkHAProxy(haproxy); - } catch (error) { - return; - } + await checkHAProxy(haproxy); const transactionId = await getNextTransactionId(); try { await haproxy.get(`v2/services/haproxy/configuration/backends/${id}`).json(); @@ -198,11 +190,7 @@ export async function reloadHaproxy(engine) { } export async function configureProxyForApplication({ domain, imageId, applicationId, port }) { const haproxy = await haproxyInstance(); - try { - await checkHAProxy(haproxy); - } catch (error) { - return; - } + await checkHAProxy(haproxy); let serverConfigured = false; let backendAvailable: any = null; @@ -283,11 +271,7 @@ export async function configureProxyForApplication({ domain, imageId, applicatio export async function configureCoolifyProxyOff(fqdn) { const domain = getDomain(fqdn); const haproxy = await haproxyInstance(); - try { - await checkHAProxy(haproxy); - } catch (error) { - return; - } + await checkHAProxy(haproxy); try { const transactionId = await getNextTransactionId(); @@ -308,22 +292,21 @@ export async function configureCoolifyProxyOff(fqdn) { throw error?.response?.body || error; } } -export async function checkHAProxy(haproxy) { +export async function checkHAProxy(haproxy?: any) { if (!haproxy) haproxy = await haproxyInstance(); try { await haproxy.get('v2/info'); } catch (error) { - throw 'HAProxy is not running, but it should be!'; + throw { + message: + 'Coolify Proxy is not running, but it should be!

Start it in the "Destinations" menu.' + }; } } export async function configureCoolifyProxyOn(fqdn) { const domain = getDomain(fqdn); const haproxy = await haproxyInstance(); - try { - await checkHAProxy(haproxy); - } catch (error) { - return; - } + await checkHAProxy(haproxy); let serverConfigured = false; let backendAvailable: any = null; try { @@ -572,12 +555,7 @@ export async function configureSimpleServiceProxyOn({ id, domain, port }) { export async function configureSimpleServiceProxyOff({ domain }) { const haproxy = await haproxyInstance(); - try { - await checkHAProxy(haproxy); - } catch (error) { - return; - } - + await checkHAProxy(haproxy); try { await haproxy.get(`v2/services/haproxy/configuration/backends/${domain}`).json(); const transactionId = await getNextTransactionId(); @@ -596,12 +574,7 @@ export async function configureSimpleServiceProxyOff({ domain }) { export async function removeWwwRedirection(domain) { const haproxy = await haproxyInstance(); - try { - await checkHAProxy(haproxy); - } catch (error) { - return; - } - + await checkHAProxy(); const rules: any = await haproxy .get(`v2/services/haproxy/configuration/http_request_rules`, { searchParams: { @@ -631,11 +604,7 @@ export async function removeWwwRedirection(domain) { } export async function setWwwRedirection(fqdn) { const haproxy = await haproxyInstance(); - try { - await checkHAProxy(haproxy); - } catch (error) { - return; - } + await checkHAProxy(haproxy); const transactionId = await getNextTransactionId(); try { diff --git a/src/routes/services/[id]/__layout.svelte b/src/routes/services/[id]/__layout.svelte index 0beb4df6c..21012ad3e 100644 --- a/src/routes/services/[id]/__layout.svelte +++ b/src/routes/services/[id]/__layout.svelte @@ -110,23 +110,23 @@ loading = false; } } - onMount(async () => { - if ( - service.type && - service.destinationDockerId && - service.version && - service.fqdn && - !isRunning - ) { - try { - await post(`/services/${service.id}/${service.type}/stop.json`, {}); - } catch ({ error }) { - return errorNotification(error); - } finally { - loading = false; - } - } - }); + // onMount(async () => { + // if ( + // service.type && + // service.destinationDockerId && + // service.version && + // service.fqdn && + // !isRunning + // ) { + // try { + // await post(`/services/${service.id}/${service.type}/stop.json`, {}); + // } catch ({ error }) { + // return errorNotification(error); + // } finally { + // loading = false; + // } + // } + // });