/**
* Worked example — the parity benchmark.
*
* Type-checked local configuration/parity example. Loader and graph tests do not
* certify an actual Immich deployment or support on every execution target.
*
* A line-for-line counterpart to Immich's published Compose file
* (`docker/docker-compose.yml`, 4 services). This is the shape Principle 1 is
* measured against: if a self-hostable app plus its database and cache is
* longer or stranger here than in YAML, the premise fails.
*
* It is also the file that proves bind mounts were not optional surface.
* Immich's own comment on the line below is the product:
*
* "Do not edit the next line. If you want to change the media storage
* location on your system, edit the value of UPLOAD_LOCATION in the .env"
*
* The one substantive difference is not length. Immich declares a healthcheck
* on all four services and then gates on a plain `depends_on:` list, so nothing
* waits for anything — the probes exist, are correct, and are never consulted.
* Across the 27 Compose files surveyed, three of the largest do exactly this,
* for 66 edges of "started, not ready". Wiring a probe costs four lines per
* edge in Compose; here it is the default and costs nothing.
*
* Three of the four services here are `healthcheck: { disable: false }` in the
* original — Compose for "use the image's own HEALTHCHECK". That is `ready:
* { inherit: 'image' }`, which is why only Redis spells out a probe below.
*/
import { defineConfig, defineIngress, defineService, secret } from 'alzo';
import type { Node } from 'alzo';
const VERSION = process.env.IMMICH_VERSION ?? 'release';
const local = defineIngress({ hostname: 'example.dev', tls: 'internal' });
function graph(): Node[] {
const dbPassword = secret('DB_PASSWORD');
const database = defineService({
name: 'database',
ports: { pg: 5432 },
provision: { image: 'ghcr.io/immich-app/postgres:14-vectorchord0.4.3' },
env: {
POSTGRES_USER: 'postgres',
POSTGRES_PASSWORD: dbPassword,
POSTGRES_DB: 'immich',
POSTGRES_INITDB_ARGS: '--data-checksums',
},
outputs: ({ hostname, port }) => ({
connectionString: `postgresql://postgres:${dbPassword}@${hostname}:${port.pg}/immich`,
}),
// The user chooses where this lives, which is why it is a bind mount and
// not a named volume. `onRemove` is deliberately unavailable here — this
// directory is not ours to delete.
// oxlint-disable-next-line typescript/no-non-null-assertion -- This vendored parity example intentionally requires the same operator-provided path as upstream Compose; the loader owns missing-value diagnostics.
volumes: { data: { from: process.env.DB_DATA_LOCATION!, to: '/var/lib/postgresql/data' } },
resources: { shmSize: '128mb' },
// `healthcheck: { disable: false }` in the original — the image knows.
ready: { inherit: 'image' },
restart: { policy: 'always' },
});
const redis = defineService({
name: 'redis',
ports: { redis: 6379 },
provision: { image: 'docker.io/valkey/valkey:8-bookworm' },
outputs: ({ hostname, port }) => ({ connectionString: `redis://${hostname}:${port.redis}` }),
// The one service Immich writes a probe for, so we write the same one.
ready: { exec: 'redis-cli ping | grep -q PONG || exit 1', in: 'container' },
restart: { policy: 'always' },
});
const machineLearning = defineService({
name: 'machine-learning',
ports: { http: 3003 },
provision: { image: `ghcr.io/immich-app/immich-machine-learning:${VERSION}` },
// Alzo-managed: a rebuildable cache, so losing it costs a download.
volumes: { modelCache: { path: '/cache', onRemove: 'retain' } },
ready: { inherit: 'image' },
restart: { policy: 'always' },
});
const server = defineService({
name: 'server',
ports: { web: { port: 2283, ingress: local } },
provision: { image: `ghcr.io/immich-app/immich-server:${VERSION}` },
// oxlint-disable-next-line typescript/no-non-null-assertion -- This vendored parity example intentionally requires the same operator-provided path as upstream Compose; the loader owns missing-value diagnostics.
volumes: { upload: { from: process.env.UPLOAD_LOCATION!, to: '/data' } },
// Compose declares two of these three and waits for neither — `depends_on`
// there means "started". The third is ours: `IMMICH_MACHINE_LEARNING_URL`
// below is a dependency whether or not anyone wrote it down.
dependsOn: [database.available, redis.available, machineLearning.available],
env: () => ({
DB_URL: database.outputs.connectionString,
REDIS_URL: redis.outputs.connectionString,
IMMICH_MACHINE_LEARNING_URL: machineLearning.address.http,
}),
ready: { inherit: 'image' },
restart: { policy: 'always' },
});
return [server];
}
export default defineConfig({
name: 'immich',
requires: [{ command: 'docker', hint: 'Install Docker Desktop' }],
nodes: graph,
});