Compare commits
2 Commits
edf3ce27f2
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 41c37156af | |||
| 344608f056 |
@@ -1,3 +1,5 @@
|
|||||||
|
.src/config.ts
|
||||||
|
|
||||||
# dependencies (bun install)
|
# dependencies (bun install)
|
||||||
node_modules
|
node_modules
|
||||||
|
|
||||||
|
|||||||
+4
-3
@@ -9,11 +9,12 @@ export function formatcaddyfile(proxies: Service[]): string {
|
|||||||
const proxyconfig = proxies.map(proxy => {
|
const proxyconfig = proxies.map(proxy => {
|
||||||
const fullDomain = `${proxy.subdomain}.${proxy.host.baseDomain}`;
|
const fullDomain = `${proxy.subdomain}.${proxy.host.baseDomain}`;
|
||||||
const destination = `${proxy.host.ip}:${proxy.port}`
|
const destination = `${proxy.host.ip}:${proxy.port}`
|
||||||
|
const extra = proxy.caddy?.extra ? `\n\t${proxy.caddy?.extra}` : "";
|
||||||
|
|
||||||
return `${fullDomain} {
|
return `${fullDomain} {\n\treverse_proxy ${destination}
|
||||||
reverse_proxy ${destination}
|
${extra}\n}`
|
||||||
}`
|
|
||||||
}).join('\n');
|
}).join('\n');
|
||||||
|
|
||||||
return output + proxyconfig
|
return output + proxyconfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import { beszelformatter } from "../templates/systemd/beszel-hub.service";
|
||||||
|
import { memosformatter } from "../templates/systemd/memos.service";
|
||||||
|
import { llcppformatter } from "../templates/systemd/start_llcpp.service";
|
||||||
|
import type { Formatter, Service } from "./types";
|
||||||
|
|
||||||
|
//collection of file templates paired with their corresponding service
|
||||||
|
export const formatters: Formatter[] = [
|
||||||
|
{
|
||||||
|
serviceid: "memos",
|
||||||
|
format: (srvc) => memosformatter(srvc),
|
||||||
|
outputpath: (srvc) => `output/systemd/${srvc.name}.service`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
serviceid: "llcpp",
|
||||||
|
format: (srvc) => llcppformatter(srvc),
|
||||||
|
outputpath: (srvc) => `output/systemd/${srvc.name}.service`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
serviceid: "beszel",
|
||||||
|
format: (srvc) => beszelformatter(srvc),
|
||||||
|
outputpath: (srvc) => `output/systemd/${srvc.name}.service`,
|
||||||
|
}
|
||||||
|
|
||||||
|
]
|
||||||
+14
-7
@@ -1,14 +1,10 @@
|
|||||||
import { services } from "./config";
|
import { services } from "./config";
|
||||||
import { formatcaddyfile } from "./formatter";
|
import { formatcaddyfile } from "./formatter";
|
||||||
import type { Service } from "./types";
|
import { formatters } from "./formatters";
|
||||||
import { ConfigValidator } from "./validator";
|
import { ConfigValidator } from "./validator";
|
||||||
import { ConfigWriter } from "./writer";
|
import { ConfigWriter } from "./writer";
|
||||||
|
|
||||||
console.log("Hello via Bun!");
|
console.log("Hello via Bun!");
|
||||||
|
|
||||||
// const vpsservices: Service[] = services.filter(service => service.host.id == "vps-ovh");
|
|
||||||
// console.log(vpsservices);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
entry point / manager
|
entry point / manager
|
||||||
**/
|
**/
|
||||||
@@ -16,11 +12,22 @@ async function main() {
|
|||||||
try {
|
try {
|
||||||
console.log("starting caddy config");
|
console.log("starting caddy config");
|
||||||
|
|
||||||
ConfigValidator.validate(services);
|
ConfigValidator.validatecaddyfile(services);
|
||||||
|
|
||||||
const output = formatcaddyfile(services);
|
const output = formatcaddyfile(services);
|
||||||
|
|
||||||
await ConfigWriter.writeLocal("Caddyfile", output);
|
await ConfigWriter.writeLocal("output/etc/caddy/Caddyfile", output);
|
||||||
|
|
||||||
|
//check for associated formatters for each provider service definition
|
||||||
|
for ( const srvc of services ) {
|
||||||
|
const srvcformatters = formatters.filter(el => el.serviceid == srvc.name);
|
||||||
|
|
||||||
|
for (const formatter of srvcformatters) {
|
||||||
|
const content = formatter.format(srvc);
|
||||||
|
const path = formatter.outputpath(srvc);
|
||||||
|
await ConfigWriter.writeLocal(path, content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
console.log("completed succesfully");
|
console.log("completed succesfully");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ export interface Service {
|
|||||||
workingDir?: string;
|
workingDir?: string;
|
||||||
dataDir?: string;
|
dataDir?: string;
|
||||||
host: Host;
|
host: Host;
|
||||||
|
caddy?: CaddyConfig;
|
||||||
|
systemd?: SystemdConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface StaticSite {
|
export interface StaticSite {
|
||||||
@@ -22,3 +24,20 @@ export interface StaticSite {
|
|||||||
encode?: string;
|
encode?: string;
|
||||||
custom404?: boolean;
|
custom404?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface CaddyConfig {
|
||||||
|
extra?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SystemdConfig {
|
||||||
|
env?: Record<string, string>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
associate a template with a service
|
||||||
|
**/
|
||||||
|
export interface Formatter {
|
||||||
|
serviceid: string
|
||||||
|
format: (service: Service) => string;
|
||||||
|
outputpath: (service: Service) => string;
|
||||||
|
}
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ import type { Service } from "./types";
|
|||||||
should validate config, for now just checks for port collisions
|
should validate config, for now just checks for port collisions
|
||||||
**/
|
**/
|
||||||
export class ConfigValidator {
|
export class ConfigValidator {
|
||||||
static validate(services: Service[]){
|
static validatecaddyfile(services: Service[]){
|
||||||
const hostports = new Map<string, Set<number>>();
|
const hostports = new Map<string, Set<number>>();
|
||||||
|
|
||||||
for (const service of services) {
|
for (const service of services) {
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
/**
|
||||||
|
uses bun to write string to file
|
||||||
|
**/
|
||||||
export class ConfigWriter{
|
export class ConfigWriter{
|
||||||
static async writeLocal(filename: string, content: string) {
|
static async writeLocal(filename: string, content: string) {
|
||||||
await Bun.write(filename, content);
|
await Bun.write(filename, content);
|
||||||
|
|||||||
Reference in New Issue
Block a user