feat: more cdkey

This commit is contained in:
Hamcha 2024-04-07 18:49:04 +02:00
parent aae230a265
commit daf7eb4e26
Signed by: hamcha
GPG Key ID: 1669C533B8CF6D89
5 changed files with 87 additions and 94 deletions

View File

@ -3,7 +3,7 @@
* https://raw.githubusercontent.com/immich-app/immich/main/docker/docker-compose.yml * https://raw.githubusercontent.com/immich-app/immich/main/docker/docker-compose.yml
*/ */
import { Stack, Service, deploySingle } from "../mod.ts"; import { Stack } from "../mod.ts";
interface ImmichStackOptions { interface ImmichStackOptions {
stackName?: string; stackName?: string;
@ -16,8 +16,11 @@ interface ImmichStackOptions {
}; };
} }
function immichStack(props: ImmichStackOptions) { export class ImmichStack extends Stack {
const redis = new Service("redis", { constructor(props: ImmichStackOptions) {
super(props.stackName ?? "immich");
const redis = this.addService("redis", {
image: "registry.hub.docker.com/library/redis:6.2-alpine", image: "registry.hub.docker.com/library/redis:6.2-alpine",
restart: "unless-stopped", restart: "unless-stopped",
}); });
@ -29,7 +32,7 @@ function immichStack(props: ImmichStackOptions) {
database: "postgres", database: "postgres",
}; };
const database = new Service("database", { const database = this.addService("database", {
image: "registry.hub.docker.com/tensorchord/pgvecto-rs:pg14-v0.2.0", image: "registry.hub.docker.com/tensorchord/pgvecto-rs:pg14-v0.2.0",
restart: "unless-stopped", restart: "unless-stopped",
environment: { environment: {
@ -48,7 +51,7 @@ function immichStack(props: ImmichStackOptions) {
REDIS_HOSTNAME: redis.name, REDIS_HOSTNAME: redis.name,
}; };
const immichServer = new Service("immich-server", { const immichServer = this.addService("immich-server", {
image: `ghcr.io/immich-app/immich-server:${ image: `ghcr.io/immich-app/immich-server:${
props.immichVersion ?? "release" props.immichVersion ?? "release"
}`, }`,
@ -60,7 +63,7 @@ function immichStack(props: ImmichStackOptions) {
ports: ["2283:3001"], ports: ["2283:3001"],
}); });
const immichMicroservices = new Service("immich-microservices", { const immichMicroservices = this.addService("immich-microservices", {
image: `ghcr.io/immich-app/immich-server:${ image: `ghcr.io/immich-app/immich-server:${
props.immichVersion ?? "release" props.immichVersion ?? "release"
}`, }`,
@ -71,25 +74,14 @@ function immichStack(props: ImmichStackOptions) {
environment: immichEnv, environment: immichEnv,
}); });
const immichMachineLearning = new Service("immich-machine-learning", { const immichMachineLearning = this.addService("immich-machine-learning", {
image: `ghcr.io/immich-app/immich-machine-learning:${ image: `ghcr.io/immich-app/immich-machine-learning:${
props.immichVersion ?? "release" props.immichVersion ?? "release"
}`, }`,
// todo volumes // todo volumes
environment: immichEnv, environment: immichEnv,
}); });
}
return new Stack(props.stackName ?? "immich", {
services: [
redis,
database,
immichServer,
immichMicroservices,
immichMachineLearning,
],
});
} }
const stack = immichStack({ immichVersion: "v1.100.0" }); const stack = new ImmichStack({ immichVersion: "v1.100.0" });
deploySingle(stack);

1
mod.ts
View File

@ -1,2 +1 @@
export * from "./src/components/mod.ts"; export * from "./src/components/mod.ts";
export * from "./src/deployment.ts";

View File

@ -1,2 +1 @@
export * from "./stack.ts"; export * from "./stack.ts";
export * from "./service.ts";

View File

@ -1,19 +1,28 @@
import { ComposeSpecification } from "../compose-schema.ts"; import { ComposeSpecification, DefinitionsService } from "../compose-schema.ts";
import { registerDeployment } from "../deployment.ts";
import { Service } from "./service.ts"; import { Service } from "./service.ts";
interface StackOptions { export class Stack {
services: Service[]; private services: Record<string, Service> = {};
constructor(public name: string) {
registerDeployment(this);
} }
export class Stack { public addService(name: string, service: DefinitionsService): Service {
constructor(public name: string, public options: StackOptions) {} if (this.services[name]) {
throw new Error(`Service ${name} already defined.`);
}
this.services[name] = new Service(name, service);
return this.services[name];
}
public toComposeFile(): ComposeSpecification { public toComposeFile(): ComposeSpecification {
const services: ComposeSpecification["services"] = {}; const services: Record<string, DefinitionsService> = {};
for (const service of this.options.services) { for (const [name, service] of Object.entries(this.services)) {
services[service.name] = service.options; services[name] = service.options;
} }
return { return {
version: "3.8", version: "3.8",
services, services,

View File

@ -1,22 +1,16 @@
import { Stack } from "./components/mod.ts"; import { Stack } from "./components/mod.ts";
import { ComposeSpecification } from "./compose-schema.ts"; import { ComposeSpecification } from "./compose-schema.ts";
const deployments: Record<string, ComposeSpecification> = {}; const deployments: Stack[] = [];
let printDeployments = false;
export function deploy(stack: Stack) { export function registerDeployment(stack: Stack) {
deployments[stack.name] = stack.toComposeFile(); deployments.push(stack);
printDeployments = true;
}
export function deploySingle(stack: Stack) {
console.log(JSON.stringify(stack.toComposeFile(), null, 2));
} }
globalThis.addEventListener("unload", () => { globalThis.addEventListener("unload", () => {
if (!printDeployments) { const stacks: Record<string, ComposeSpecification> = {};
return; for (const stack of deployments) {
stacks[stack.name] = stack.toComposeFile();
} }
// Print deployments console.log(JSON.stringify(stacks, null, 2));
console.log(JSON.stringify(deployments, null, 2));
}); });