Pulumi code for my server setup
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

change imports

+42 -42
+2 -1
lib/relay-hosts.ts
··· 1 1 import { JSDOM } from "jsdom"; 2 2 import pMemoize from "p-memoize"; 3 3 4 + const PULSAR = "https://pulsar.feeds.blue"; 5 + 4 6 export const fetchRelays = pMemoize(async () => { 5 - const PULSAR = "https://pulsar.feeds.blue"; 6 7 const res = await fetch(PULSAR); 7 8 if (!res.ok) { 8 9 throw Error(`Error on fetching data from Pulsar: ${res.status}`);
+2 -2
lib/service/mounts.ts
··· 1 - import docker from "@pulumi/docker"; 1 + import { ContainerMount } from "@pulumi/docker/types/input"; 2 2 import { Input, output, Unwrap } from "@pulumi/pulumi"; 3 3 4 4 type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>; ··· 7 7 kind?: Input<"directory" | "file">; 8 8 }; 9 9 10 - export type MountOpts = docker.types.input.ContainerMount & CustomMountOpts; 10 + export type MountOpts = ContainerMount & CustomMountOpts; 11 11 12 12 export function _mount({ 13 13 source,
+2 -2
lib/service/networks.ts
··· 1 - import docker from "@pulumi/docker"; 1 + import { Network } from "@pulumi/docker"; 2 2 import { haringDockerProvider } from "./providers"; 3 3 4 - export const defaultNetwork = new docker.Network( 4 + export const defaultNetwork = new Network( 5 5 "haring", 6 6 { 7 7 name: "haring",
+3 -3
lib/service/providers.ts
··· 1 - import docker from "@pulumi/docker"; 1 + import { Provider } from "@pulumi/docker"; 2 2 3 - export const haringDockerProvider = new docker.Provider("haring", { 3 + export const haringDockerProvider = new Provider("haring", { 4 4 host: "ssh://haring", 5 5 context: "haring", 6 6 }); 7 7 8 - export const kaneelnasDockerProvider = new docker.Provider("kaneelnas", { 8 + export const kaneelnasDockerProvider = new Provider("kaneelnas", { 9 9 host: "ssh://kaneelnas", 10 10 context: "kaneelnas", 11 11 });
+33 -34
lib/service/service.ts
··· 1 - import command from "@pulumi/command"; 2 1 import type { input } from "@pulumi/command/types"; 3 - import docker from "@pulumi/docker"; 4 - import type { Input, Output, Resource } from "@pulumi/pulumi"; 5 - import pulumi, { all, output } from "@pulumi/pulumi"; 2 + import type { CustomResourceOptions, Input, InvokeOptions, Output, Resource } from "@pulumi/pulumi"; 3 + import { all, ComponentResource, output } from "@pulumi/pulumi"; 6 4 import path from "path"; 7 5 import { defaultNetwork } from "./networks"; 8 6 import { convertPorts } from "./ports"; ··· 10 8 import { haringDockerProvider } from "./providers"; 11 9 import { MountOpts } from "./mounts"; 12 10 import { ContainerCapabilities, ContainerPort } from "@pulumi/docker/types/input"; 11 + import { remote, local } from "@pulumi/command"; 12 + import { Container, ContainerArgs, getRegistryImage, RemoteImage } from "@pulumi/docker"; 13 13 14 14 export const defaultConnection = { 15 15 host: getEnv("CONNECTION_HOST"), ··· 22 22 type Port = (number | string | ContainerPort)[]; 23 23 24 24 export type ContainerServiceArgs = Partial< 25 - Omit<docker.ContainerArgs, "ports" | "labels" | "mounts" | "envs" | "capabilities"> & { 25 + Omit<ContainerArgs, "ports" | "labels" | "mounts" | "envs" | "capabilities"> & { 26 26 localImage: Input<string>; 27 27 servicePort: Input<number>; 28 28 subdomain: Input<string>; ··· 42 42 >; 43 43 44 44 // TODO: turn ContainerService into a factory function like https://sst.dev/docs/examples/#api-gateway-auth 45 - class ContainerService extends pulumi.ComponentResource { 46 - public readonly container: Output<docker.Container>; 45 + class ContainerService extends ComponentResource { 46 + public readonly container: Output<Container>; 47 47 public readonly localUrl: Output<string>; 48 48 public readonly ip: Output<string>; 49 - public readonly mounts: docker.Container["mounts"]; 50 - public readonly envs: docker.Container["envs"]; 51 - public readonly capabilities: docker.Container["capabilities"]; 52 - public readonly ports: docker.Container["ports"]; 49 + public readonly mounts: Container["mounts"]; 50 + public readonly envs: Container["envs"]; 51 + public readonly capabilities: Container["capabilities"]; 52 + public readonly ports: Container["ports"]; 53 53 54 54 private commandConnection: Input<input.remote.ConnectionArgs>; 55 55 56 - constructor(name: string, args: ContainerServiceArgs, opts?: pulumi.CustomResourceOptions) { 56 + constructor(name: string, args: ContainerServiceArgs, opts?: CustomResourceOptions) { 57 57 super("bas:docker:ContainerService", name, args, opts); 58 58 59 59 this.commandConnection = args.commandConnection ?? defaultConnection; ··· 69 69 70 70 const image = 71 71 args.localImage ?? 72 - new docker.RemoteImage( 72 + new RemoteImage( 73 73 `${name}`, 74 74 { 75 75 name: output(args.image ?? `lscr.io/linuxserver/${name}`).apply(async (image) => 76 - docker 77 - .getRegistryImage({ name: image }, { parent: this }) 78 - .then((registryImage) => `${registryImage.name}@${registryImage.sha256Digest}`), 76 + getRegistryImage({ name: image }, { parent: this }).then( 77 + (registryImage) => `${registryImage.name}@${registryImage.sha256Digest}`, 78 + ), 79 79 ), 80 80 keepLocally: true, 81 81 }, ··· 201 201 this.capabilities = output(capabilities); 202 202 203 203 this.container = output( 204 - new docker.Container( 204 + new Container( 205 205 name, 206 206 { 207 207 ...args, ··· 220 220 // healthcheck: {tests} 221 221 networksAdvanced: args.networkMode 222 222 ? [] 223 - : pulumi 224 - .output(args.networksAdvanced ?? []) 225 - .apply((networksAdvanced) => [...networksAdvanced, { name: defaultNetwork.name }]), 223 + : output(args.networksAdvanced ?? []).apply((networksAdvanced) => [ 224 + ...networksAdvanced, 225 + { name: defaultNetwork.name }, 226 + ]), 226 227 hosts: args.networkMode 227 228 ? [] 228 - : pulumi 229 - .output(args.hosts ?? []) 230 - .apply((hosts) => [{ host: "host.docker.internal", ip: "host-gateway" }, ...hosts]), 229 + : output(args.hosts ?? []).apply((hosts) => [ 230 + { host: "host.docker.internal", ip: "host-gateway" }, 231 + ...hosts, 232 + ]), 231 233 capabilities, 232 234 }, 233 235 { ··· 241 243 ), 242 244 ); 243 245 244 - this.ip = pulumi 245 - .all([args.networkMode, this.container.networkDatas, defaultNetwork.name]) 246 - .apply(([networkMode, networks, haringNetwork]) => { 246 + this.ip = all([args.networkMode, this.container.networkDatas, defaultNetwork.name]).apply( 247 + ([networkMode, networks, haringNetwork]) => { 247 248 if (networkMode === "host") { 248 249 return "host.docker.internal"; 249 250 } else if (networkMode?.startsWith("container")) { ··· 261 262 } 262 263 263 264 return net.ipAddress; 264 - }); 265 + }, 266 + ); 265 267 266 268 this.registerOutputs(); 267 269 } 268 270 269 271 private createRemoteDir(path: string, name: string, index: number) { 270 - return new command.remote.Command( 272 + return new remote.Command( 271 273 `mkdir-${name}-${index}`, 272 274 { 273 275 connection: this.commandConnection, ··· 291 293 ); 292 294 } 293 295 294 - static async remoteRun( 295 - args: command.local.RunArgs, 296 - opts?: pulumi.InvokeOptions, 297 - ): Promise<command.local.RunResult> { 296 + static async remoteRun(args: local.RunArgs, opts?: InvokeOptions): Promise<local.RunResult> { 298 297 const newArgs = { 299 298 ...args, 300 299 interpreter: [ ··· 302 301 `-p ${defaultConnection.port}`, 303 302 `${defaultConnection.user}@${defaultConnection.host}`, 304 303 ], 305 - } satisfies command.local.RunArgs; 304 + } satisfies local.RunArgs; 306 305 307 - return command.local.run(newArgs, { 306 + return local.run(newArgs, { 308 307 ...opts, 309 308 }); 310 309 }