Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.env
alios
ingot
.DS_Store
scripts/build
24 changes: 12 additions & 12 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co

## What this is

Alios CLI (`alios`) is a single-binary Go CLI that manages a local Docker-based PHP development environment: per-project PHP (FrankenPHP) containers, global shared services (DNS, Caddy reverse proxy, MailHog), optional MySQL/PostgreSQL databases, and locally-trusted SSL certificates for `*.test` domains. It has no server component — every command shells out to the `docker` CLI on the user's machine.
Ingot (`ingot`) is a single-binary Go CLI that manages a local Docker-based PHP development environment: per-project PHP (FrankenPHP) containers, global shared services (DNS, Caddy reverse proxy, MailHog), optional MySQL/PostgreSQL databases, and locally-trusted SSL certificates for `*.test` domains. It has no server component — every command shells out to the `docker` CLI on the user's machine.

Alios CLI is the local-dev counterpart to Alios, a separate production server-management platform (Laravel app + Go microservices) that provisions servers and deploys Docker apps. Where practical, this CLI mirrors production's conventions (image selection vocabulary, Caddy as the reverse proxy) so a project's local dev environment structurally resembles what it runs as in production — but the two are independent codebases; this repo has no dependency on the production platform.
Ingot is a standalone tool for any PHP developer. It started as the local-dev companion to Alios, Alias Project's server-management platform, and was renamed and split out so it can be used without Alios. That's why some code comments refer to "production Alios" or "the Alios platform repo": the conventions here (image-selection vocabulary, Caddy as the reverse proxy, env injection) were copied from it so local projects look like production. There is no code dependency on Alios, and none should be added. Alios-specific features belong in a future Alios CLI that can build on Ingot.

## Build & run

