schemaVersion: 1.0 # A parent stack whose only infrastructure is one machine somebody created by hand. # # `fs` + `passphrase` keep this example runnable with no cloud account at all: the # Pulumi state lives next to the checkout and secrets are encrypted with a passphrase. # Swap in `s3-bucket`/`gcp-bucket` + a KMS secrets provider once more than one person # deploys this stack. # # `path` is a plain directory and SC creates it, mode 0700. Writing the Pulumi DIY # URL in full (`file://${git:root}/.sc/state`) means the same thing. # # Add `.sc/state` to .gitignore yourself. Nothing does it for you: `sc init` ignores # only the profile file and `sc secrets reveal` only the revealed secrets file. The # checkpoint under this path carries the stack's inputs and outputs — the deploy key # and the env file among them, encrypted with the passphrase above, which is exactly # as strong as that passphrase and no stronger. provisioner: type: pulumi config: state-storage: type: fs config: path: ${git:root}/.sc/state secrets-provider: type: passphrase config: passPhrase: ${secret:SC_STATE_PASSPHRASE} templates: # Delivery behaviour ONLY. Everything about the machine — provider, size, image, # sshUser, ingress — belongs to the `vm` resource this references by name, exactly as # gcp-gke-autopilot references gkeClusterResource. That split is what lets several # stacks share one machine and lets the delivery strategy change without touching the # machine description. compose-on-vm: type: vm-compose config: vmResource: portal-vm # The default, and the reason this delivery path exists: `sc image ship` streams # the built image over the same SSH connection, so no registry has to be reachable # from the machine. Use `registry` (plus `dockerRegistryURL`, and the username and # password when it is private) if you already have one. imageDelivery: ssh-tar # What happens to images SC did not build — a mongo, a redis, anything with an # `image:` and no build context in your compose file. `ship` (the default under # `ssh-tar`) has the deploy runner pull them and stream them to the machine in # the same way, in ONE stream alongside your own image: that is what makes the # promise above true, because otherwise the machine still had to reach Docker # Hub for every third-party image. `pull` leaves them to the machine. # # Pin third-party tags (`mongo:7.0.14`, not `mongo:7`) when you ship them: the # re-ship is triggered by the reference, so a tag that moves upstream is not # noticed. And `docker login` on the runner before `sc deploy` if any of them is # private — the ship pulls only what the runner does not already have. externalImages: ship # `blue-green` (default) brings the new slot up beside the old one and gates on its # health before stopping the old one. `recreate` stops first — a few seconds of 502 # in exchange for not running both slots at once, which is the honest choice on a # machine with 2 GB of RAM. strategy: blue-green # Previous versions kept on the machine for rollback. The image is already there, # which is what makes rollback on a VM faster than in Kubernetes. keepImages: 3 resources: resources: staging: template: compose-on-vm resources: portal-vm: type: vm config: # `byo` is the zeroth cloud: SC does not create the machine, it only connects # to one you created in the console (Cloud.ru, VK Cloud, MWS, a rack — it does # not matter). The cloud-specific drivers (`cloudru-vm`, `yc-vm`, …) create the # machine themselves and refuse `hosts:`. provider: byo hosts: - address: 203.0.113.10 # Defaults to `sc`. Use the image's stock account (`ubuntu`, `debian`) if # you have not created a dedicated one yet. user: ubuntu port: 22 # The deploy key. SC never writes it into a command line — it reaches the # SSH client as a secret input and is encrypted in the Pulumi checkpoint. # Password and ssh-agent authentication are not supported. privateKey: ${secret:PORTAL_VM_DEPLOY_KEY} # Pin the machine's identity. Optional, and the one optional field whose # absence has a real cost: a deploy carries the stack's whole env file, # every `${secret:...}` in it, and the deploy key itself, so without this # all of that goes to whoever answers on that address. A CI runner has no # known_hosts to fall back on, which is why there is no implicit default. # # Paste the output of `ssh-keyscan -t ed25519 203.0.113.10` verbatim (the # leading address is ignored, not verified), or just the # `ssh-ed25519 AAAA…` part. Compare it against the machine's console # before you trust it — reading it off the network is what it protects # you from. hostKey: "203.0.113.10 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEXAMPLEEXAMPLEEXAMPLEEXAMPLEEXAMPLE00" # A FLEET is the same list with more entries. Add a second machine and every # stack on this resource deploys a full container set onto each one, rolled # one host at a time — the next host starts only after the previous host's # new slot is live, so a bad image stops the roll instead of taking the # fleet down. Each machine runs its own Caddy and its own blue-green pair; # blue-green is WITHIN a host and is not, and will not be, across machines. # # hosts: # - address: 203.0.113.10 # user: ubuntu # privateKey: ${secret:PORTAL_VM_DEPLOY_KEY} # hostKey: "…" # - address: 203.0.113.11 # user: ubuntu # privateKey: ${secret:PORTAL_VM_DEPLOY_KEY} # hostKey: "…" # # No `role:` needed — a pool with no roles declared is a compose fleet, and # no `privateAddress:` either, because these machines never talk to each # other. That is the useful difference from a multi-node k3s pool (see # ../../k3s/byo-host/server.yaml), and it is why a compose fleet works on # cheap VPS hosting that offers no private network at all. # # Two things a fleet needs that a single machine does not: # # * `ingress.acmeStorage` — otherwise each machine runs its own ACME # client against the same name and you get N certificates, N sets of # rate-limit consumption, and HTTP-01 challenges answered by whichever # node DNS happened to pick (which 404s a token another node minted). # One shared store makes it one certificate. See `ingress` below. # * More than one A record for the name, so requests reach more than one # machine. Note what this does and does not give you: a dead node means # roughly 1/N of requests fail and are retried by the client. It is # round-robin, not failover — a cloud load balancer with health checks # is strictly better where the cloud has one. # The front door: a Caddy container in its own compose project, terminating # TLS for every stack on this machine. It belongs to the resource and not to # a template because one machine has one port 443 — and because a stack's # own compose project is destroyed and recreated by each deploy, so a Caddy # inside it would go down with the slot it is meant to route away from. # # A stack opts in by setting `domain:`; its deploy then owns exactly one file # in Caddy's conf.d plus a reload, which is why two stacks can deploy at the # same time without a lock. # # Open ports 80 AND 443 on the machine: 80 is where the ACME challenge is # answered, so TLS never provisions without it. Caddy also publishes 443/udp # for HTTP/3 — a firewall that passes only TCP costs you QUIC, which browsers # fall back from, and nothing else. # # Leave this out and stacks are published on a high host port instead # (see client.yaml). Changing it needs `sc provision`, not `sc deploy`. ingress: enable: true # The ACME account address. Required — no CA issues without one. Expiry # notices go here. email: ops@example.com # Everything below is optional. # # Pin the Caddy build. Defaults to the same `simplecontainer/caddy` tag # the Kubernetes edge runs, which carries the plugins (`rate_limit`, # certmagic storage) that the official image does not — so # `lbConfig.siteExtraHelpers` means the same thing on both paths. Point it # at a mirror if the machine cannot reach Docker Hub. # # That default is the `sc` binary's OWN version string, which keeps the # Caddyfile this code renders in lockstep with the Caddy that reads it. # A released `sc` resolves it (the image is tagged with the same version); # a locally-rebuilt one does not, because `welder run rebuild` stamps # `0.0.0-pre` and no such image was ever pushed. So if you are # running this example against a binary you built, pin a real tag here. # image: registry.example.ru/mirror/caddy:2.11 # # How that image reaches the machine. `registry` (the default) has the # machine pull it. `ssh-tar` has the deploy runner pull it and stream it # over the provision's SSH connection, the same way `imageDelivery: # ssh-tar` above moves your own image — which is what you want on a # machine with no route to Docker Hub, because Caddy is otherwise the # last image on it that still needs a registry. # # Not the default, for two reasons: it changes nothing for the machines # that can pull, and it makes `sc provision` need a working local docker # daemon, which it has never needed before. # imageDelivery: ssh-tar # # A certificate authority other than Let's Encrypt. This exists for the # Russian market: a `.ru` domain opened from inside Russia in a browser # without foreign roots wants a Russian Trusted CA certificate, and Let's # Encrypt may not be reachable from a closed network at all. Whether that # CA speaks ACME is UNVERIFIED — the field is here so there is an option, # not because the path is known to work. # acmeCa: https://acme.example-ca.ru/directory # # External Account Binding, which a private or enterprise ACME CA # generally requires and Let's Encrypt does not. Both or neither, and only # alongside `acmeCa`. The MAC key is a credential: it never appears in the # rendered Caddyfile, reaching the machine in the ingress env file. # acmeEabKeyId: "kid-from-your-ca" # acmeEabMacKey: ${secret:PORTAL_VM_ACME_EAB_MAC_KEY} # # Whether THIS machine terminates TLS. Unset means true — every vm # resource that existed before the field. Set it to false when something # in front already terminates (Cloudflare's proxy, a cloud load # balancer, an existing reverse proxy): Caddy then serves plain HTTP on # port 80, runs no ACME at all, and `email` above is unused. # # It is also what makes `domainProxied: true` legal on a client stack. # That refusal exists because a proxied domain breaks the HTTP-01 # challenge Caddy runs itself — and here Caddy runs none, so on a fleet # an *unproxied* record would be the mistake, handing clients a # cleartext origin. The refusal therefore lives at DEPLOY time, not at # config load: the client tier cannot see this field. # # What it does NOT do is secure the hop. Edge-to-origin is cleartext # over the public internet unless the machine's firewall admits only the # edge's addresses — Cloudflare publishes theirs, and `ingressPorts` on # this resource is where they go. Said plainly, because "my site is # HTTPS" is true for the visitor and false for the leg SC owns. # originTls: false # # ONE shared certificate store for every machine of this resource. On a # single machine it is optional; on a fleet behind N A records it is the # prerequisite, and `originTls: false` is the only alternative. The # reason: Let's Encrypt's validator reaches an arbitrary machine, which # 404s a challenge token another machine minted. certmagic shares that # state — and the issued certificate — through storage, so with a store # the fleet issues ONE certificate and any machine can answer any # machine's challenge. # # The three credentials never reach the rendered Caddyfile: it holds # `{$SC_ACME_S3_*}` placeholders and the values arrive in a 0600 env # file. SC also renders `admin { config { persist false } }` alongside # the store, because Caddy substitutes those placeholders at adapt time # and would otherwise autosave the resolved JSON — credentials included # — to /config/caddy/autosave.json on every start. # # The same block exists on the Kubernetes edge as `kubernetes-caddy`'s # `acmeStorage`, rendered by the same code. # acmeStorage: # bucket: mycompany-acme # # Omit for AWS S3. Any S3-compatible endpoint works — yc-bucket, # # GCS interop, or a minio on one of the machines where the cloud # # has no bucket resource at all. # endpoint: https://storage.yandexcloud.net # region: ru-central1 # default: us-east-1 # accessKey: ${secret:ACME_S3_ACCESS_KEY} # secretKey: ${secret:ACME_S3_SECRET_KEY} # # Exactly 32 bytes. Encrypts the certificates and the ACME account # # key at rest in the bucket. Lose it and the store is unreadable: # # the fleet re-issues, against Let's Encrypt's 50-per-domain-per- # # week limit. # encryptionKey: ${secret:ACME_S3_ENCRYPTION_KEY} # prefix: acme # default: acme # # Defaults to true when `endpoint` is set and false otherwise, # # which is right for minio and for AWS respectively. # # pathStyle: true