Coolify CLI

repository·v4.x·Indexed 19 days ago

https://github.com/coollabsio/coolify-cli

A command-line interface for interacting with the Coolify API, supporting both Cloud and self-hosted instances. It enables management of servers, applications, databases, and one-click services. Key features include multi-instance context management, environment variable syncing from .env files, batch deployments, and GitHub App integration. Additionally, it includes early preview tools for Coolify v5 Mesh provisioning via SSH to manage WireGuard meshes and firewall rules.

Tokens
80.9K
Snippets
402
Records
464
Agent score
64%

What's inside coolify-cli

  1. Understand the Coolify v5 Control Plane Architecture

    v4.x

    The Coolify v5 architecture manages a fleet of mesh-connected hosts using a centralized UI/API and per-host agents called coold.

    Key Components

    • Coolify Central UI/API: The command center. It routes commands to specific hosts using host_id. It listens for outbound TLS connections (:443) from agents.
    • coold (Per-host agent): The local agent running on every host. It dials outbound to Central (or an optional gateway) via WSS/gRPC bidi streams. It never accepts inbound connections from the internet or Central, allowing it to work through NAT and firewalls.
    • Podman: The container runtime. coold interacts with Podman exclusively through the local /run/podman/podman.sock via a bind-mount. The raw socket is never exposed on a TCP network.
    • Per-customer Gateway (Optional): For large-scale deployments, a single host in a mesh can act as a stream aggregator. It dials Central once and proxies commands to other coold agents over the WireGuard (wg0) mesh, reducing the connection load on Central.

    Connectivity Model

    • Outbound-only: Agents (coold) initiate all connections to Central. This ensures scalability and security.
    • Intra-mesh REST API: coold exposes a local REST API on the WireGuard (wg0) management IP (port :8443). This is accessible only to intra-mesh callers (like the coolify firewall CLI or other agents in the same mesh) and is never reachable from the public internet.
    ┌─────────────────────────────────────┐
    │  Coolify central UI / API           │
    └────────────────────▲────────────────┘
                         │ outbound TLS :443 (WSS / gRPC bidi)
                         │
       ┌─────────────────┴──────────────────┐
       │      (per-customer gateway,        │
       │       OPTIONAL — one mesh host     │
       └─────────────────▲──────────────────┘
                         │
    ┌────────────────────┴────────────────┐  ┌─────────────────────────┐
    │  coold (per-host agent)             │  │  /run/podman/podman.sock│
    └─────────────────────────────────────┘  └─────────────┬───────────┘
                                                          ▼
                                             ┌─────────────────────────────┐
                                             │  podmand (containers, nets) │
                                             └─────────────────────────────┘
  2. How Network Policy (Firewall) works in Coolify v5

    v4.x

    When a host has --default-deny enabled, all cross-host container traffic is dropped by default. The control plane manages access via a three-layer model:

    1. Chain Scaffold: Created by coolify init bootstrap. It sets up the COOLIFY-INTRA, COOLIFY-ALLOW, and other necessary jumps. It is idempotent and re-converges on extend.
    2. Rule Metadata: Managed by Coolify Central. This is the authoritative source for RBAC, audit logs, and mapping apps to rules.
    3. Raw Rule Tuples: Managed by coold. coold is the sole writer of raw rules (src, dst, proto, port) to the host kernel. It caches these rules in /etc/coolify/allow.rules to ensure persistence across reboots.

    Important: coold does not generate rules from intent (e.g., "allow web to db"). Central Coolify compiles that intent into individual POST /firewall/allow frames and sends them to the agent.

  3. Storage and Volume Management in v5

    v4.x

    In the current v5 architecture, stateful services are pinned to a host.

    • Local Volumes: Uses standard Podman volumes located at /var/lib/containers/storage/volumes.
    • Cross-host: Distributed file systems are currently out of scope for alpha. To ensure data persistence, the scheduler pins stateful services to specific hosts.
    • Backups: Orchestrated by Coolify using podman volume export followed by scp to a backup target.
  4. Service Discovery and DNS via `.coolify.internal`

    v4.x

    Coolify uses an internal DNS system for service discovery.

    • TLD: The default Top-Level Domain is .coolify.internal (configurable per-cluster).
    • Mechanism: coold manages a local DNS socket on the bridge gateway IP. When a service is registered, its IP is gossiped via Corrosion and becomes resolvable via DNS.
    • TTL: The DNS TTL is set to 5s. This provides a balance between fast failover and DNS stability.
    • Multi-replica: The resolver returns all healthy A records. Applications should use connection pools (e.g., standard Postgres or Redis clients) to handle multiple targets naturally.

    Important Note for Developers: Applications must implement reconnection logic. When a container is redeployed, its IP changes; the application's client must re-resolve the DNS name to find the new IP. Applications with infinite-cache DNS resolvers (like certain Java configurations) will fail to see updates.

  5. How the Coolify CLI architecture works

    v4.x

    The Coolify CLI uses a layered architecture to separate user interaction from API communication. This design ensures that the CLI can manage multiple Coolify instances, handle complex business logic, and provide flexible output formats without tightly coupling the command-line interface to the underlying API.

    Architecture Layers

    1. Command Layer (cmd/): Handles CLI parsing, flag validation, and user interaction.
    2. Service Layer (internal/service/): Implements business logic, validates requests, and transforms API responses into CLI-friendly formats.
    3. API Client Layer (internal/api/): Manages HTTP communication, including authentication (Bearer tokens), retry logic with exponential backoff, and error handling.
    4. Configuration Layer (internal/config/): Manages multi-instance settings and token storage.
    5. Output Layer (internal/output/): Formats data for the terminal (Table, JSON, or Pretty JSON).
    6. Models Layer (internal/models/): Defines the data structures (Servers, Projects, etc.) used throughout the application.
  6. How the Coolify v5 Control Plane architecture works

    v4.x

    The Coolify v5 architecture separates high-level application logic from low-level host management through three primary layers:

    1. Central Coolify (SaaS/Self-hosted): The brain of the system. It handles RBAC, tenant scoping, business audit logs, scheduling, ingress templating, and application-aware logic (Compose, Dockerfiles, Nixpacks). It communicates with hosts via an outbound WSS/gRPC bi-directional stream.
    2. coold (Host Agent): A lightweight agent running on each host. It is the only process with access to the local podman socket and the sole writer of kernel firewall rules. It acts as the auth/privilege boundary. It exposes a local REST API on the wg0 management IP (http://100.64.0.X:8443) for intra-mesh callers like the coolify firewall CLI.
    3. SSH (Provisioning Channel): Used exclusively for the initial host installation and re-convergence (running coolify init commands). It is not used for steady-state runtime control.

    Persistence Model:

    • Bootstrap State: Managed via idempotent coolify init runs.
    • Rule Metadata: Stored in the central Coolify DB (audit logs, RBAC, etc.).
    • Kernel Rules: Programmed by coold and mirrored to /etc/coolify/allow.rules for persistence across reboots via the coolify-mesh-allow.service.
  7. Understand the Coolify v5 Control Plane Architecture

    v4.x

    The Coolify v5 architecture separates the Central controller from the coold (Control Plane Daemon) running on individual hosts.

    • Central: Acts as the brain. It handles the build pipeline (BuildKit, Nixpacks), scheduling (deciding which host runs which app), and orchestration (compiling app intent into a sequence of primitives).
    • coold: Acts as the executor on the host. It is a narrow, primitive-based daemon that interacts with the local Podman socket, manages the local firewall, and handles local DNS/service registration. It does not parse Compose files, build images, or make scheduling decisions.

    Key Mental Model: Deployment is a sequence of 'frames' (primitives) sent from Central to coold. Each frame represents a single, atomic operation (e.g., POST /images/pull, POST /containers).

  8. Handle sensitive data and API tokens in output

    v4.x

    For security, the CLI implements several protections for sensitive data:

    • Storage: API tokens are stored in the config file with restricted permissions (0600).
    • Masking: Tokens are masked as ******** in command output by default.
    • Viewing Sensitive Data: To reveal masked values, use the --show-sensitive flag.
    • Logging: Tokens are never included in logs, even in debug mode.
  9. Coolify v5 Mesh (alpha) provisioning

    v4.x

    The init and firewall command groups are part of an early preview for Coolify v5 fleet provisioning. Unlike other commands, these do not communicate with the Coolify API; instead, they connect directly to your servers via SSH to manage a WireGuard mesh (using Podman) and cross-host container firewall rules.

    # First-time mesh installation across all servers
    coolify init bootstrap
    
    # Add an allow rule between containers on the mesh
    coolify firewall allow
  10. Understand Coolify API communication and authentication

    v4.x

    The CLI communicates with the Coolify API using standard HTTP patterns:

    • Base URL Structure: {fqdn}/api/v1/{endpoint}
    • Authentication: Uses Bearer token authentication via the Authorization header.
    • Content Type: All requests and responses use application/json.
    • Retry Logic: The CLI implements exponential backoff for failed requests. It retries on network failures and 429 (rate limit) errors, but does not retry on 4xx client errors (except 429).

    Common Error Mappings:

    • 401 $\rightarrow$ "Unauthenticated. Check your API token."
    • 404 $\rightarrow$ "Resource not found."
    • 500 $\rightarrow$ "Server error. Please try again."
  11. How firewall rule persistence and reconciliation works

    v4.x

    The Coolify central database is the authoritative source of truth for the desired state of firewall rules. The coold service on each host is responsible for making the kernel's live state match that truth.

    The Write Sequence:

    1. Central DB Update: The central server writes the rule to its database first.
    2. Command Dispatch: Central sends the rule (src, dst, proto, port) to coold via an established stream.
    3. Kernel Application: coold applies the rule using iptables -A/-D.
    4. Snapshot Generation: coold regenerates /etc/coolify/allow.rules via iptables-save.
    5. Acknowledgment: coold returns success to Central.

    Error Handling:

    • If a crash occurs between kernel application and snapshot generation, the rule is lost on reboot. However, the Central Reconcile Loop periodically compares the Central DB against the live kernel (iptables -S COOLIFY-ALLOW) and re-pushes any missing rules to ensure convergence.
  12. Generate documentation for LLMs and AI agents

    v4.x

    The CLI provides specialized documentation files (llms.txt and llms-full.txt) optimized for LLM consumption. You can regenerate these files using the following command:

    go run ./coolify docs llms
    go run ./coolify docs llms