initctl

package
v0.39.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 31, 2026 License: MIT, MIT Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package initctl is `pstack init` — stand up the CONTROL stack on a host.

── WHY THIS LIVES IN THE CLI AND NOT IN THE API ──────────────────────────────────────────────

host (systemd / CLI)
  └─ pstack init ──▶ CONTROL stack: traefik + pstack (API + UI)
                                      │ manages
                                      ▼
                          shared + isolated deployments

The running API manages every OTHER deployment. It must never manage the stack it is running in, because `up` on that project recreates the pstack container — killing the process halfway through the operation it was performing. The request never returns, the job transcript is lost with the process (job history is in-memory, invariant 10), and if the new image is broken the host is left with no control plane and no remote way to fix it: the only thing that could have repaired it was the thing that just died. So self-management is not a feature with a caveat, it is a way to brick a host from a browser tab.

The host keeps that power. `init` runs over SSH, from systemd, or from CI-with-a-key — always from OUTSIDE the containers it is recreating, which is the only place a failed upgrade is recoverable.

Everything here is idempotent: re-running `init` is the supported way to change the domain, rotate the token, or move to a new image.

Index

Constants

View Source
const (
	HTTP01   Challenge = "http01"
	DNS01    Challenge = "dns01"
	Basic    UI        = "basic"
	Advanced UI        = "advanced"
)
View Source
const ControlProject = "pstack-control"

ControlProject is the control stack's compose project name. Exported because the API reads it to SHOW the control stack's status — never to act on it. Keep it stable: it is how an operator finds the stack with `docker compose -p pstack-control …`.

Variables

View Source
var DNSTokenVar = map[string]string{
	"cloudflare": "CF_DNS_API_TOKEN",
	"hetzner":    "HETZNER_API_TOKEN",
	"route53":    "",
	"gcloud":     "",
}

DNSTokenVar is lego's DNS-01 credential variable, per provider — the name Traefik expects the token under.

ONLY the providers verified in `docs/bootstrap.md` §3 are listed. A wrong variable name fails as "propagation timeout", which sends you debugging DNS instead of a typo, so an unknown provider gets a CHANGEME line pointing at lego's list rather than a guess.

