From 08704c289a1ef979f1f815fc804cc4eaa301a1ca Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Tue, 12 Apr 2022 10:12:46 +0200 Subject: [PATCH 1/4] fix: Proxy --- src/lib/haproxy/configuration.ts | 46 +++++++-------------- src/routes/destinations/[id]/index.json.ts | 1 - src/routes/sources/[id]/newGithubApp.svelte | 1 - 3 files changed, 16 insertions(+), 32 deletions(-) diff --git a/src/lib/haproxy/configuration.ts b/src/lib/haproxy/configuration.ts index f93a34838..8a967befd 100644 --- a/src/lib/haproxy/configuration.ts +++ b/src/lib/haproxy/configuration.ts @@ -1,6 +1,8 @@ import { dev } from '$app/env'; import got, { type Got } from 'got'; import * as db from '$lib/database'; +import mustache from 'mustache'; +import crypto from 'crypto'; import { checkContainer, checkHAProxy } from '.'; import { asyncExecShell, getDomain, getEngine } from '$lib/common'; import { supportedServiceTypesAndVersions } from '$lib/components/common'; @@ -262,36 +264,20 @@ export async function configureHAProxy(): Promise { redirectValue, redirectTo: isWWW ? domain.replace('www.', '') : 'www.' + domain }); - for (const service of services) { - const { fqdn, id, type, destinationDocker, destinationDockerId, updatedAt } = service; - if (destinationDockerId) { - const { engine } = destinationDocker; - const found = supportedServiceTypesAndVersions.find((a) => a.name === type); - if (found) { - const port = found.ports.main; - const publicPort = service[type]?.publicPort; - const isRunning = await checkContainer(engine, id); - if (fqdn) { - const domain = getDomain(fqdn); - const isHttps = fqdn.startsWith('https://'); - const isWWW = fqdn.includes('www.'); - const redirectValue = `${isHttps ? 'https://' : 'http://'}${domain}%[capture.req.uri]`; - if (isRunning) { - data.services.push({ - id, - port, - publicPort, - domain, - isRunning, - isHttps, - redirectValue, - redirectTo: isWWW ? domain.replace('www.', '') : 'www.' + domain, - updatedAt: updatedAt.getTime() - }); - } - } - } + } + const output = mustache.render(template, data); + const newHash = crypto.createHash('md5').update(output).digest('hex'); + const { proxyHash, id } = await db.listSettings(); + if (proxyHash !== newHash) { + await db.prisma.setting.update({ where: { id }, data: { proxyHash: newHash } }); + await haproxy.post(`v2/services/haproxy/configuration/raw`, { + searchParams: { + skip_version: true + }, + body: output, + headers: { + 'Content-Type': 'text/plain' } - } + }); } } diff --git a/src/routes/destinations/[id]/index.json.ts b/src/routes/destinations/[id]/index.json.ts index d64df8c08..aa9be6aea 100644 --- a/src/routes/destinations/[id]/index.json.ts +++ b/src/routes/destinations/[id]/index.json.ts @@ -8,7 +8,6 @@ import type { RequestHandler } from '@sveltejs/kit'; export const get: RequestHandler = async (event) => { const { teamId, status, body } = await getUserDetails(event); if (status === 401) return { status, body }; - console.log(teamId); const { id } = event.params; try { const destination = await db.getDestination({ id, teamId }); diff --git a/src/routes/sources/[id]/newGithubApp.svelte b/src/routes/sources/[id]/newGithubApp.svelte index b6a74c3ba..c8cb4f6f3 100644 --- a/src/routes/sources/[id]/newGithubApp.svelte +++ b/src/routes/sources/[id]/newGithubApp.svelte @@ -36,7 +36,6 @@ export let settings; onMount(() => { const { organization, id, htmlUrl } = source; - console.log(source); const { fqdn } = settings; const host = dev ? 'http://localhost:3000' From 19aca9ab35a744eb6451fd4641568378e4003181 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Tue, 12 Apr 2022 10:13:19 +0200 Subject: [PATCH 2/4] chore: version++ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6069fa22c..9bc02f325 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "coolify", "description": "An open-source & self-hostable Heroku / Netlify alternative.", - "version": "2.4.3", + "version": "2.4.4", "license": "AGPL-3.0", "scripts": { "dev": "docker-compose -f docker-compose-dev.yaml up -d && cross-env NODE_ENV=development & svelte-kit dev", From a4e7c85184de1b2d44a344ffaa3e5d511dc0aa93 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Tue, 12 Apr 2022 10:14:18 +0200 Subject: [PATCH 3/4] Add only amd release --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 9bc02f325..3964bd7ac 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "db:seed": "prisma db seed", "db:migrate": "COOLIFY_DATABASE_URL=file:../db/migration.db prisma migrate dev --skip-seed --name", "release:production:all": "cross-var docker build --platform linux/amd64,linux/arm64 -t coollabsio/coolify:$npm_package_version -t coollabsio/coolify:latest --push .", + "release:production:amd": "cross-var docker build --platform linux/amd64 -t coollabsio/coolify:$npm_package_version -t coollabsio/coolify:latest --push .", "release:staging:all": "cross-var docker build --platform linux/amd64,linux/arm64 -t coollabsio/coolify:$npm_package_version --push .", "release:staging:amd": "cross-var docker build --platform linux/amd64 -t coollabsio/coolify:$npm_package_version --push .", "release:haproxy": "docker build --platform linux/amd64,linux/arm64 -t coollabsio/coolify-haproxy-alpine:latest -t coollabsio/coolify-haproxy-alpine:1.1.0 -f data/haproxy.Dockerfile --push .", From 41bf6b5b860b6a47f41852948ac12f84f5edf0b0 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Tue, 12 Apr 2022 10:47:53 +0200 Subject: [PATCH 4/4] fixes --- package.json | 2 +- pnpm-lock.yaml | 16 ++++++------ src/lib/api.ts | 2 +- src/lib/database/gitSources.ts | 23 ++++++++--------- src/lib/queues/index.ts | 6 +++++ src/routes/sources/[id]/_Github.svelte | 35 +++++++++++++++++++++++++- src/routes/sources/[id]/github.json.ts | 4 +-- 7 files changed, 63 insertions(+), 25 deletions(-) diff --git a/package.json b/package.json index 3964bd7ac..ac318b2ad 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,7 @@ "@prisma/client": "3.11.1", "@sentry/node": "6.19.6", "bcryptjs": "^2.4.3", - "bullmq": "1.79.0", + "bullmq": "1.80.0", "compare-versions": "4.1.3", "cookie": "0.4.2", "cuid": "2.1.8", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5577cc3fa..66d7c480f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5,7 +5,7 @@ specifiers: '@prisma/client': 3.11.1 '@sentry/node': 6.19.6 '@sveltejs/adapter-node': 1.0.0-next.73 - '@sveltejs/kit': 1.0.0-next.310 + '@sveltejs/kit': 1.0.0-next.303 '@types/js-cookie': 3.0.1 '@types/js-yaml': 4.0.5 '@types/node': 17.0.23 @@ -15,7 +15,7 @@ specifiers: '@zerodevx/svelte-toast': 0.7.1 autoprefixer: 10.4.4 bcryptjs: ^2.4.3 - bullmq: 1.79.0 + bullmq: 1.78.1 compare-versions: 4.1.3 cookie: 0.4.2 cross-env: 7.0.3 @@ -60,7 +60,7 @@ dependencies: '@prisma/client': 3.11.1_prisma@3.11.1 '@sentry/node': 6.19.6 bcryptjs: 2.4.3 - bullmq: 1.79.0 + bullmq: 1.78.1 compare-versions: 4.1.3 cookie: 0.4.2 cuid: 2.1.8 @@ -82,7 +82,7 @@ dependencies: devDependencies: '@sveltejs/adapter-node': 1.0.0-next.73 - '@sveltejs/kit': 1.0.0-next.310_svelte@3.47.0 + '@sveltejs/kit': 1.0.0-next.303_svelte@3.47.0 '@types/js-cookie': 3.0.1 '@types/js-yaml': 4.0.5 '@types/node': 17.0.23 @@ -374,10 +374,10 @@ packages: tiny-glob: 0.2.9 dev: true - /@sveltejs/kit/1.0.0-next.310_svelte@3.47.0: + /@sveltejs/kit/1.0.0-next.303_svelte@3.47.0: resolution: { - integrity: sha512-pTyMyaoyHS+V5cQZIQMfQXmLkhw1VaRwT9avOSgwDc0QBpnNw2LdzwoPYsUr96ca5B6cfT3SMUNolxErTNHmPQ== + integrity: sha512-WdxDc8OiF1WEd/bEza7CBdzA+3qIcCi1GKBj/gieKX9I3N8iDJt/Cg2POrLo9wQoJ47nZcAd1eOhfr7XEX1aIQ== } engines: { node: '>=14.13' } hasBin: true @@ -1669,10 +1669,10 @@ packages: ieee754: 1.2.1 dev: false - /bullmq/1.79.0: + /bullmq/1.78.1: resolution: { - integrity: sha512-rVtNCDpcWdc+U1MinRtvhJv+GBFNkz0Q3Unf20010qIC6Pj+O2kkIUeepBkCmMNz6G9abrhsee2PheGRJ32+sw== + integrity: sha512-er45mM8nGhgA83EVCJ4PNxPyDSzakvoxeFGU4vdSgYeB+SbeFQAlJYmAC50Ms7YFPstm1LeinbVZ+oX/BmBzOg== } dependencies: cron-parser: 4.2.1 diff --git a/src/lib/api.ts b/src/lib/api.ts index 867ed338e..2e9271a6c 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -69,7 +69,7 @@ export function del( export function post( path: string, data: Record, - headers: Record + headers?: Record ): Promise> { return send({ method: 'POST', path, data, headers }); } diff --git a/src/lib/database/gitSources.ts b/src/lib/database/gitSources.ts index 01d36a7da..4d3374344 100644 --- a/src/lib/database/gitSources.ts +++ b/src/lib/database/gitSources.ts @@ -18,18 +18,10 @@ export async function listSources( export async function newSource({ name, - teamId, - type, - htmlUrl, - apiUrl, - organization + teamId }: { name: string; teamId: string; - type: string; - htmlUrl: string; - apiUrl: string; - organization: string; }): Promise { return await prisma.gitSource.create({ data: { @@ -74,8 +66,11 @@ export async function getSource({ if (body?.gitlabApp?.appSecret) body.gitlabApp.appSecret = decrypt(body.gitlabApp.appSecret); return body; } -export async function addGitHubSource({ id, teamId, type, name, htmlUrl, apiUrl }) { - await prisma.gitSource.update({ where: { id }, data: { type, name, htmlUrl, apiUrl } }); +export async function addGitHubSource({ id, teamId, type, name, htmlUrl, apiUrl, organization }) { + await prisma.gitSource.update({ + where: { id }, + data: { type, name, htmlUrl, apiUrl, organization } + }); return await prisma.githubApp.create({ data: { teams: { connect: { id: teamId } }, @@ -123,10 +118,14 @@ export async function configureGitsource({ } export async function updateGitsource({ id, - name + name, + htmlUrl, + apiUrl }: { id: string; name: string; + htmlUrl: string; + apiUrl: string; }): Promise { return await prisma.gitSource.update({ where: { id }, diff --git a/src/lib/queues/index.ts b/src/lib/queues/index.ts index 21a5b0330..694ddc9cc 100644 --- a/src/lib/queues/index.ts +++ b/src/lib/queues/index.ts @@ -2,7 +2,9 @@ import * as Bullmq from 'bullmq'; import { default as ProdBullmq, QueueScheduler } from 'bullmq'; import { dev } from '$app/env'; import { prisma } from '$lib/database'; + import builder from './builder'; +import logger from './logger'; import cleanup from './cleanup'; import proxy from './proxy'; import ssl from './ssl'; @@ -142,5 +144,9 @@ buildWorker.on('failed', async (job: Bullmq.Job, failedReason) => { const buildLogQueueName = 'log_queue'; const buildLogQueue = new Queue(buildLogQueueName, connectionOptions); +const buildLogWorker = new Worker(buildLogQueueName, async (job) => await logger(job), { + concurrency: 1, + ...connectionOptions +}); export { buildQueue, buildLogQueue }; diff --git a/src/routes/sources/[id]/_Github.svelte b/src/routes/sources/[id]/_Github.svelte index a01746267..3390cb712 100644 --- a/src/routes/sources/[id]/_Github.svelte +++ b/src/routes/sources/[id]/_Github.svelte @@ -2,6 +2,7 @@ export let source; import { page, session } from '$app/stores'; import { post } from '$lib/api'; + import Explainer from '$lib/components/Explainer.svelte'; import { errorNotification } from '$lib/form'; import { toast } from '@zerodevx/svelte-toast'; const { id } = $page.params; @@ -51,7 +52,8 @@ type: 'github', name: source.name, htmlUrl: source.htmlUrl.replace(/\/$/, ''), - apiUrl: source.apiUrl.replace(/\/$/, '') + apiUrl: source.apiUrl.replace(/\/$/, ''), + organization: source.organization }); } catch ({ error }) { return errorNotification(error); @@ -97,6 +99,22 @@ +
+
+ + +
+ +
{#if source.apiUrl && source.htmlUrl && source.name}
@@ -135,6 +153,21 @@
+
+
+ +
+ +
{:else} diff --git a/src/routes/sources/[id]/github.json.ts b/src/routes/sources/[id]/github.json.ts index e0f1d3b61..14da66c0a 100644 --- a/src/routes/sources/[id]/github.json.ts +++ b/src/routes/sources/[id]/github.json.ts @@ -9,8 +9,8 @@ export const post: RequestHandler = async (event) => { const { id } = event.params; try { - let { type, name, htmlUrl, apiUrl } = await event.request.json(); - await db.addGitHubSource({ id, teamId, type, name, htmlUrl, apiUrl }); + let { type, name, htmlUrl, apiUrl, organization } = await event.request.json(); + await db.addGitHubSource({ id, teamId, type, name, htmlUrl, apiUrl, organization }); return { status: 201 }; } catch (error) { return ErrorHandler(error);