Deployment

An MLambda service builds to one static Linux executable. Its Docker image is Alpine with that one binary; the same image is every role, and its environment decides which one.

The image

The Dockerfile compiles the program with the native Aleph compiler image, then links it statically against musl and OpenSSL on Alpine:

ARG ALEPH_IMAGE=aleph-build

FROM ${ALEPH_IMAGE} AS aleph
WORKDIR /genesis
COPY modules/MLambda.Aleph/stdlib/src           modules/MLambda.Aleph/stdlib/src
COPY modules/MLambda.Actors/MLambda.Actor      modules/MLambda.Actors/MLambda.Actor
COPY modules/MLambda.Actors/MLambda.Actor.Demo modules/MLambda.Actors/MLambda.Actor.Demo
ENV ALEPH_STDLIB=/genesis/modules/MLambda.Aleph/stdlib/src

FROM aleph AS test
RUN aleph-compiler test --project modules/MLambda.Actors/MLambda.Actor \
 && aleph-compiler test --project modules/MLambda.Actors/MLambda.Actor.Demo

FROM aleph AS object
RUN mkdir -p /out \
 && aleph-compiler build --project modules/MLambda.Actors/MLambda.Actor.Demo \
      --triple x86_64-unknown-linux-gnu --release -o /out/mlambda-actor-demo.o

FROM alpine:3.22 AS link
RUN apk add --no-cache gcc musl-dev openssl-dev openssl-libs-static
COPY --from=object /out /out
RUN gcc -static -no-pie /out/mlambda-actor-demo*.o -lssl -lcrypto -lpthread -lm -o /out/mlambda-actor-demo \
 && strip /out/mlambda-actor-demo

FROM alpine:3.22
RUN adduser -D -H actor
COPY --from=link /out/mlambda-actor-demo /usr/local/bin/mlambda-actor-demo
USER actor
ENV DEMO_ROLE=standalone
EXPOSE 5000 5001 5002
ENTRYPOINT ["/usr/local/bin/mlambda-actor-demo"]
Stage What it does
aleph The compiler image with the stdlib and the packages from source
test docker build --target test runs the specs on Linux
object The whole program and its runtime, as one x86-64 object
link A static executable, so the final image needs no libraries
final Alpine, a user, the binary

The build context is the root of the repository that holds MLambda.Aleph and MLambda.Actors side by side. The compiler image is aleph-build, made by MLambda.Aleph’s bootstrap/stage0.sh; pass another with --build-arg ALEPH_IMAGE=.... The demo’s image is about 6 MB.

Settings

Every setting comes from the environment:

Variable Meaning
ACTOR_TOPOLOGY standalone, cluster or hybrid (a service using hostConfigFromEnv)
NODE_ID The node’s name
NODE_HOST The name other nodes reach it by (the compose service name)
NODE_PORT Its port; a hybrid node also uses the next two
SEEDS The cluster nodes, host:port;host:port
ACTOR_SEAL fortress (the default) or open: the open transport, for nodes of one cluster on its own network (see Fortress below)
FORTRESS_IDENTITY The file holding this process’s identity (its key, its certificate, the CA’s public key); a cluster topology sealed by Fortress refuses to start without it
CLUSTER_ID The cluster this node is of. A node that links to other clusters (MESH_SEEDS) names it, or it has no seal and does not start
MESH_SEEDS Other clusters’ nodes, host:port;host:port (default none: every link uses the one seal ACTOR_SEAL names, as before). With ACTOR_SEAL=open the node dials these with Fortress (it then needs FORTRESS_IDENTITY) and every other node open; it takes an open hello as its own cluster’s, and Fortress’s offer only from a host MESH_SEEDS names. With Fortress (ACTOR_SEAL unset or fortress) every link is sealed, inside the cluster and across, and the node meshes the same way. Clusters share their route families and live nodes, never their actors: one cluster owns each route

The topologies in compose

MLambda.Actor.Demo has a compose file per topology. Each ends with a client that runs a scenario and exits with its verdict, so --exit-code-from makes a test of it:

cd MLambda.Actor.Demo
docker compose -f compose.standalone.yml up --build --abort-on-container-exit --exit-code-from standalone
docker compose -f compose.hybrid.yml     up --build --abort-on-container-exit --exit-code-from client
docker compose -f compose.cluster.yml    up --build --abort-on-container-exit --exit-code-from client
docker compose -f compose.fortress.yml   up --build --abort-on-container-exit --exit-code-from client

./test-docker.sh          # the specs on Linux, then every topology

A cluster, as compose.cluster.yml writes it:

x-demo: &demo
  build:
    context: ../../..
    dockerfile: modules/MLambda.Actors/MLambda.Actor.Demo/Dockerfile
    args:
      ALEPH_IMAGE: ${ALEPH_IMAGE:-aleph-build}
  image: mlambda-actor-demo:latest
  networks: [actors]

services:
  cluster-0:
    <<: *demo
    environment:
      DEMO_ROLE: node
      NODE_ID: cluster-0
      NODE_HOST: cluster-0
      NODE_PORT: "5000"
      SEEDS: "cluster-1:5000;cluster-2:5000"
  # cluster-1 and cluster-2 the same, each seeding from the other two

  satellite:
    <<: *demo
    depends_on: [cluster-0, cluster-1, cluster-2]
    environment:
      DEMO_ROLE: satellite
      NODE_ID: satellite
      NODE_HOST: satellite
      NODE_PORT: "5100"
      SEEDS: "cluster-0:5000;cluster-1:5000;cluster-2:5000"

  client:
    <<: *demo
    depends_on: [satellite]
    environment:
      DEMO_ROLE: client
      NODE_ID: client
      NODE_HOST: client
      NODE_PORT: "6000"
      SEEDS: "cluster-0:5000;cluster-1:5000;cluster-2:5000"
      STARTUP_DELAY: "3000"

Fortress

Every connection between nodes is sealed: each side shows its certificate (signed by the cluster’s CA, for its host), the two run an X25519 handshake, and each frame is then ChaCha20-Poly1305 under keys derived from it (HKDF), its sequence number authenticated. A certificate another CA signed, an expired one, or one whose key the peer does not hold is refused; a frame that does not open, or comes out of order, closes the connection. So only the cluster’s nodes read and are heard.

Make the CA once (fortress-issue ca DIR) and keep its key off the nodes; issue each node its identity (fortress-issue nodes DIR CLUSTER DAYS OUT HOST...) and give it the file as FORTRESS_IDENTITY. The compose files’ identities service does both before any node starts; compose.fortress.yml also starts a stranger, whose identity another CA issued, and the cluster does not admit it.

Fortress is for the links that leave a cluster (other regions, other clouds). Nodes of one cluster, on its own network, may talk with the open transport instead: ACTOR_SEAL=open (the kernel chart’s transport: open) gives a node a seal that seals nothing, frames neither encrypted nor authenticated, and no identity. It is chosen only when asked for: a node with no identity and no ACTOR_SEAL still refuses to start, and an open node and a sealed one refuse each other at the handshake.

Persistence across restarts

The actor model keeps state in memory. Services that keep data (MLambda.Data, MLambda.OAuth, MLambda.EBank) mount a volume at /data; their test-docker.sh stops the servers, starts them again on the same volumes, and checks the data is still there.

Building without Docker

aleph build --project MLambda.Actor.Demo -o mlambda-actor-demo

builds a native executable for the machine you are on, with the linker the Aleph installation ships.