"" (the TS's `null`) means the provider is *tokenless*: AWS satisfies the credential chain from an instance profile and GCP from the VM's attached service account, so there is nothing to write, nothing on disk, and nothing to rotate. Prefer those where you have the choice. Presence in the map is the "known" test; a lookup table, never ranged into output.

Functions

func AcmeChallengeArgs

func AcmeChallengeArgs(challenge Challenge, provider string) string

AcmeChallengeArgs is Traefik's ACME challenge flags for the chosen mode, at the template's indentation.

HTTP-01 needs no credential: Traefik answers on the `web` entrypoint over port 80. The web→websecure redirect does NOT break it — Traefik installs an internal ACME router at maximum priority that bypasses the redirect for `/.well-known/acme-challenge/`. Port 80 must be reachable from the internet, which is the one hard requirement.

func AcmeRouterLabels

func AcmeRouterLabels(challenge Challenge) string

AcmeRouterLabels is the TLS labels on the control router.

dns01 requests ONE wildcard from a single always-on router; every other router (including every per-PR one) sets `tls=true` alone and inherits it by SNI. Adding `certresolver` to another router makes Traefik order a SEPARATE certificate for it — the rate-limit trap.

http01 cannot do wildcards at all, so each router resolves its own certificate on first request.

func AdvancedUIService

func AdvancedUIService(ui UI) string

AdvancedUIService is the optional advanced-UI container. Omitted entirely in basic mode — not merely disabled.

func ControlUIService

func ControlUIService(ui UI) string

ControlUIService is which Traefik service `control.<domain>` routes to.

The ROUTER stays on the pstack container in both modes so the TLS labels render identically; only its target changes. Traefik happily lets a router declared on one container reference a loadbalancer service declared on another, which keeps this a one-line swap.

func Init

func Init(opts Options) error

Init stands up the control stack.

func SwarmProviderArgs

func SwarmProviderArgs(orchestrator spec.Orchestrator) string

SwarmProviderArgs is Traefik's swarm provider, in swarm mode only. Both providers run: docker for the control stack's own containers (and any compose-mode preview), swarm for the stacks. `exposedbydefault=false` on both for the same reason — routing is opt-in.

func WakeRouterLabels

func WakeRouterLabels(domain string) string

WakeRouterLabels is the catch-all router for wake-on-call. A Go regexp over one label under the domain; `$$` is how a literal `$` survives compose's interpolation of this file, and the dots are escaped here (the template cannot, it only knows `${DOMAIN}`).

Types

type Challenge

type Challenge string

Challenge is how Let's Encrypt verifies the domain.

type Options

type Options struct {
	// DataDir is where the control plane keeps its state — the same path the API reads as PSTACK_DATA.
	DataDir string
	// Domain is the apex of the preview domain, e.g. `preview.example.com`. The UI lands on `control.<domain>`.
	Domain string
	// AcmeEmail is the ACME registration address. Let's Encrypt mails expiry warnings here.
	AcmeEmail string
	// Challenge is how Let's Encrypt verifies the domain.
	//
	//   http01  DEFAULT. Zero credentials — Traefik answers a challenge on port 80. Works the
	//           moment DNS points at the box. CANNOT issue wildcards, so every hostname gets its
	//           own certificate, and Let's Encrypt allows only ~50 new certificates per registered
	//           domain per week. At 3 surfaces per PR that is ~16 PRs/week. It also cannot cover a
	//           hostname before its container exists, so a not-yet-deployed preview URL has no cert.
	//   dns01   One wildcard covers every present and future `*.<domain>` host: no per-PR issuance,
	//           no rate-limit ceiling, and a URL is valid before the stack is deployed. Costs a DNS
	//           API credential to obtain, store and rotate.
	//
	// Start on http01; move to dns01 when PR volume or pre-deploy URLs demand it.
	Challenge Challenge
	// UI is which web UI `control.<domain>` serves.
	//
	//   basic     DEFAULT. The UI embedded in the API bundle — no extra container, nothing else to
	//             build or pull. Enough to submit a deployment and watch a job.
	//   advanced  The standalone SPA (@samyx/preview-stacks-ui) as its OWN container, which the
	//             control stack gains a service for. Richer, but one more image to build and keep
	//             current, so it is opt-in rather than the default.
	//
	// Either way the API keeps serving the basic UI on `api.<domain>`, so a broken advanced image
	// never leaves the host with no usable interface.
	UI UI
	// Orchestrator is how previews are deployed on this host.
	//
	//   swarm    DEFAULT for a new host. This daemon becomes a one-node swarm manager; previews deploy
	//            as swarm stacks; workers can join later from the swarm panel. The control stack
	//            itself stays a plain compose project on the manager (it must never depend on the
	//            orchestrator it manages), and the two external networks become attachable overlays
	//            so its containers reach tasks on any node.
	//   compose  What every host before 0.26.0 ran. `pstack upgrade` keeps it: switching an existing
	//            host means recreating its networks, which needs every preview torn down first.
	Orchestrator spec.Orchestrator
	// DNSProvider is the lego DNS-01 provider code, e.g. `cloudflare`. Required for, and only used by, `dns01`.
	DNSProvider string
	// Token is the DNS-01 API token, and ONLY that — it is written to `dns.env` for Traefik and
	// never reused as the API's bearer token. Two different secrets, two different blast radii:
	// this one can edit a DNS zone, PSTACK_TOKEN can start privileged containers. Omit it for the
	// tokenless providers (route53, gcloud), which authenticate from the instance's own identity.
	Token string
	// DryRun: change nothing — print what would happen. Must match the flag the runner was built with.
	DryRun bool
	// Runner is from exec.New, so `--dry-run` behaves exactly as it does everywhere else.
	Runner exec.Runner
	// Out is where init's own lines go (stdout when nil). Pass the runner's Out so a dry-run
	// transcript interleaves in order.
	Out io.Writer
}

Options are init's inputs.

type UI

type UI string

UI is which web UI `control.<domain>` serves.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL