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
wip
Andras Bacsaid61671c1a08a
diff --git a/apps/api/src/routes/api/v1/settings/handlers.ts b/apps/api/src/routes/api/v1/settings/handlers.tsindex e12e05a0ea..96389000b9 100644--- a/apps/api/src/routes/api/v1/settings/handlers.ts+++ b/apps/api/src/routes/api/v1/settings/handlers.ts@@ -3,7 +3,7 @@ import { X509Certificate } from 'node:crypto';import type { FastifyReply, FastifyRequest } from 'fastify';import { asyncExecShell, checkDomainsIsValidInDNS, decrypt, encrypt, errorHandler, isDev, isDNSValid, isDomainConfigured, listSettings, prisma } from '../../../../lib/common';-import { CheckDNS, CheckDomain, DeleteDomain, OnlyIdInBody, SaveSettings, SaveSSHKey } from './types';+import { CheckDNS, CheckDomain, DeleteDomain, OnlyIdInBody, SaveSettings, SaveSSHKey, SetDefaultRegistry } from './types';export async function listAllSettings(request: FastifyRequest) {@@ -11,8 +11,20 @@ export async function listAllSettings(request: FastifyRequest) {const teamId = request.user.teamId;const settings = await listSettings();const sshKeys = await prisma.sshKey.findMany({ where: { team: { id: teamId } } })- const publicRegistries = await prisma.dockerRegistry.findMany({ where: { isSystemWide: true } })- const registries = await prisma.dockerRegistry.findMany({ where: { team: { id: teamId } } })+ let publicRegistries = await prisma.dockerRegistry.findMany({ where: { isSystemWide: true } })+ let privateRegistries = await prisma.dockerRegistry.findMany({ where: { team: { id: teamId } } })+ publicRegistries = publicRegistries.map((registry) => {+ if (registry.password) {+ registry.password = decrypt(registry.password)+ }+ return registry+ })+ privateRegistries = privateRegistries.map((registry) => {+ if (registry.password) {+ registry.password = decrypt(registry.password)+ }+ return registry+ })const unencryptedKeys = []if (sshKeys.length > 0) {for (const key of sshKeys) {@@ -32,7 +44,7 @@ export async function listAllSettings(request: FastifyRequest) {sshKeys: unencryptedKeys,registries: {public: publicRegistries,- private: registries+ private: privateRegistries}}} catch ({ status, message }) {@@ -154,4 +166,23 @@ export async function deleteCertificates(request: FastifyRequest<OnlyIdInBody>,} catch ({ status, message }) {return errorHandler({ status, message })}+}++export async function setDockerRegistry(request: FastifyRequest<SetDefaultRegistry>, reply: FastifyReply) {+ try {+ const teamId = request.user.teamId;+ const { id, username, password } = request.body;++ let encryptedPassword = ''+ if (password) encryptedPassword = encrypt(password)++ if (teamId === '0') {+ await prisma.dockerRegistry.update({ where: { id }, data: { username, password: encryptedPassword } })+ } else {+ await prisma.dockerRegistry.updateMany({ where: { id, teamId }, data: { username, password: encryptedPassword } })+ }+ return reply.code(201).send()+ } catch ({ status, message }) {+ return errorHandler({ status, message })+ }}\ No newline at end of filediff --git a/apps/api/src/routes/api/v1/settings/index.ts b/apps/api/src/routes/api/v1/settings/index.tsindex 45e418b346..c93fa94277 100644--- a/apps/api/src/routes/api/v1/settings/index.ts+++ b/apps/api/src/routes/api/v1/settings/index.ts@@ -2,8 +2,8 @@ import { FastifyPluginAsync } from 'fastify';import { X509Certificate } from 'node:crypto';import { encrypt, errorHandler, prisma } from '../../../../lib/common';-import { checkDNS, checkDomain, deleteCertificates, deleteDomain, deleteSSHKey, listAllSettings, saveSettings, saveSSHKey } from './handlers';-import { CheckDNS, CheckDomain, DeleteDomain, OnlyIdInBody, SaveSettings, SaveSSHKey } from './types';+import { checkDNS, checkDomain, deleteCertificates, deleteDomain, deleteSSHKey, listAllSettings, saveSettings, saveSSHKey, setDockerRegistry } from './handlers';+import { CheckDNS, CheckDomain, DeleteDomain, OnlyIdInBody, SaveSettings, SaveSSHKey, SetDefaultRegistry } from './types';const root: FastifyPluginAsync = async (fastify): Promise<void> => {@@ -20,6 +20,9 @@ const root: FastifyPluginAsync = async (fastify): Promise<void> => {fastify.post<SaveSSHKey>('/sshKey', async (request, reply) => await saveSSHKey(request, reply));fastify.delete<OnlyIdInBody>('/sshKey', async (request, reply) => await deleteSSHKey(request, reply));+ fastify.post<SetDefaultRegistry>('/registry', async (request, reply) => await setDockerRegistry(request, reply));+ // fastify.delete<>('/registry', async (request, reply) => await deleteSSHKey(request, reply));+fastify.post('/upload', async (request) => {try {const teamId = request.user.teamId;@@ -53,7 +56,6 @@ const root: FastifyPluginAsync = async (fastify): Promise<void> => {});fastify.delete<OnlyIdInBody>('/certificate', async (request, reply) => await deleteCertificates(request, reply))- // fastify.get('/certificates', async (request) => await getCertificates(request))};export default root;diff --git a/apps/api/src/routes/api/v1/settings/types.ts b/apps/api/src/routes/api/v1/settings/types.tsindex d68a7bdd3b..850128d513 100644--- a/apps/api/src/routes/api/v1/settings/types.ts+++ b/apps/api/src/routes/api/v1/settings/types.ts@@ -47,4 +47,12 @@ export interface OnlyIdInBody {Body: {id: string}+}++export interface SetDefaultRegistry {+ Body: {+ id: string+ username: string+ password: string+ }}\ No newline at end of filediff --git a/apps/ui/src/lib/components/CopyPasswordField.svelte b/apps/ui/src/lib/components/CopyPasswordField.svelteindex f45adcd3d1..b25817ac19 100644--- a/apps/ui/src/lib/components/CopyPasswordField.svelte+++ b/apps/ui/src/lib/components/CopyPasswordField.svelte@@ -15,7 +15,7 @@export let placeholder = '';export let inputStyle = '';- let disabledClass = 'bg-coolback disabled:bg-coolblack w-full';+ let disabledClass = 'input input-primary bg-coolback disabled:bg-coolblack w-full';let isHttps = browser && window.location.protocol === 'https:';function copyToClipboard() {diff --git a/apps/ui/src/routes/settings/docker.svelte b/apps/ui/src/routes/settings/docker.svelteindex 00548f0a0e..7bef5fc15f 100644--- a/apps/ui/src/routes/settings/docker.svelte+++ b/apps/ui/src/routes/settings/docker.svelte@@ -20,16 +20,17 @@export let registries: any;import { del, post } from '$lib/api';import { errorNotification } from '$lib/common';+ import CopyPasswordField from '$lib/components/CopyPasswordField.svelte';const publicRegistries = registries.public;const privateRegistries = registries.private;let isModalActive = false;let newRegistry = {- name: null,- username: null,- password: null,- url: null,+ name: '',+ username: '',+ password: '',+ url: '',isSystemWide: false};@@ -43,6 +44,11 @@return false;}}+ async function setRegistry(registry: any) {+ try {+ await post(`/settings/registry`, registry);+ } catch (error) {}+ }async function deleteSSHKey(id: string) {const sure = confirm('Are you sure you would like to delete this SSH key?');if (sure) {@@ -80,6 +86,39 @@</thead><tbody>{#each publicRegistries as registry}+ <tr>+ <td>{registry.name}</td>+ <td>{(registry.isSystemWide && 'Yes') || 'No'}</td>+ <td>+ <CopyPasswordField+ name="username"+ id="Username"+ bind:value={registry.username}+ placeholder="Username"+ /></td+ >+ <td+ ><CopyPasswordField+ isPasswordField={true}+ name="Password"+ id="Password"+ bind:value={registry.password}+ placeholder="Password"+ /></td+ >+ <td>+ <button on:click={() => setRegistry(registry)} class="btn btn-sm btn-primary"+ >Set</button+ >+ {#if !registry.isSystemWide}+ <button on:click={() => deleteSSHKey(registry.id)} class="btn btn-sm btn-error"+ >Delete</button+ >+ {/if}+ </td>+ </tr>+ {/each}+ {#each privateRegistries as registry}<tr><td>{registry.name}</td><td>{(registry.isSystemWide && 'Yes') || 'No'}</td>@@ -95,22 +134,6 @@</td></tr>{/each}- {#each privateRegistries as registry}- <tr>- <td>{registry.name}</td>- <td>{(registry.isSystemWide && 'Yes') || 'No'}</td>- <td>{registry.username ?? 'N/A'}</td>- <td>{registry.password ?? 'N/A'}</td>-- <td>- {#if !registry.isSystemWide}- <button on:click={() => deleteSSHKey(registry.id)} class="btn btn-sm btn-error"- >Delete</button- >- {/if}- </td>- </tr>- {/each}</tbody></table></div>@@ -121,49 +144,46 @@<div class="modal modal-bottom sm:modal-middle"><div class="modal-box rounded bg-coolgray-300"><h3 class="font-bold text-lg">Add a Docker Registry to Coolify</h3>- <div >+ <div><form on:submit|preventDefault={handleSubmit}><label for="name" class="label"><span class="label-text">Name</span></label>- <input+ <CopyPasswordFieldid="name"- type="text"+ name="name"bind:value={newRegistry.name}placeholder="Docker Registry Name"- class="input input-primary w-full bg-coolgray-100"required/><label for="url" class="label"><span class="label-text">URL</span></label>- <input+ <CopyPasswordFieldid="url"- type="text"+ name="url"bind:value={newRegistry.url}placeholder="Docker Registry URL"- class="input input-primary w-full bg-coolgray-100"required/><label for="Username" class="label"><span class="label-text">Username</span></label>- <input+ <CopyPasswordFieldid="Username"- type="text"+ name="username"bind:value={newRegistry.username}placeholder="Username"- class="input input-primary w-full bg-coolgray-100"/><label for="Password" class="label"><span class="label-text">Password</span></label>- <input+ <CopyPasswordField+ isPasswordField={true}id="Password"- type="text"+ name="password"bind:value={newRegistry.password}placeholder="Password"- class="input input-primary w-full bg-coolgray-100"/><div class="flex items-center"><label for="systemwide" class="label">