MCPcopy Index your code
hub / github.com/TritonDataCenter/containerpilot

github.com/TritonDataCenter/containerpilot @3.8

Chat with this repo
repository ↗ · DeepWiki ↗ · release 3.8 ↗ · + Follow
472 symbols 1,508 edges 71 files 245 documented · 52%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

ContainerPilot

An init system for cloud-native distributed applications that automates the process of service discovery, configuration, and lifecycle management inside the container, so you can focus on your apps.

Build Status MPL licensed GoDoc

What is ContainerPilot?

Orchestration is the automation of the operations of an application. Most application require operational tasks like connecting them to related components (WordPress needs to know where it's MySQL and Memcached servers are, for example), and some applications require special attention as they start up or shut down to be sure they bootstrap correctly or persist their data. We can do all that by hand, but modern applications automate those tasks in code. That's called "orchestration."

To make this work, every application needs to do the following (at a minimum):

  • Register itself in a service catalog (like Consul or Etcd) for use by other apps
  • Look to the service catalog to find the apps it depends on
  • Configure itself when the container starts, and reconfigure itself over time

We can write our new applications to do that, but existing apps will need some help. We can wrap each application in a shell script that registers itself with the discovery service easily enough, but watching for changes to that service and ensuring that health checks are being made is more complicated. We can put a second process in the container, but as soon as we do that we need an init system running inside the container as well.

ContainerPilot to the rescue!

ContainerPilot is an init system designed to live inside the container. It acts as a process supervisor, reaps zombies, run health checks, registers the app in the service catalog, watches the service catalog for changes, and runs your user-specified code at events in the lifecycle of the container to make it all work right. ContainerPilot uses Consul to coordinate global state among the application containers.

Quick Start Guide

Check out our "Hello, World" application on GitHub. Assuming you have Docker and Docker Compose available, it's as easy as:

git clone git@github.com:autopilotpattern/hello-world.git
cd hello-world
docker-compose up -d
open http://localhost

This application blueprint demonstrates using ContainerPilot to update Nginx upstream configuration at runtime. Try scaling up via docker-compose scale hello=2 world=3 to see the Nginx configuration updated.

You can also download the latest release of ContainerPilot from GitHub.

Documentation

Documentation for ContainerPilot and where it fits with the rest of the Triton ecosystem can be found at www.joyent.com/containerpilot. The index below links to the documentation in this repo for convenience.

Lifecycle - What is a job? - What is an event? - What is a watch? - How do events trigger jobs? - How can jobs be ordered?

Design: the Why of ContainerPilot - Why active service discovery? - Why isn't there a "post-start" or "started" event? - Why Consul and not etcd or Zookeeper? - Why are jobs not the same as services? - Why don't watches or metrics have an exec field? - Why use something other than ContainerPilot?

Configuration - Installation - Configuration file - Schema - Consul - Logging - Jobs - Watches - Control - Telemetry - Extras - Interfaces - Environment variables - Template rendering - Consul - Client configuration - Consul agent configuration - Jobs - Lifecycle Events - Configuration - name - exec - when - timeout - stopTimeout - restarts - health checks - service discovery - Exec arguments - Watches - Telemetry - Sensor configuration - Control plane - ContainerPilot subcommands - Logging - Example configurations

Support - Where to file issues - Contributing - Backwards compatibility

You might also read our guide building self-operating applications with ContainerPilot and look at the examples below.

Examples

We've published a number of example applications demonstrating how ContainerPilot works.

Extension points exported contracts — how you extend this code

EventPublisher (Interface)
EventPublisher is an interface for publishers that register/unregister from the EventBus and publish Events. [2 implementers]
events/publisher.go
Backend (Interface)
Backend is an interface which all service discovery backends must implement [2 implementers]
discovery/discovery.go
EventSubscriber (Interface)
EventSubscriber is an interface for subscribers that subscribe/unsubscribe from the EventBus and receive Events. [1 implementers]
events/subscriber.go
PostHandler (FuncType)
PostHandler is an adapter which allows a normal function to serve itself and handle incoming HTTP POST requests, and all
control/endpoints.go
Handler (FuncType)
Handler functions implement a subcommand
subcommands/subcommands.go

Core symbols most depended-on inside this repo

processEvent
called by 25
jobs/jobs.go
Publish
called by 24
events/publisher.go
NewConfigs
called by 21
jobs/config.go
Run
called by 20
jobs/jobs.go
Wait
called by 19
events/bus.go
Run
called by 15
control/control.go
Run
called by 15
core/app.go
Register
called by 15
events/publisher.go

Shape

Function 248
Method 163
Struct 48
TypeAlias 7
Interface 4
FuncType 2

Languages

Go98%
Python2%

Modules by API surface

jobs/jobs.go27 symbols
config/services/ips.go26 symbols
jobs/config.go19 symbols
jobs/config_test.go18 symbols
config/services/ips_test.go16 symbols
events/bus.go15 symbols
discovery/consul.go14 symbols
config/template/template.go14 symbols
config/config.go13 symbols
subcommands/subcommands.go11 symbols
discovery/consul_test.go11 symbols
core/flags_test.go10 symbols

For agents

$ claude mcp add containerpilot \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact