From 20f594c66c8c602c32bddc561d735f507983cf1a Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 28 Sep 2022 09:30:57 +0200 Subject: [PATCH 1/6] chore: version++ --- apps/api/src/lib/common.ts | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/api/src/lib/common.ts b/apps/api/src/lib/common.ts index 5435e976e..6f819433e 100644 --- a/apps/api/src/lib/common.ts +++ b/apps/api/src/lib/common.ts @@ -21,7 +21,7 @@ import { scheduler } from './scheduler'; import { supportedServiceTypesAndVersions } from './services/supportedVersions'; import { includeServices } from './services/common'; -export const version = '3.10.9'; +export const version = '3.10.10'; export const isDev = process.env.NODE_ENV === 'development'; const algorithm = 'aes-256-ctr'; diff --git a/package.json b/package.json index 50a447f4c..386613892 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "coolify", "description": "An open-source & self-hostable Heroku / Netlify alternative.", - "version": "3.10.9", + "version": "3.10.10", "license": "Apache-2.0", "repository": "github:coollabsio/coolify", "scripts": { From 96f2660b98b72aaabf012f6f05153317251fb925 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 28 Sep 2022 09:47:05 +0200 Subject: [PATCH 2/6] ui: loading button --- apps/ui/src/routes/index.svelte | 138 +++++++++++++++++++++++--------- 1 file changed, 100 insertions(+), 38 deletions(-) diff --git a/apps/ui/src/routes/index.svelte b/apps/ui/src/routes/index.svelte index 4b41d56e5..c349b2135 100644 --- a/apps/ui/src/routes/index.svelte +++ b/apps/ui/src/routes/index.svelte @@ -41,25 +41,44 @@ let numberOfGetStatus = 0; let status: any = {}; + let noInitialStatus: any = { + applications: false, + services: false, + databases: false + }; + let loading = { + applications: false, + services: false, + databases: false + }; doSearch(); async function refreshStatusApplications() { + loading.applications = true; + noInitialStatus.applications = false; numberOfGetStatus = 0; for (const application of applications) { - getStatus(application, true); + await getStatus(application, true); } + loading.applications = false; } async function refreshStatusServices() { + loading.services = true; + noInitialStatus.services = false; numberOfGetStatus = 0; for (const service of services) { - getStatus(service, true); + await getStatus(service, true); } + loading.services = false; } async function refreshStatusDatabases() { + loading.databases = true; + noInitialStatus.databases = false; numberOfGetStatus = 0; for (const database of databases) { - getStatus(database, true); + await getStatus(database, true); } + loading.databases = false; } function setInitials(onlyOthers: boolean = false) { return { @@ -109,9 +128,15 @@ async function getStatus(resources: any, force: boolean = false) { const { id, buildPack, dualCerts, type } = resources; if (buildPack && applications.length > 10 && !force) { + noInitialStatus.applications = true; return; } if (type && services.length > 10 && !force) { + noInitialStatus.services = true; + return; + } + if (databases.length > 10 && !force) { + noInitialStatus.databases = true; return; } if (status[id] && !force) return status[id]; @@ -498,8 +523,12 @@ {#if (filtered.applications.length > 0 && applications.length > 0) || filtered.otherApplications.length > 0}

Applications

- {noInitialStatus.applications ? 'Load Status' : 'Refresh Status'}
{/if} @@ -515,12 +544,16 @@ class="w-full rounded p-5 bg-coolgray-200 hover:bg-green-600 indicator duration-150" > {#await getStatus(application)} - + {:then} - {#if status[application.id] === 'running'} - - {:else} - + {#if !noInitialStatus.applications} + {#if loading.applications} + + {:else if status[application.id] === 'running'} + + {:else} + + {/if} {/if} {/await}
@@ -621,12 +654,16 @@
{#await getStatus(application)} - + {:then} - {#if status[application.id] === 'running'} - - {:else} - + {#if !noInitialStatus.applications} + {#if loading.applications} + + {:else if status[application.id] === 'running'} + + {:else} + + {/if} {/if} {/await}
@@ -708,7 +745,12 @@ {#if (filtered.services.length > 0 && services.length > 0) || filtered.otherServices.length > 0}

Services

- {noInitialStatus.services ? 'Load Status' : 'Refresh Status'}
{/if} @@ -724,12 +766,16 @@ class="w-full rounded p-5 bg-coolgray-200 hover:bg-pink-600 indicator duration-150" > {#await getStatus(service)} - + {:then} - {#if status[service.id] === 'running'} - - {:else} - + {#if !noInitialStatus.services} + {#if loading.services} + + {:else if status[service.id] === 'running'} + + {:else} + + {/if} {/if} {/await}
@@ -796,12 +842,16 @@
{#await getStatus(service)} - + {:then} - {#if status[service.id] === 'running'} - - {:else} - + {#if !noInitialStatus.services} + {#if loading.services} + + {:else if status[service.id] === 'running'} + + {:else} + + {/if} {/if} {/await}
@@ -852,8 +902,12 @@ {#if (filtered.databases.length > 0 && databases.length > 0) || filtered.otherDatabases.length > 0}

Databases

- {noInitialStatus.databases ? 'Load Status' : 'Refresh Status'}
{/if} @@ -869,12 +923,16 @@ class="w-full rounded p-5 bg-coolgray-200 hover:bg-databases indicator duration-150" > {#await getStatus(database)} - + {:then} - {#if status[database.id] === 'running'} - - {:else} - + {#if !noInitialStatus.databases} + {#if loading.databases} + + {:else if status[databases.id] === 'running'} + + {:else} + + {/if} {/if} {/await}
@@ -945,12 +1003,16 @@
{#await getStatus(database)} - + {:then} - {#if status[database.id] === 'running'} - - {:else} - + {#if !noInitialStatus.databases} + {#if loading.databases} + + {:else if status[databases.id] === 'running'} + + {:else} + + {/if} {/if} {/await}
From 9662bc29fb043bd73478accbfa35da94736bd015 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 28 Sep 2022 09:56:27 +0200 Subject: [PATCH 3/6] ui: fix gitlab importer view --- .../[id]/configuration/_GithubRepositories.svelte | 6 +++--- .../[id]/configuration/_GitlabRepositories.svelte | 5 ++++- apps/ui/src/tailwind.css | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/apps/ui/src/routes/applications/[id]/configuration/_GithubRepositories.svelte b/apps/ui/src/routes/applications/[id]/configuration/_GithubRepositories.svelte index 98a984087..193b19791 100644 --- a/apps/ui/src/routes/applications/[id]/configuration/_GithubRepositories.svelte +++ b/apps/ui/src/routes/applications/[id]/configuration/_GithubRepositories.svelte @@ -152,8 +152,8 @@
{:else}
-
-
+
+
-
+
+ Date: Wed, 28 Sep 2022 10:34:27 +0200 Subject: [PATCH 4/6] feat: system-wide github apps --- .../migration.sql | 26 +++++++ apps/api/prisma/schema.prisma | 1 + apps/api/src/routes/api/v1/handlers.ts | 2 +- .../api/src/routes/api/v1/sources/handlers.ts | 11 +-- apps/api/src/routes/api/v1/sources/types.ts | 1 + apps/ui/src/lib/components/Setting.svelte | 3 +- .../routes/applications/[id]/__layout.svelte | 2 +- .../[id]/configuration/source.svelte | 62 +++++++++++++++- apps/ui/src/routes/index.svelte | 67 +++++++++++------ .../ui/src/routes/sources/[id]/_Github.svelte | 73 ++++++++++++++----- .../src/routes/sources/[id]/__layout.svelte | 2 +- 11 files changed, 200 insertions(+), 50 deletions(-) create mode 100644 apps/api/prisma/migrations/20220928083348_system_wide_git_sources/migration.sql diff --git a/apps/api/prisma/migrations/20220928083348_system_wide_git_sources/migration.sql b/apps/api/prisma/migrations/20220928083348_system_wide_git_sources/migration.sql new file mode 100644 index 000000000..a3657504d --- /dev/null +++ b/apps/api/prisma/migrations/20220928083348_system_wide_git_sources/migration.sql @@ -0,0 +1,26 @@ +-- RedefineTables +PRAGMA foreign_keys=OFF; +CREATE TABLE "new_GitSource" ( + "id" TEXT NOT NULL PRIMARY KEY, + "name" TEXT NOT NULL, + "forPublic" BOOLEAN NOT NULL DEFAULT false, + "type" TEXT, + "apiUrl" TEXT, + "htmlUrl" TEXT, + "customPort" INTEGER NOT NULL DEFAULT 22, + "organization" TEXT, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" DATETIME NOT NULL, + "githubAppId" TEXT, + "gitlabAppId" TEXT, + "isSystemWide" BOOLEAN NOT NULL DEFAULT false, + CONSTRAINT "GitSource_gitlabAppId_fkey" FOREIGN KEY ("gitlabAppId") REFERENCES "GitlabApp" ("id") ON DELETE SET NULL ON UPDATE CASCADE, + CONSTRAINT "GitSource_githubAppId_fkey" FOREIGN KEY ("githubAppId") REFERENCES "GithubApp" ("id") ON DELETE SET NULL ON UPDATE CASCADE +); +INSERT INTO "new_GitSource" ("apiUrl", "createdAt", "customPort", "forPublic", "githubAppId", "gitlabAppId", "htmlUrl", "id", "name", "organization", "type", "updatedAt") SELECT "apiUrl", "createdAt", "customPort", "forPublic", "githubAppId", "gitlabAppId", "htmlUrl", "id", "name", "organization", "type", "updatedAt" FROM "GitSource"; +DROP TABLE "GitSource"; +ALTER TABLE "new_GitSource" RENAME TO "GitSource"; +CREATE UNIQUE INDEX "GitSource_githubAppId_key" ON "GitSource"("githubAppId"); +CREATE UNIQUE INDEX "GitSource_gitlabAppId_key" ON "GitSource"("gitlabAppId"); +PRAGMA foreign_key_check; +PRAGMA foreign_keys=ON; diff --git a/apps/api/prisma/schema.prisma b/apps/api/prisma/schema.prisma index d064f707a..4640a4350 100644 --- a/apps/api/prisma/schema.prisma +++ b/apps/api/prisma/schema.prisma @@ -299,6 +299,7 @@ model GitSource { updatedAt DateTime @updatedAt githubAppId String? @unique gitlabAppId String? @unique + isSystemWide Boolean @default(false) gitlabApp GitlabApp? @relation(fields: [gitlabAppId], references: [id]) githubApp GithubApp? @relation(fields: [githubAppId], references: [id]) application Application[] diff --git a/apps/api/src/routes/api/v1/handlers.ts b/apps/api/src/routes/api/v1/handlers.ts index 7b0e9959b..117bb9d13 100644 --- a/apps/api/src/routes/api/v1/handlers.ts +++ b/apps/api/src/routes/api/v1/handlers.ts @@ -135,7 +135,7 @@ export async function showDashboard(request: FastifyRequest) { include: { destinationDocker: true, teams: true }, }); const gitSources = await prisma.gitSource.findMany({ - where: { teams: { some: { id: teamId === "0" ? undefined : teamId } } }, + where: { OR: [{ teams: { some: { id: teamId === "0" ? undefined : teamId } } }, { isSystemWide: true }] }, include: { teams: true }, }); const destinations = await prisma.destinationDocker.findMany({ diff --git a/apps/api/src/routes/api/v1/sources/handlers.ts b/apps/api/src/routes/api/v1/sources/handlers.ts index 8a1c19987..b67ab7eb4 100644 --- a/apps/api/src/routes/api/v1/sources/handlers.ts +++ b/apps/api/src/routes/api/v1/sources/handlers.ts @@ -9,7 +9,7 @@ export async function listSources(request: FastifyRequest) { try { const teamId = request.user?.teamId; const sources = await prisma.gitSource.findMany({ - where: { teams: { some: { id: teamId === '0' ? undefined : teamId } } }, + where: { OR: [{ teams: { some: { id: teamId === "0" ? undefined : teamId } } }, { isSystemWide: true }] }, include: { teams: true, githubApp: true, gitlabApp: true } }); return { @@ -22,11 +22,11 @@ export async function listSources(request: FastifyRequest) { export async function saveSource(request, reply) { try { const { id } = request.params - let { name, htmlUrl, apiUrl, customPort } = request.body + let { name, htmlUrl, apiUrl, customPort, isSystemWide } = request.body if (customPort) customPort = Number(customPort) await prisma.gitSource.update({ where: { id }, - data: { name, htmlUrl, apiUrl, customPort } + data: { name, htmlUrl, apiUrl, customPort, isSystemWide } }); return reply.code(201).send() } catch ({ status, message }) { @@ -56,7 +56,7 @@ export async function getSource(request: FastifyRequest) { } const source = await prisma.gitSource.findFirst({ - where: { id, teams: { some: { id: teamId === '0' ? undefined : teamId } } }, + where: { id, OR: [{ teams: { some: { id: teamId === "0" ? undefined : teamId } } }, { isSystemWide: true }] }, include: { githubApp: true, gitlabApp: true } }); if (!source) { @@ -104,7 +104,7 @@ export async function saveGitHubSource(request: FastifyRequest const { teamId } = request.user const { id } = request.params - let { name, htmlUrl, apiUrl, organization, customPort } = request.body + let { name, htmlUrl, apiUrl, organization, customPort, isSystemWide } = request.body if (customPort) customPort = Number(customPort) if (id === 'new') { @@ -117,6 +117,7 @@ export async function saveGitHubSource(request: FastifyRequest apiUrl, organization, customPort, + isSystemWide, type: 'github', teams: { connect: { id: teamId } } } diff --git a/apps/api/src/routes/api/v1/sources/types.ts b/apps/api/src/routes/api/v1/sources/types.ts index a748b3943..bb65c7d85 100644 --- a/apps/api/src/routes/api/v1/sources/types.ts +++ b/apps/api/src/routes/api/v1/sources/types.ts @@ -7,6 +7,7 @@ export interface SaveGitHubSource extends OnlyId { apiUrl: string, organization: string, customPort: number, + isSystemWide: boolean } } export interface SaveGitLabSource extends OnlyId { diff --git a/apps/ui/src/lib/components/Setting.svelte b/apps/ui/src/lib/components/Setting.svelte index d4db07e91..18404684d 100644 --- a/apps/ui/src/lib/components/Setting.svelte +++ b/apps/ui/src/lib/components/Setting.svelte @@ -3,6 +3,7 @@ import Tooltip from './Tooltip.svelte'; export let id: any; + export let customClass: any = null; export let setting: any; export let title: any; export let description: any; @@ -24,7 +25,7 @@
-
+
Force Redeploy (without cache) - {:else if $isDeploymentEnabled} + {:else if $isDeploymentEnabled && !$page.url.pathname.startsWith(`/applications/${id}/configuration/`)} @@ -159,9 +183,16 @@ {/if}
- - - + + + - + - - + + changeSettings('isSystemWide', true)} + title="System Wide Git Source" + description="System Wide Git Sources are available to all the users in your Coolify instance.

Use with caution, as it can be a security risk." + />
{:else} diff --git a/apps/ui/src/routes/sources/[id]/__layout.svelte b/apps/ui/src/routes/sources/[id]/__layout.svelte index 47cc8df1f..c4f00a331 100644 --- a/apps/ui/src/routes/sources/[id]/__layout.svelte +++ b/apps/ui/src/routes/sources/[id]/__layout.svelte @@ -53,7 +53,7 @@ } -{#if id !== 'new'} +{#if id !== 'new' && $appSession.teamId === '0'}