feat: cleanup unconfigured applications
This commit is contained in:
parent
60a033f93a
commit
28377a156d
@ -21,7 +21,7 @@ import { scheduler } from './scheduler';
|
|||||||
import { supportedServiceTypesAndVersions } from './services/supportedVersions';
|
import { supportedServiceTypesAndVersions } from './services/supportedVersions';
|
||||||
import { includeServices } from './services/common';
|
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';
|
export const isDev = process.env.NODE_ENV === 'development';
|
||||||
|
|
||||||
const algorithm = 'aes-256-ctr';
|
const algorithm = 'aes-256-ctr';
|
||||||
|
@ -69,6 +69,43 @@ export async function getImages(request: FastifyRequest<GetImages>) {
|
|||||||
return errorHandler({ status, message })
|
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>) {
|
export async function getApplicationStatus(request: FastifyRequest<OnlyId>) {
|
||||||
try {
|
try {
|
||||||
const { id } = request.params
|
const { id } = request.params
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { FastifyPluginAsync } from 'fastify';
|
import { FastifyPluginAsync } from 'fastify';
|
||||||
import { OnlyId } from '../../../../types';
|
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';
|
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.get('/', async (request) => await listApplications(request));
|
||||||
fastify.post<GetImages>('/images', async (request) => await getImages(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.post('/new', async (request, reply) => await newApplication(request, reply));
|
||||||
|
|
||||||
fastify.get<OnlyId>('/:id', async (request) => await getApplication(request));
|
fastify.get<OnlyId>('/:id', async (request) => await getApplication(request));
|
||||||
|
@ -122,7 +122,7 @@ export async function showDashboard(request: FastifyRequest) {
|
|||||||
try {
|
try {
|
||||||
const userId = request.user.userId;
|
const userId = request.user.userId;
|
||||||
const teamId = request.user.teamId;
|
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 } } },
|
where: { teams: { some: { id: teamId === "0" ? undefined : teamId } } },
|
||||||
include: { settings: true, destinationDocker: true, teams: true },
|
include: { settings: true, destinationDocker: true, teams: true },
|
||||||
});
|
});
|
||||||
@ -143,7 +143,15 @@ export async function showDashboard(request: FastifyRequest) {
|
|||||||
include: { teams: true },
|
include: { teams: true },
|
||||||
});
|
});
|
||||||
const settings = await listSettings();
|
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 {
|
return {
|
||||||
|
foundUnconfiguredApplication,
|
||||||
applications,
|
applications,
|
||||||
databases,
|
databases,
|
||||||
services,
|
services,
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
<div class="dropdown dropdown-bottom">
|
<div class="dropdown dropdown-bottom">
|
||||||
<slot>
|
<slot>
|
||||||
<label for="new" tabindex="0" class="btn btn-sm text-sm bg-coollabs hover:bg-coollabs-100">
|
<label for="new" tabindex="0" class="btn btn-sm text-sm bg-coollabs hover:bg-coollabs-100">
|
||||||
Create New Resource <svg
|
<svg
|
||||||
class="h-6 w-6"
|
class="h-6 w-6"
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
fill="none"
|
fill="none"
|
||||||
@ -31,8 +31,8 @@
|
|||||||
stroke-width="2"
|
stroke-width="2"
|
||||||
d="M12 6v6m0 0v6m0-6h6m-6 0H6"
|
d="M12 6v6m0 0v6m0-6h6m-6 0H6"
|
||||||
/></svg
|
/></svg
|
||||||
></label
|
> Create New Resource
|
||||||
>
|
</label>
|
||||||
</slot>
|
</slot>
|
||||||
|
|
||||||
<ul id="new" tabindex="0" class="dropdown-content menu p-2 shadow bg-coolgray-300 rounded w-52">
|
<ul id="new" tabindex="0" class="dropdown-content menu p-2 shadow bg-coolgray-300 rounded w-52">
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
export let applications: any;
|
export let applications: any;
|
||||||
|
export let foundUnconfiguredApplication: boolean;
|
||||||
export let databases: any;
|
export let databases: any;
|
||||||
export let services: any;
|
export let services: any;
|
||||||
export let settings: any;
|
export let settings: any;
|
||||||
@ -28,9 +29,9 @@
|
|||||||
export let destinations: any;
|
export let destinations: any;
|
||||||
|
|
||||||
let filtered: any = setInitials();
|
let filtered: any = setInitials();
|
||||||
import { get } from '$lib/api';
|
import { get, post } from '$lib/api';
|
||||||
import { t } from '$lib/translations';
|
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 { appSession, search } from '$lib/store';
|
||||||
|
|
||||||
import ApplicationsIcons from '$lib/components/svg/applications/ApplicationIcons.svelte';
|
import ApplicationsIcons from '$lib/components/svg/applications/ApplicationIcons.svelte';
|
||||||
@ -325,6 +326,17 @@
|
|||||||
filtered = setInitials();
|
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>
|
</script>
|
||||||
|
|
||||||
<nav class="header">
|
<nav class="header">
|
||||||
@ -334,7 +346,7 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</nav>
|
</nav>
|
||||||
<div class="container lg:mx-auto lg:p-0 px-8 pt-5">
|
<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 ">
|
||||||
<button
|
<button
|
||||||
class="btn btn-sm btn-ghost"
|
class="btn btn-sm btn-ghost"
|
||||||
class:bg-applications={$search === '!app'}
|
class:bg-applications={$search === '!app'}
|
||||||
@ -521,7 +533,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
{#if (filtered.applications.length > 0 && applications.length > 0) || filtered.otherApplications.length > 0}
|
{#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>
|
<h1 class="title lg:text-3xl pr-4">Applications</h1>
|
||||||
<button
|
<button
|
||||||
class="btn btn-sm btn-primary"
|
class="btn btn-sm btn-primary"
|
||||||
@ -530,6 +542,14 @@
|
|||||||
on:click={refreshStatusApplications}
|
on:click={refreshStatusApplications}
|
||||||
>{noInitialStatus.applications ? 'Load Status' : 'Refresh Status'}</button
|
>{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>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
{#if filtered.applications.length > 0 && applications.length > 0}
|
{#if filtered.applications.length > 0 && applications.length > 0}
|
||||||
@ -559,7 +579,7 @@
|
|||||||
<div class="w-full flex flex-row">
|
<div class="w-full flex flex-row">
|
||||||
<ApplicationsIcons {application} isAbsolute={true} />
|
<ApplicationsIcons {application} isAbsolute={true} />
|
||||||
<div class="w-full flex flex-col">
|
<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}
|
{application.name}
|
||||||
{#if application.settings?.isBot}
|
{#if application.settings?.isBot}
|
||||||
<span class="text-xs badge bg-coolblack border-none text-applications"
|
<span class="text-xs badge bg-coolblack border-none text-applications"
|
||||||
@ -666,7 +686,7 @@
|
|||||||
<div class="w-full flex flex-row">
|
<div class="w-full flex flex-row">
|
||||||
<ApplicationsIcons {application} isAbsolute={true} />
|
<ApplicationsIcons {application} isAbsolute={true} />
|
||||||
<div class="w-full flex flex-col">
|
<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}
|
{application.name}
|
||||||
{#if application.settings?.isBot}
|
{#if application.settings?.isBot}
|
||||||
<span class="text-xs badge bg-coolblack border-none text-applications">BOT</span
|
<span class="text-xs badge bg-coolblack border-none text-applications">BOT</span
|
||||||
@ -778,7 +798,7 @@
|
|||||||
<div class="w-full flex flex-row">
|
<div class="w-full flex flex-row">
|
||||||
<ServiceIcons type={service.type} isAbsolute={true} />
|
<ServiceIcons type={service.type} isAbsolute={true} />
|
||||||
<div class="w-full flex flex-col">
|
<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">
|
<div class="h-10 text-xs">
|
||||||
{#if service?.fqdn}
|
{#if service?.fqdn}
|
||||||
<h2>{service?.fqdn.replace('https://', '').replace('http://', '')}</h2>
|
<h2>{service?.fqdn.replace('https://', '').replace('http://', '')}</h2>
|
||||||
@ -851,7 +871,7 @@
|
|||||||
<div class="w-full flex flex-row">
|
<div class="w-full flex flex-row">
|
||||||
<ServiceIcons type={service.type} isAbsolute={true} />
|
<ServiceIcons type={service.type} isAbsolute={true} />
|
||||||
<div class="w-full flex flex-col">
|
<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">
|
<div class="h-10 text-xs">
|
||||||
{#if service?.fqdn}
|
{#if service?.fqdn}
|
||||||
<h2>{service?.fqdn.replace('https://', '').replace('http://', '')}</h2>
|
<h2>{service?.fqdn.replace('https://', '').replace('http://', '')}</h2>
|
||||||
@ -933,7 +953,7 @@
|
|||||||
<DatabaseIcons type={database.type} isAbsolute={true} />
|
<DatabaseIcons type={database.type} isAbsolute={true} />
|
||||||
<div class="w-full flex flex-col">
|
<div class="w-full flex flex-col">
|
||||||
<div class="h-10">
|
<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">
|
<div class="h-10 text-xs">
|
||||||
{#if database?.version}
|
{#if database?.version}
|
||||||
<h2 class="">{database?.version}</h2>
|
<h2 class="">{database?.version}</h2>
|
||||||
@ -1010,7 +1030,7 @@
|
|||||||
<DatabaseIcons type={database.type} isAbsolute={true} />
|
<DatabaseIcons type={database.type} isAbsolute={true} />
|
||||||
<div class="w-full flex flex-col">
|
<div class="w-full flex flex-col">
|
||||||
<div class="h-10">
|
<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">
|
<div class="h-10 text-xs">
|
||||||
{#if database?.version}
|
{#if database?.version}
|
||||||
<h2 class="">{database?.version}</h2>
|
<h2 class="">{database?.version}</h2>
|
||||||
@ -1129,7 +1149,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="w-full flex flex-col">
|
<div class="w-full flex flex-col">
|
||||||
<div class="h-10">
|
<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}
|
{#if source.teams.length > 0 && source.teams[0]?.name}
|
||||||
<div class="truncate text-xs">{source.teams[0]?.name}</div>
|
<div class="truncate text-xs">{source.teams[0]?.name}</div>
|
||||||
{/if}
|
{/if}
|
||||||
@ -1218,7 +1238,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="w-full flex flex-col">
|
<div class="w-full flex flex-col">
|
||||||
<div class="h-10">
|
<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}
|
{#if source.teams.length > 0 && source.teams[0]?.name}
|
||||||
<div class="truncate text-xs">{source.teams[0]?.name}</div>
|
<div class="truncate text-xs">{source.teams[0]?.name}</div>
|
||||||
{/if}
|
{/if}
|
||||||
@ -1292,7 +1312,7 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
<div class="w-full flex flex-col">
|
<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">
|
<div class="h-10 text-xs">
|
||||||
{#if $appSession.teamId === '0' && destination.remoteVerified === false && destination.remoteEngine}
|
{#if $appSession.teamId === '0' && destination.remoteVerified === false && destination.remoteEngine}
|
||||||
<h2 class="text-red-500">Not verified yet</h2>
|
<h2 class="text-red-500">Not verified yet</h2>
|
||||||
@ -1373,7 +1393,7 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
<div class="w-full flex flex-col">
|
<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">
|
<div class="h-10 text-xs">
|
||||||
{#if $appSession.teamId === '0' && destination.remoteVerified === false && destination.remoteEngine}
|
{#if $appSession.teamId === '0' && destination.remoteVerified === false && destination.remoteEngine}
|
||||||
<h2 class="text-red-500">Not verified yet</h2>
|
<h2 class="text-red-500">Not verified yet</h2>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "coolify",
|
"name": "coolify",
|
||||||
"description": "An open-source & self-hostable Heroku / Netlify alternative.",
|
"description": "An open-source & self-hostable Heroku / Netlify alternative.",
|
||||||
"version": "3.10.11",
|
"version": "3.10.12",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"repository": "github:coollabsio/coolify",
|
"repository": "github:coollabsio/coolify",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user