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,80 +16,72 @@ interface ImmichStackOptions {
}; };
} }
function immichStack(props: ImmichStackOptions) { export class ImmichStack extends Stack {
const redis = new Service("redis", { constructor(props: ImmichStackOptions) {
image: "registry.hub.docker.com/library/redis:6.2-alpine", super(props.stackName ?? "immich");
restart: "unless-stopped",
});
// Create default credentials if not provided const redis = this.addService("redis", {
props.postgres ??= { image: "registry.hub.docker.com/library/redis:6.2-alpine",
password: "postgres", restart: "unless-stopped",
username: "postgres", });
database: "postgres",
};
const database = new Service("database", { // Create default credentials if not provided
image: "registry.hub.docker.com/tensorchord/pgvecto-rs:pg14-v0.2.0", props.postgres ??= {
restart: "unless-stopped", password: "postgres",
environment: { username: "postgres",
POSTGRES_USER: props.postgres.username, database: "postgres",
POSTGRES_PASSWORD: props.postgres.password, };
POSTGRES_DB: props.postgres.database,
},
// todo volumes
});
const immichEnv = { const database = this.addService("database", {
DB_HOSTNAME: database.name, image: "registry.hub.docker.com/tensorchord/pgvecto-rs:pg14-v0.2.0",
DB_USERNAME: props.postgres.username, restart: "unless-stopped",
DB_PASSWORD: props.postgres.password, environment: {
DB_DATABASE_NAME: props.postgres.database, POSTGRES_USER: props.postgres.username,
REDIS_HOSTNAME: redis.name, POSTGRES_PASSWORD: props.postgres.password,
}; POSTGRES_DB: props.postgres.database,
},
// todo volumes
});
const immichServer = new Service("immich-server", { const immichEnv = {
image: `ghcr.io/immich-app/immich-server:${ DB_HOSTNAME: database.name,
props.immichVersion ?? "release" DB_USERNAME: props.postgres.username,
}`, DB_PASSWORD: props.postgres.password,
restart: "unless-stopped", DB_DATABASE_NAME: props.postgres.database,
command: ["start.sh", "immich"], REDIS_HOSTNAME: redis.name,
depends_on: [database.name, redis.name], };
// todo volumes
environment: immichEnv,
ports: ["2283:3001"],
});
const immichMicroservices = new Service("immich-microservices", { 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"
}`, }`,
restart: "unless-stopped", restart: "unless-stopped",
command: ["start.sh", "microservices"], command: ["start.sh", "immich"],
depends_on: [database.name, redis.name], depends_on: [database.name, redis.name],
// todo volumes // todo volumes
environment: immichEnv, environment: immichEnv,
}); ports: ["2283:3001"],
});
const immichMachineLearning = new Service("immich-machine-learning", { const immichMicroservices = this.addService("immich-microservices", {
image: `ghcr.io/immich-app/immich-machine-learning:${ image: `ghcr.io/immich-app/immich-server:${
props.immichVersion ?? "release" props.immichVersion ?? "release"
}`, }`,
// todo volumes restart: "unless-stopped",
environment: immichEnv, command: ["start.sh", "microservices"],
}); depends_on: [database.name, redis.name],
// todo volumes
environment: immichEnv,
});
return new Stack(props.stackName ?? "immich", { const immichMachineLearning = this.addService("immich-machine-learning", {
services: [ image: `ghcr.io/immich-app/immich-machine-learning:${
redis, props.immichVersion ?? "release"
database, }`,
immichServer, // todo volumes
immichMicroservices, environment: immichEnv,
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 {
services: Service[];
}
export class Stack { export class Stack {
constructor(public name: string, public options: StackOptions) {} private services: Record<string, Service> = {};
constructor(public name: string) {
registerDeployment(this);
}
public addService(name: string, service: DefinitionsService): Service {
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));
}); });