An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
feat: cleanup unconfigured applications
Andras Bacsai28377a156dbb
diff --git a/apps/api/src/lib/common.ts b/apps/api/src/lib/common.tsindex d9cb80a58c..e8d12c97e2 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.11';+export const version = '3.10.12';export const isDev = process.env.NODE_ENV === 'development';const algorithm = 'aes-256-ctr';diff --git a/apps/api/src/routes/api/v1/applications/handlers.ts b/apps/api/src/routes/api/v1/applications/handlers.tsindex 70c5937283..895f69dc5e 100644--- a/apps/api/src/routes/api/v1/applications/handlers.ts+++ b/apps/api/src/routes/api/v1/applications/handlers.ts@@ -69,6 +69,43 @@ export async function getImages(request: FastifyRequest<GetImages>) {return errorHandler({ status, message })}}+export async function cleanupUnconfigured(request: FastifyRequest<any>) {+ try {+ let teamId = request.user.teamId+ let applications = await prisma.application.findMany({+ where: { teams: { some: { id: teamId === "0" ? undefined : teamId } } },+ include: { settings: true, destinationDocker: true, teams: true },+ });+ for (const application of applications) {+ if (!application.buildPack || !application.destinationDockerId || !application.branch || (!application.settings?.isBot && !application?.fqdn)) {+ if (application?.destinationDockerId && application.destinationDocker?.network) {+ const { stdout: containers } = await executeDockerCmd({+ dockerId: application.destinationDocker.id,+ command: `docker ps -a --filter network=${application.destinationDocker.network} --filter name=${application.id} --format '{{json .}}'`+ })+ if (containers) {+ const containersArray = containers.trim().split('\n');+ for (const container of containersArray) {+ const containerObj = JSON.parse(container);+ const id = containerObj.ID;+ await removeContainer({ id, dockerId: application.destinationDocker.id });+ }+ }+ }+ await prisma.applicationSettings.deleteMany({ where: { applicationId: application.id } });+ await prisma.buildLog.deleteMany({ where: { applicationId: application.id } });+ await prisma.build.deleteMany({ where: { applicationId: application.id } });+ await prisma.secret.deleteMany({ where: { applicationId: application.id } });+ await prisma.applicationPersistentStorage.deleteMany({ where: { applicationId: application.id } });+ await prisma.applicationConnectedDatabase.deleteMany({ where: { applicationId: application.id } });+ await prisma.application.deleteMany({ where: { id: application.id } });+ }+ }+ return {}+ } catch ({ status, message }) {+ return errorHandler({ status, message })+ }+}export async function getApplicationStatus(request: FastifyRequest<OnlyId>) {try {const { id } = request.paramsdiff --git a/apps/api/src/routes/api/v1/applications/index.ts b/apps/api/src/routes/api/v1/applications/index.tsindex af39e63ce3..cece28f84a 100644--- a/apps/api/src/routes/api/v1/applications/index.ts+++ b/apps/api/src/routes/api/v1/applications/index.ts@@ -1,6 +1,6 @@import { FastifyPluginAsync } from 'fastify';import { OnlyId } from '../../../../types';-import { cancelDeployment, checkDNS, checkDomain, checkRepository, deleteApplication, deleteSecret, deleteStorage, deployApplication, getApplication, getApplicationLogs, getApplicationStatus, getBuildIdLogs, getBuildPack, getBuilds, getGitHubToken, getGitLabSSHKey, getImages, getPreviews, getPreviewStatus, getSecrets, getStorages, getUsage, listApplications, loadPreviews, newApplication, restartApplication, restartPreview, saveApplication, saveApplicationSettings, saveApplicationSource, saveBuildPack, saveConnectedDatabase, saveDeployKey, saveDestination, saveGitLabSSHKey, saveRepository, saveSecret, saveStorage, stopApplication, stopPreviewApplication, updatePreviewSecret, updateSecret } from './handlers';+import { cancelDeployment, checkDNS, checkDomain, checkRepository, cleanupUnconfigured, deleteApplication, deleteSecret, deleteStorage, deployApplication, getApplication, getApplicationLogs, getApplicationStatus, getBuildIdLogs, getBuildPack, getBuilds, getGitHubToken, getGitLabSSHKey, getImages, getPreviews, getPreviewStatus, getSecrets, getStorages, getUsage, listApplications, loadPreviews, newApplication, restartApplication, restartPreview, saveApplication, saveApplicationSettings, saveApplicationSource, saveBuildPack, saveConnectedDatabase, saveDeployKey, saveDestination, saveGitLabSSHKey, saveRepository, saveSecret, saveStorage, stopApplication, stopPreviewApplication, updatePreviewSecret, updateSecret } from './handlers';import type { CancelDeployment, CheckDNS, CheckDomain, CheckRepository, DeleteApplication, DeleteSecret, DeleteStorage, DeployApplication, GetApplicationLogs, GetBuildIdLogs, GetBuilds, GetImages, RestartPreviewApplication, SaveApplication, SaveApplicationSettings, SaveApplicationSource, SaveDeployKey, SaveDestination, SaveSecret, SaveStorage, StopPreviewApplication } from './types';@@ -11,6 +11,8 @@ const root: FastifyPluginAsync = async (fastify): Promise<void> => {fastify.get('/', async (request) => await listApplications(request));fastify.post<GetImages>('/images', async (request) => await getImages(request));+ fastify.post<any>('/cleanup/unconfigured', async (request) => await cleanupUnconfigured(request));+fastify.post('/new', async (request, reply) => await newApplication(request, reply));fastify.get<OnlyId>('/:id', async (request) => await getApplication(request));diff --git a/apps/api/src/routes/api/v1/handlers.ts b/apps/api/src/routes/api/v1/handlers.tsindex 117bb9d137..815ca30006 100644--- a/apps/api/src/routes/api/v1/handlers.ts+++ b/apps/api/src/routes/api/v1/handlers.ts@@ -122,7 +122,7 @@ export async function showDashboard(request: FastifyRequest) {try {const userId = request.user.userId;const teamId = request.user.teamId;- const applications = await prisma.application.findMany({+ let applications = await prisma.application.findMany({where: { teams: { some: { id: teamId === "0" ? undefined : teamId } } },include: { settings: true, destinationDocker: true, teams: true },});@@ -143,7 +143,15 @@ export async function showDashboard(request: FastifyRequest) {include: { teams: true },});const settings = await listSettings();+ let foundUnconfiguredApplication = false;+ for (const application of applications) {+ if (!application.buildPack || !application.destinationDockerId || !application.branch || (!application.settings?.isBot && !application?.fqdn)) {+ foundUnconfiguredApplication = true+ }+ }+return {+ foundUnconfiguredApplication,applications,databases,services,diff --git a/apps/ui/src/routes/_NewResource.svelte b/apps/ui/src/routes/_NewResource.svelteindex e3c494aa39..84e115c5cc 100644--- a/apps/ui/src/routes/_NewResource.svelte+++ b/apps/ui/src/routes/_NewResource.svelte@@ -19,7 +19,7 @@<div class="dropdown dropdown-bottom"><slot><label for="new" tabindex="0" class="btn btn-sm text-sm bg-coollabs hover:bg-coollabs-100">- Create New Resource <svg+ <svgclass="h-6 w-6"xmlns="http://www.w3.org/2000/svg"fill="none"@@ -31,8 +31,8 @@stroke-width="2"d="M12 6v6m0 0v6m0-6h6m-6 0H6"/></svg- ></label- >+ > Create New Resource+ </label></slot><ul id="new" tabindex="0" class="dropdown-content menu p-2 shadow bg-coolgray-300 rounded w-52">diff --git a/apps/ui/src/routes/index.svelte b/apps/ui/src/routes/index.svelteindex 03584247a2..57cd74bafd 100644--- a/apps/ui/src/routes/index.svelte+++ b/apps/ui/src/routes/index.svelte@@ -21,6 +21,7 @@<script lang="ts">export let applications: any;+ export let foundUnconfiguredApplication: boolean;export let databases: any;export let services: any;export let settings: any;@@ -28,9 +29,9 @@export let destinations: any;let filtered: any = setInitials();- import { get } from '$lib/api';+ import { get, post } from '$lib/api';import { t } from '$lib/translations';- import { asyncSleep, getRndInteger } from '$lib/common';+ import { asyncSleep, errorNotification, getRndInteger } from '$lib/common';import { appSession, search } from '$lib/store';import ApplicationsIcons from '$lib/components/svg/applications/ApplicationIcons.svelte';@@ -325,6 +326,17 @@filtered = setInitials();}}+ async function cleanupApplications() {+ try {+ const sure = confirm('Are you sure? This will delete all UNCONFIGURED applications and their data.');+ if (sure) {+ await post(`/applications/cleanup/unconfigured`, {});+ return window.location.reload();+ }+ } catch (error) {+ return errorNotification(error);+ }+ }</script><nav class="header">@@ -334,7 +346,7 @@{/if}</nav><div class="container lg:mx-auto lg:p-0 px-8 pt-5">- <div class="space-x-2 lg:flex lg:justify-center text-center mb-4 ">+ <div class="space-x-2 lg:flex lg:justify-center text-center mb-4 "><buttonclass="btn btn-sm btn-ghost"class:bg-applications={$search === '!app'}@@ -521,7 +533,7 @@</div>{/if}{#if (filtered.applications.length > 0 && applications.length > 0) || filtered.otherApplications.length > 0}- <div class="flex items-center mt-10">+ <div class="flex items-center mt-10 space-x-2"><h1 class="title lg:text-3xl pr-4">Applications</h1><buttonclass="btn btn-sm btn-primary"@@ -530,6 +542,14 @@on:click={refreshStatusApplications}>{noInitialStatus.applications ? 'Load Status' : 'Refresh Status'}</button>+ {#if foundUnconfiguredApplication}+ <button+ class="btn btn-sm"+ class:loading={loading.applications}+ disabled={loading.applications}+ on:click={cleanupApplications}>Cleanup Unconfigured Resources</button+ >+ {/if}</div>{/if}{#if filtered.applications.length > 0 && applications.length > 0}@@ -559,7 +579,7 @@<div class="w-full flex flex-row"><ApplicationsIcons {application} isAbsolute={true} /><div class="w-full flex flex-col">- <h1 class="font-bold text-lg lg:text-xl truncate">+ <h1 class="font-bold text-base truncate">{application.name}{#if application.settings?.isBot}<span class="text-xs badge bg-coolblack border-none text-applications"@@ -666,7 +686,7 @@<div class="w-full flex flex-row"><ApplicationsIcons {application} isAbsolute={true} /><div class="w-full flex flex-col">- <h1 class="font-bold text-lg lg:text-xl truncate">+ <h1 class="font-bold text-base truncate">{application.name}{#if application.settings?.isBot}<span class="text-xs badge bg-coolblack border-none text-applications">BOT</span@@ -778,7 +798,7 @@<div class="w-full flex flex-row"><ServiceIcons type={service.type} isAbsolute={true} /><div class="w-full flex flex-col">- <h1 class="font-bold text-lg lg:text-xl truncate">{service.name}</h1>+ <h1 class="font-bold text-base truncate">{service.name}</h1><div class="h-10 text-xs">{#if service?.fqdn}<h2>{service?.fqdn.replace('https://', '').replace('http://', '')}</h2>@@ -851,7 +871,7 @@<div class="w-full flex flex-row"><ServiceIcons type={service.type} isAbsolute={true} /><div class="w-full flex flex-col">- <h1 class="font-bold text-lg lg:text-xl truncate">{service.name}</h1>+ <h1 class="font-bold text-base truncate">{service.name}</h1><div class="h-10 text-xs">{#if service?.fqdn}<h2>{service?.fqdn.replace('https://', '').replace('http://', '')}</h2>@@ -933,7 +953,7 @@<DatabaseIcons type={database.type} isAbsolute={true} /><div class="w-full flex flex-col"><div class="h-10">- <h1 class="font-bold text-lg lg:text-xl truncate">{database.name}</h1>+ <h1 class="font-bold text-base truncate">{database.name}</h1><div class="h-10 text-xs">{#if database?.version}<h2 class="">{database?.version}</h2>@@ -1010,7 +1030,7 @@<DatabaseIcons type={database.type} isAbsolute={true} /><div class="w-full flex flex-col"><div class="h-10">- <h1 class="font-bold text-lg lg:text-xl truncate">{database.name}</h1>+ <h1 class="font-bold text-base truncate">{database.name}</h1><div class="h-10 text-xs">{#if database?.version}<h2 class="">{database?.version}</h2>@@ -1129,7 +1149,7 @@</div><div class="w-full flex flex-col"><div class="h-10">- <h1 class="font-bold text-lg lg:text-xl truncate">{source.name}</h1>+ <h1 class="font-bold text-base truncate">{source.name}</h1>{#if source.teams.length > 0 && source.teams[0]?.name}<div class="truncate text-xs">{source.teams[0]?.name}</div>{/if}@@ -1218,7 +1238,7 @@</div><div class="w-full flex flex-col"><div class="h-10">- <h1 class="font-bold text-lg lg:text-xl truncate">{source.name}</h1>+ <h1 class="font-bold text-base truncate">{source.name}</h1>{#if source.teams.length > 0 && source.teams[0]?.name}<div class="truncate text-xs">{source.teams[0]?.name}</div>{/if}@@ -1292,7 +1312,7 @@{/if}</div><div class="w-full flex flex-col">- <h1 class="font-bold text-lg lg:text-xl truncate">{destination.name}</h1>+ <h1 class="font-bold text-base truncate">{destination.name}</h1><div class="h-10 text-xs">{#if $appSession.teamId === '0' && destination.remoteVerified === false && destination.remoteEngine}<h2 class="text-red-500">Not verified yet</h2>@@ -1373,7 +1393,7 @@{/if}</div><div class="w-full flex flex-col">- <h1 class="font-bold text-lg lg:text-xl truncate">{destination.name}</h1>+ <h1 class="font-bold text-base truncate">{destination.name}</h1><div class="h-10 text-xs">{#if $appSession.teamId === '0' && destination.remoteVerified === false && destination.remoteEngine}<h2 class="text-red-500">Not verified yet</h2>diff --git a/package.json b/package.jsonindex 12a7d4a113..8c4799c7d2 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.11",+ "version": "3.10.12","license": "Apache-2.0","repository": "github:coollabsio/coolify","scripts": {