feat: ipv4 and ipv6

This commit is contained in:
Andras Bacsai 2022-07-22 20:48:04 +00:00
parent bb2864a83f
commit 9e3ba295ea
7 changed files with 35 additions and 5 deletions

View File

@ -0,0 +1,3 @@
-- AlterTable
ALTER TABLE "Setting" ADD COLUMN "ipv4" TEXT;
ALTER TABLE "Setting" ADD COLUMN "ipv6" TEXT;

View File

@ -11,6 +11,8 @@ datasource db {
model Setting { model Setting {
id String @id @default(cuid()) id String @id @default(cuid())
fqdn String? @unique fqdn String? @unique
ipv4 String?
ipv6 String?
isRegistrationEnabled Boolean @default(false) isRegistrationEnabled Boolean @default(false)
dualCerts Boolean @default(false) dualCerts Boolean @default(false)
minPort Int @default(9000) minPort Int @default(9000)

View File

@ -5,7 +5,7 @@ import env from '@fastify/env';
import cookie from '@fastify/cookie'; import cookie from '@fastify/cookie';
import path, { join } from 'path'; import path, { join } from 'path';
import autoLoad from '@fastify/autoload'; import autoLoad from '@fastify/autoload';
import { asyncExecShell, isDev, prisma } from './lib/common'; import { asyncExecShell, isDev, listSettings, prisma } from './lib/common';
import { scheduler } from './lib/scheduler'; import { scheduler } from './lib/scheduler';
declare module 'fastify' { declare module 'fastify' {
@ -101,10 +101,10 @@ fastify.listen({ port, host }, async (err: any, address: any) => {
process.exit(1); process.exit(1);
} }
console.log(`Coolify's API is listening on ${host}:${port}`); console.log(`Coolify's API is listening on ${host}:${port}`);
await initServer() await initServer();
await scheduler.start('deployApplication'); await scheduler.start('deployApplication');
await scheduler.start('cleanupStorage'); await scheduler.start('cleanupStorage');
await scheduler.start('checkProxies') await scheduler.start('checkProxies');
// Check if no build is running // Check if no build is running
@ -130,8 +130,24 @@ fastify.listen({ port, host }, async (err: any, address: any) => {
if (!scheduler.workers.has('deployApplication')) await scheduler.start('deployApplication'); if (!scheduler.workers.has('deployApplication')) await scheduler.start('deployApplication');
} }
}); });
await getIPAddress();
}); });
async function getIPAddress() {
const { publicIpv4, publicIpv6 } = await import('public-ip')
try {
const settings = await listSettings();
if (!settings.ipv4) {
const ipv4 = await publicIpv4({ timeout: 2000 })
await prisma.setting.update({ where: { id: settings.id }, data: { ipv4 } })
}
if (!settings.ipv6) {
const ipv6 = await publicIpv6({ timeout: 2000 })
await prisma.setting.update({ where: { id: settings.id }, data: { ipv6 } })
}
} catch (error) { }
}
async function initServer() { async function initServer() {
try { try {
await asyncExecShell(`docker network create --attachable coolify`); await asyncExecShell(`docker network create --attachable coolify`);

View File

@ -1,10 +1,13 @@
import { FastifyPluginAsync } from 'fastify'; import { FastifyPluginAsync } from 'fastify';
import { errorHandler, version } from '../../../../lib/common'; import { errorHandler, listSettings, version } from '../../../../lib/common';
const root: FastifyPluginAsync = async (fastify): Promise<void> => { const root: FastifyPluginAsync = async (fastify): Promise<void> => {
fastify.get('/', async () => { fastify.get('/', async () => {
const settings = await listSettings()
try { try {
return { return {
ipv4: settings.ipv4,
ipv6: settings.ipv6,
version, version,
whiteLabeled: process.env.COOLIFY_WHITE_LABELED === 'true', whiteLabeled: process.env.COOLIFY_WHITE_LABELED === 'true',
whiteLabeledIcon: process.env.COOLIFY_WHITE_LABELED_ICON, whiteLabeledIcon: process.env.COOLIFY_WHITE_LABELED_ICON,

View File

@ -1,6 +1,8 @@
import { writable, readable, type Writable, type Readable } from 'svelte/store'; import { writable, readable, type Writable, type Readable } from 'svelte/store';
interface AppSession { interface AppSession {
ipv4: string | null,
ipv6: string | null,
version: string | null, version: string | null,
userId: string | null, userId: string | null,
teamId: string | null, teamId: string | null,
@ -17,6 +19,8 @@ interface AppSession {
} }
export const loginEmail: Writable<string | undefined> = writable() export const loginEmail: Writable<string | undefined> = writable()
export const appSession: Writable<AppSession> = writable({ export const appSession: Writable<AppSession> = writable({
ipv4: null,
ipv6: null,
version: null, version: null,
userId: null, userId: null,
teamId: null, teamId: null,

View File

@ -65,6 +65,8 @@
<script lang="ts"> <script lang="ts">
export let baseSettings: any; export let baseSettings: any;
$appSession.ipv4 = baseSettings.ipv4;
$appSession.ipv6 = baseSettings.ipv6;
$appSession.version = baseSettings.version; $appSession.version = baseSettings.version;
$appSession.whiteLabeled = baseSettings.whiteLabeled; $appSession.whiteLabeled = baseSettings.whiteLabeled;
$appSession.whiteLabeledDetails.icon = baseSettings.whiteLabeledIcon; $appSession.whiteLabeledDetails.icon = baseSettings.whiteLabeledIcon;

View File

@ -51,7 +51,7 @@
return `${database.type}://${ return `${database.type}://${
databaseDbUser ? databaseDbUser + ':' : '' databaseDbUser ? databaseDbUser + ':' : ''
}${databaseDbUserPassword}@${ }${databaseDbUserPassword}@${
isPublic ? (settings.fqdn ? getDomain(settings.fqdn) : window.location.hostname) : database.id isPublic ? ($appSession.ipv4) : database.id
}:${isPublic ? database.publicPort : privatePort}/${databaseDefault}`; }:${isPublic ? database.publicPort : privatePort}/${databaseDefault}`;
} }