```bash
go build -o alios ./cmd # build the binary
go build -o ingot ./cmd # build the binary
go run ./cmd <command> # run without building, e.g. go run ./cmd status
go vet ./... # static checks
```
Expand All @@ -22,27 +22,27 @@ Releases are cut with `scripts/release.sh <version> [notes]`, which patches `int

## Architecture

**Entry point**: `cmd/main.go` builds a `config.Config` (singleton, env-var driven) and a `docker.Client`, then hands off to `commands.Handler`, which is the dispatch table for every CLI subcommand (`internal/commands/handler.go`). First run (no binary at `/usr/local/bin/alios`) triggers `commands.Installer` (`internal/commands/installer.go`) instead of normal command dispatch.
**Entry point**: `cmd/main.go` builds a `config.Config` (singleton, env-var driven) and a `docker.Client`, then hands off to `commands.Handler`, which is the dispatch table for every CLI subcommand (`internal/commands/handler.go`). First run (no binary at `/usr/local/bin/ingot`) triggers `commands.Installer` (`internal/commands/installer.go`) instead of normal command dispatch.

**No persisted config files.** This is deliberate, not incomplete: `config.Config.Save()` is a no-op. All state lives in one of two places:
- Environment variables (`GITHUB_TOKEN`, `ALIOS_*`) for user settings — see `internal/config/config.go`.
- Docker container labels (`alios.project.name`, `alios.project.php_version`, `alios.project.server_root`, `alios.project.image_type`, `alios.project.framework`, etc.) for per-project state — projects are *discovered* by inspecting containers, not read from disk. `project.Manager.GetCurrentProject()` derives project identity from the current working directory name plus the `alios_php_<name>` container's labels/state; there is no separate "project database."
- Environment variables (`GITHUB_TOKEN`, `INGOT_*`) for user settings — see `internal/config/config.go`.
- Docker container labels (`ingot.project.name`, `ingot.project.php_version`, `ingot.project.server_root`, `ingot.project.image_type`, `ingot.project.framework`, etc.) for per-project state — projects are *discovered* by inspecting containers, not read from disk. `project.Manager.GetCurrentProject()` derives project identity from the current working directory name plus the `ingot_php_<name>` container's labels/state; there is no separate "project database."

**`internal/docker/client.go`** is the only layer that shells out to the `docker` binary (`exec.Command`). Every other package goes through `*docker.Client` rather than calling `os/exec` directly for container operations.

**Two tiers of containers**, both Docker-labeled so they're discoverable without local state:
- *Project containers* (`internal/project/manager.go`): one `alios_php_<project>` container per project directory, created directly via `docker.Client.RunContainer` (not compose) — or, for a project with `image_type=custom` and a build-from-Dockerfile choice, via `docker.Client.BuildImage` first. Changing PHP version, image choice, or server root means destroying and recreating the container, not reconfiguring it in place.
- *Global services* (`internal/services/manager.go`): `alios_dns`, `alios-reverse-proxy`, `alios_mail`, plus any configured databases, all managed as one Docker Compose project (`name: alios`) whose YAML is generated inline in Go (`generateComposeConfig`) rather than read from a file. Adding/removing a database rewrites and re-applies the whole compose config, which restarts the group.
- *Project containers* (`internal/project/manager.go`): one `ingot_php_<project>` container per project directory, created directly via `docker.Client.RunContainer` (not compose) — or, for a project with `image_type=custom` and a build-from-Dockerfile choice, via `docker.Client.BuildImage` first. Changing PHP version, image choice, or server root means destroying and recreating the container, not reconfiguring it in place.
- *Global services* (`internal/services/manager.go`): `ingot_dns`, `ingot_proxy`, `ingot_mail`, plus any configured databases, all managed as one Docker Compose project (`name: ingot`) whose YAML is generated inline in Go (`generateComposeConfig`) rather than read from a file. Adding/removing a database rewrites and re-applies the whole compose config, which restarts the group.

**Images come from a private GHCR registry** (`ghcr.io/aliasproject/{php,dns,caddy,openssl}`), so most flows depend on GitHub auth being set up first (`internal/github/client.go` — supports PAT, OAuth device flow, or delegating to `gh auth token`, then does the `docker login ghcr.io` for image pulls). The `php` image comes in several variant tags per PHP version (`-frankenphp-dev`, `-frankenphp-wordpress-dev`, ...), selected in `project.Manager.createContainer` based on the project's detected/chosen `framework` and `image_type` labels.

**SSL** (`internal/ssl/manager.go`): a CA cert and per-domain certs are generated by running the `ghcr.io/aliasproject/openssl` image against the `alios_certs` volume (not via a Go TLS library) — self-signed, not Let's Encrypt, since `.test` domains are IANA-reserved and never publicly resolvable so ACME has no path to succeed. Per-project Caddy vhost files (`<project>.caddyfile`) are written directly into the `alios_vhosts` volume, which is mounted at `/etc/caddy` in the `alios-reverse-proxy` container alongside a base `Caddyfile` (written by `services.Manager.Start`) that does `import /etc/caddy/*.caddyfile` — adding or removing a project is just adding/removing one file plus `caddy reload`, no full-file rewrite. There's no templating engine, just Go `fmt.Sprintf` strings. The base Caddyfile also has host-less `https://`/`http://` catch-all sites that serve a branded "No project here" 404 page (`internal/services/default_page.html`, embedded in the binary and written to `alios_vhosts/default/`) for any `*.test` host without a vhost. Its HTTPS side can't use a static cert (browsers reject a wildcard directly under a TLD like `*.test`), so it uses Caddy's on-demand internal issuer with the alios CA as its root (the `pki` global block; `ssl.Manager.PrepareCAForCaddy` makes the CA key readable to Caddy before start), minting an exact cert per requested host that chains to the already-trusted CA.
**SSL** (`internal/ssl/manager.go`): a CA cert and per-domain certs are generated by running the `ghcr.io/aliasproject/openssl` image against the `ingot_certs` volume (not via a Go TLS library) — self-signed, not Let's Encrypt, since `.test` domains are IANA-reserved and never publicly resolvable so ACME has no path to succeed. Per-project Caddy vhost files (`<project>.caddyfile`) are written directly into the `ingot_vhosts` volume, which is mounted at `/etc/caddy` in the `ingot_proxy` container alongside a base `Caddyfile` (written by `services.Manager.Start`) that does `import /etc/caddy/*.caddyfile` — adding or removing a project is just adding/removing one file plus `caddy reload`, no full-file rewrite. There's no templating engine, just Go `fmt.Sprintf` strings. The base Caddyfile also has host-less `https://`/`http://` catch-all sites that serve a branded "No project here" 404 page (`internal/services/default_page.html`, embedded in the binary and written to `ingot_vhosts/default/`) for any `*.test` host without a vhost. Its HTTPS side can't use a static cert (browsers reject a wildcard directly under a TLD like `*.test`), so it uses Caddy's on-demand internal issuer with the ingot CA as its root (the `pki` global block; `ssl.Manager.PrepareCAForCaddy` makes the CA key readable to Caddy before start), minting an exact cert per requested host that chains to the already-trusted CA.

**Sharing** (`internal/share/manager.go`, `alios share`): exposes a project publicly through a Cloudflare Tunnel. A `cloudflared` container on `alios_internal` sends traffic to Caddy over plain HTTP, and a `<project>.share.caddyfile` vhost matching the exact public host proxies it on to the project. That vhost file is the only record of a share's URL, mode and auth. The tunnel containers carry `alios.share.*` labels only so leftovers can be found and removed, and they're deliberately not global services, so `global restart` doesn't bounce them. Quick mode (default) runs one `alios_share_<project>` container per share with a random trycloudflare.com URL. Named mode (`ALIOS_SHARE_TUNNEL_TOKEN` + `ALIOS_SHARE_DOMAIN`) runs one shared `alios_share` container whose `*.<domain>` ingress is configured in the Cloudflare dashboard. See `docs/SHARING.md`.
**Sharing** (`internal/share/manager.go`, `ingot share`): exposes a project publicly through a Cloudflare Tunnel. A `cloudflared` container on `ingot_internal` sends traffic to Caddy over plain HTTP, and a `<project>.share.caddyfile` vhost matching the exact public host proxies it on to the project. That vhost file is the only record of a share's URL, mode and auth. The tunnel containers carry `ingot.share.*` labels only so leftovers can be found and removed, and they're deliberately not global services, so `global restart` doesn't bounce them. Quick mode (default) runs one `ingot_share_<project>` container per share with a random trycloudflare.com URL. Named mode (`INGOT_SHARE_TUNNEL_TOKEN` + `INGOT_SHARE_DOMAIN`) runs one shared `ingot_share` container whose `*.<domain>` ingress is configured in the Cloudflare dashboard. See `docs/SHARING.md`.

**Scale to zero** (`internal/idle`, `cmd/alios-idle`, `alios idle`): the `alios_idle` global service stops project containers that have been idle for `ALIOS_IDLE_TIMEOUT` (default 30m; the per-project `alios.project.idle` label overrides it) and starts them again when Caddy can't reach them. Every project and share vhost ends with `import alios_wake <project>`, a snippet in the base Caddyfile that sends 502/503/504 errors to the waker, which starts the container and 307-redirects back to the same URL. `alios stop` swaps that line for `import alios_stopped <project>` (a "stopped" page), so a project stopped by hand stays down until `alios start`; the vhost is the only record of which state a project is in (`ssl.SetProjectStopped`). Idle means no network traffic, no CPU and no exec'd processes over the timeout (`idle.Tracker`, unit-tested). `alios_idle` is deliberately not a compose service or in `GlobalServices`: it's optional, and compose aborts the whole `up` when one image can't be pulled (`services/idle.go`). The service runs from its own image (`Dockerfile.idle`, pushed by `scripts/release.sh` as `ghcr.io/aliasproject/alios-idle:<version>`), and it is the one place that talks to the Docker Engine API over the socket directly instead of through `docker.Client`, because its scratch image has no docker CLI. See `docs/IDLE.md`.
**Scale to zero** (`internal/idle`, `cmd/ingot-idle`, `ingot idle`): the `ingot_idle` global service stops project containers that have been idle for `INGOT_IDLE_TIMEOUT` (default 30m; the per-project `ingot.project.idle` label overrides it) and starts them again when Caddy can't reach them. Every project and share vhost ends with `import ingot_wake <project>`, a snippet in the base Caddyfile that sends 502/503/504 errors to the waker, which starts the container and 307-redirects back to the same URL. `ingot stop` swaps that line for `import ingot_stopped <project>` (a "stopped" page), so a project stopped by hand stays down until `ingot start`; the vhost is the only record of which state a project is in (`ssl.SetProjectStopped`). Idle means no network traffic, no CPU and no exec'd processes over the timeout (`idle.Tracker`, unit-tested). `ingot_idle` is deliberately not a compose service or in `GlobalServices`: it's optional, and compose aborts the whole `up` when one image can't be pulled (`services/idle.go`). The service runs from its own image (`Dockerfile.idle`, pushed by `scripts/release.sh` as `ghcr.io/aliasproject/ingot-idle:<version>`), and it is the one place that talks to the Docker Engine API over the socket directly instead of through `docker.Client`, because its scratch image has no docker CLI. See `docs/IDLE.md`.

**Networking**: all alios containers share one Docker bridge network (`alios_internal`, see `config.GetNetworkConfig()`). The `alios_dns` container resolves `*.test` to the host so `https://<project>.test` reaches Caddy, which reverse-proxies to `alios_php_<project>` by container name (Caddy resolves Docker container names on the shared network natively — no explicit resolver directive needed). Project containers get `alios_dns`'s live container IP injected as their DNS server (resolved at container-creation time, not hardcoded) so they can resolve other `.test` domains from inside.
**Networking**: all ingot containers share one Docker bridge network (`ingot_internal`, see `config.GetNetworkConfig()`). The `ingot_dns` container resolves `*.test` to the host so `https://<project>.test` reaches Caddy, which reverse-proxies to `ingot_php_<project>` by container name (Caddy resolves Docker container names on the shared network natively — no explicit resolver directive needed). Project containers get `ingot_dns`'s live container IP injected as their DNS server (resolved at container-creation time, not hardcoded) so they can resolve other `.test` domains from inside.

**Self-update** (`internal/updater/updater.go`): checks GitHub Releases (private repo, needs `GITHUB_TOKEN`) first, then falls back to a public S3/R2-hosted `manifest.json`. Replaces the running binary atomically, escalating to `sudo`/Windows UAC if the install path isn't writable.

Expand Down
14 changes: 7 additions & 7 deletions Dockerfile.idle
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# The alios_idle global service (cmd/alios-idle). Published as
# ghcr.io/aliasproject/alios-idle:<version> by scripts/release.sh, tagged with
# The ingot_idle global service (cmd/ingot-idle). Published as
# ghcr.io/aliasproject/ingot-idle:<version> by scripts/release.sh, tagged with
# the CLI version so a CLI always runs the service it was built against.
FROM golang:1.23-alpine AS build
WORKDIR /src
COPY go.mod ./
COPY cmd/alios-idle ./cmd/alios-idle
COPY cmd/ingot-idle ./cmd/ingot-idle
COPY internal/idle ./internal/idle
ARG TARGETOS TARGETARCH
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH \
go build -trimpath -ldflags="-s -w" -o /alios-idle ./cmd/alios-idle
go build -trimpath -ldflags="-s -w" -o /ingot-idle ./cmd/ingot-idle

FROM scratch
COPY --from=build /alios-idle /alios-idle
COPY --from=build /ingot-idle /ingot-idle
EXPOSE 8080
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s CMD ["/alios-idle", "healthcheck"]
ENTRYPOINT ["/alios-idle"]
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s CMD ["/ingot-idle", "healthcheck"]
ENTRYPOINT ["/ingot-idle"]
Loading