From 494b6b5331d826017afef490780ff062868b5c87 Mon Sep 17 00:00:00 2001 From: Hamcha Date: Sun, 7 Apr 2024 22:45:51 +0200 Subject: [PATCH] docs: add docs! --- README.md | 30 ++++++++++++++++++++++++++++++ src/components/stack.ts | 24 ++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/README.md b/README.md index 35ce3c8..a46050a 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,36 @@ AWS CDK but for normal people. Don't worry about scaling and AWS bills, just ren Also this is only going to be tested with Deno. You deserve better than node. +## Usage + +Use with [staxman](https://git.fromouter.space/staxman) (WIP). + +Usage example (v0): + +```ts +import { Stack } from "../mod.ts"; + +interface RedisStackOptions { + stackName?: string; + redisVersion?: string; +} + +export class RedisStack extends Stack { + constructor(props: ImmichStackOptions) { + super(props.stackName ?? "immich"); + + const redis = this.addService("redis", { + image: `registry.hub.docker.com/library/redis:${props.redisVersion ?? "alpine"}`, + restart: "unless-stopped" + }); + } +} + +const stack = new RedisStack({ redisVersion: "6.2-alpine" }); +``` + +For a more in-depth example, see the example stacks in `example/`. + ## World domination plan Current status: v0 - Annoyingly, this already kinda works! diff --git a/src/components/stack.ts b/src/components/stack.ts index 85263db..096a6a1 100644 --- a/src/components/stack.ts +++ b/src/components/stack.ts @@ -17,6 +17,30 @@ function mapRecordToCompose( ); } +/** + * Stack is a collection of services, networks, and volumes. + * Every stack gets turned into a compose file at the end of the execution. + * To create a stack, define a new class that extends Stack, then + * instantiate the class with the name of the stack. + * + * Example: + * ```ts + * import { Stack } from "../mod.ts"; + * + * class ExampleStack extends Stack { + * constructor(name: string) { + * super(name); + * + * const redis = this.addService("redis", { + * image: "registry.hub.docker.com/library/redis:6.2-alpine", + * restart: "unless-stopped", + * }); + * } + * } + * + * const stack = new ExampleStack("example"); + * ``` + */ export class Stack { private services: Record = {}; private networks: Record = {};