Categorygithub.com/joyent/containerpilot
modulepackage
0.0.0-20210209154853-8018142368d2
Repository: https://github.com/joyent/containerpilot.git
Documentation: pkg.go.dev

# 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 [email protected]: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

Design: the Why of ContainerPilot

Configuration

Support

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.

# Packages

Package client provides a HTTP client used to send commands to the ContainerPilot control socket.
Package commands provides a wrapper around os/exec to consistently manage process execution, cancellation of their child processes, timeouts, logging, arg parsing, and correct shutdown.
Package config is the top-level configuration parsing package.
Package control provides a HTTP server listening on the unix domain socket for use as a control plane, as well as all the HTTP endpoints.
Package core contains the main control loop.
Package discovery manages the configuration of the Consul clients and the functions used to update/query Consul with service discovery data.
Package events contains the internal message bus used to broadcast events between goroutines representing jobs, watches, etc.
Package jobs manages the configuration and execution of the jobs.
Package subcommands provides all the alternative top-level functions that run one-off commands that don't run the main event loop.
Package sup provides the child process reaper for PID1.
Package telemetry provides a Prometheus client and the configuration for metrics collectors.
No description provided by the author
Package version only provides some package variables set at build time.
Package watches manages the configuration and running of Consul service monitoring.