Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| edf3ce27f2 |
@@ -1,5 +1,3 @@
|
||||
.src/config.ts
|
||||
|
||||
# dependencies (bun install)
|
||||
node_modules
|
||||
|
||||
|
||||
+4
-5
@@ -9,12 +9,11 @@ export function formatcaddyfile(proxies: Service[]): string {
|
||||
const proxyconfig = proxies.map(proxy => {
|
||||
const fullDomain = `${proxy.subdomain}.${proxy.host.baseDomain}`;
|
||||
const destination = `${proxy.host.ip}:${proxy.port}`
|
||||
const extra = proxy.caddy?.extra ? `\n\t${proxy.caddy?.extra}` : "";
|
||||
|
||||
return `${fullDomain} {\n\treverse_proxy ${destination}
|
||||
${extra}\n}`
|
||||
|
||||
return `${fullDomain} {
|
||||
reverse_proxy ${destination}
|
||||
}`
|
||||
}).join('\n');
|
||||
|
||||
return output + proxyconfig
|
||||
}
|
||||
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
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`,
|
||||
}
|
||||
|
||||
]
|
||||
+7
-14
@@ -1,10 +1,14 @@
|
||||
import { services } from "./config";
|
||||
import { formatcaddyfile } from "./formatter";
|
||||
import { formatters } from "./formatters";
|
||||
import type { Service } from "./types";
|
||||
import { ConfigValidator } from "./validator";
|
||||
import { ConfigWriter } from "./writer";
|
||||
|
||||
console.log("Hello via Bun!");
|
||||
|
||||
// const vpsservices: Service[] = services.filter(service => service.host.id == "vps-ovh");
|
||||
// console.log(vpsservices);
|
||||
|
||||
/**
|
||||
entry point / manager
|
||||
**/
|
||||
@@ -12,23 +16,12 @@ async function main() {
|
||||
try {
|
||||
console.log("starting caddy config");
|
||||
|
||||
ConfigValidator.validatecaddyfile(services);
|
||||
ConfigValidator.validate(services);
|
||||
|
||||
const output = formatcaddyfile(services);
|
||||
|
||||
await ConfigWriter.writeLocal("output/etc/caddy/Caddyfile", output);
|
||||
await ConfigWriter.writeLocal("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");
|
||||
} catch (error) {
|
||||
console.error("error", error);
|
||||
|
||||
@@ -14,8 +14,6 @@ export interface Service {
|
||||
workingDir?: string;
|
||||
dataDir?: string;
|
||||
host: Host;
|
||||
caddy?: CaddyConfig;
|
||||
systemd?: SystemdConfig;
|
||||
}
|
||||
|
||||
export interface StaticSite {
|
||||
@@ -24,20 +22,3 @@ export interface StaticSite {
|
||||
encode?: string;
|
||||
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
|
||||
**/
|
||||
export class ConfigValidator {
|
||||
static validatecaddyfile(services: Service[]){
|
||||
static validate(services: Service[]){
|
||||
const hostports = new Map<string, Set<number>>();
|
||||
|
||||
for (const service of services) {
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
/**
|
||||
uses bun to write string to file
|
||||
**/
|
||||
export class ConfigWriter{
|
||||
static async writeLocal(filename: string, content: string) {
|
||||
await Bun.write(filename, content);
|
||||
|
||||
Reference in New Issue
Block a user