GithubHelp home page GithubHelp logo

p2's Introduction

P2: Tools for Scalable Software Deployment

Build Status

This is a collection of tools intended to allow huge fleets of machines to participate in safe, flexible and scalable deployment models. It was designed for Square but is a general-purpose framework that should look suspiciously like Kubernetes to anyone paying close attention.

Docker Optional

Using Docker isn't an overnight choice, especially for a company with a long history of deploying things that aren't Docker. P2 supports our internal artifact specification ("Hoist artifacts") which are .tar.gz files with a defined layout.

Almost any .tar.gz can be a Hoist artifact, as long as it has a bin/launch script or directory of scripts to exec under process management (we use Runit).

Hoist artifacts are totally self-contained and are expected to have all dependencies statically linked internally with very few exceptions.

P2 executes artifacts in resource constrained cgroups as different users with different home directories to create extremely lightweight isolation.

Pods, Labels and Replication Controllers

Kubernetes provides some excellent tools for grouping and managing sets of applications. We copied them! We didn't want to wait to have our entire Docker ecosystem established (new build system, new kernel, etc) to start using these great higher-order orchestration primitives.

We currently have production-quality support for pod manifests, replication controllers and rolling updates, analagous to Kubernetes pods, replication controllers and deployments, respectively. We are also actively working on pod clusters, our variation on Kubernetes services.

More stuff!

We had to solve a number of problems that Square has today. That led us to the following concepts built-in from the beginning:

  • Arbitrary configuration files written into the pod manifest, exported and mounted at CONFIG_PATH for applications.
  • Application lifecycle management and health. During the shutdown of an instance, we first run bin/disable. When starting up an instance, we run bin/enable, and then monitor the application via a call to GET /_status. A 200 response code means ready and healthy.
  • Rich plugin architecture for secret company stuff. For example, our integration with Keywhiz is implemented in an after_install hook. The hooks package in this repo provides a handy Go library for writing hooks that can be scheduled.
  • Self-hosting! We wanted to deploy P2 with P2, so we did that. The binary p2-bootstrap allows you to set up a Consul agent and a P2 preparer on the same host. If done right, that host should allow any future deploys to Just Work, including to both the Consul agent and the preparer themselves!
  • Deployment Authorization. From the beginning we needed a way to restrict who can start which applications. The preparer can be given an ACL that can be enforced by GPG signatures on pod manifests, signed by the deployer. Or if you hate GPG, you can use delegated signing with a trusted orchestration service.

Playing Around

To build the tools in p2, run rake build. The bin subdirectory contains agents and executables, the pkg directory contains useful libraries for Go. We strongly believe in small things that do one thing well.

Layout

  • bin/ contains executables that, together, manage deployment. The bootstrap executable can be used to set up new nodes.
  • pkg/ contains standalone libraries that provide supporting functionality of the executables. These libraries are all useful in isolation.

Integration Test

Running rake integration will attempt to launch a Vagrant Centos7 machine on your computer, launch Consul and our preparer and then launch an application. If you see a success message, you can vagrant up the halted box to check out the setup without needing to do any work yourself.

Ensure that Vagrant and VirtualBox are installed if rake integration does not work.

Dependencies

P2 is based on existing deployment tools at Square. The following list reflects all the system dependencies required by every P2 library, although many libraries require only one of these or are dependency-free.

Many P2 binaries expect to be able to invoke the p2-exec binary, ideally by knowing its full path. The location can be set at compile-time by modifying the github.com/square/p2/pkg/p2exec.DefaultP2Exec variable. The -X flag to go install -ldflags can be used to perform this assignment.

If the preparer config option process_result_reporter_config is set, the preparer will crash unless the configured extractor exists. We provide one possible implementation at p2-finish-env-extractor.

Desirable Features

Adding Docker support is a big next step, but will ultimately help us migrate to using Docker (or equally excellent RunC implementation) at Square.

P2 also lacks a native job admission / scheduling system, so all pod scheduling is currently done manually by client using either a label selector or simply a hostname. Solutions to this are to be determined.

License

Apache 2.0

p2's People

Contributors

anthonybishopric avatar ausmith avatar brianrli avatar bunsenmcdubbs avatar bwester avatar csstaub avatar cuzelac avatar derektamsen avatar drcapulet avatar esuen avatar jackdanger avatar jbowens avatar jsoref avatar koishikomeiji avatar mcpherrinm avatar mpuncel avatar mweissbacher avatar petertseng avatar praneeth-sq avatar robertabbott avatar rudle avatar simmons-square avatar spenceral avatar stouset avatar tummychow avatar xaviershay avatar zapman449 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

p2's Issues

Data race due to consul dependencies

==================
WARNING: DATA RACE
Read at 0x00c4201726c8 by goroutine 98:
  github.com/square/p2/vendor/github.com/hashicorp/consul/consul.(*Server).leaderLoop()
      /home/travis/gopath/src/github.com/square/p2/vendor/github.com/hashicorp/consul/consul/leader.go:60 +0x12f
Previous write at 0x00c4201726c8 by goroutine 30:
  github.com/square/p2/vendor/github.com/hashicorp/consul/consul.NewServer()
      /home/travis/gopath/src/github.com/square/p2/vendor/github.com/hashicorp/consul/consul/server.go:268 +0x146e
  github.com/square/p2/vendor/github.com/hashicorp/consul/command/agent.(*Agent).setupServer()
      /home/travis/gopath/src/github.com/square/p2/vendor/github.com/hashicorp/consul/command/agent/agent.go:406 +0x162
  github.com/square/p2/vendor/github.com/hashicorp/consul/command/agent.Create()
      /home/travis/gopath/src/github.com/square/p2/vendor/github.com/hashicorp/consul/command/agent/agent.go:203 +0x1010
  github.com/square/p2/pkg/store/consul/consulutil.NewFixture()
      /home/travis/gopath/src/github.com/square/p2/pkg/store/consul/consulutil/consultest.go:80 +0x4eb
  github.com/square/p2/pkg/store/consul.NewConsulTestFixture()
      /home/travis/gopath/src/github.com/square/p2/pkg/store/consul/fixtures_test.go:20 +0x6a
  github.com/square/p2/pkg/store/consul.TestGetHealthNoEntry()
      /home/travis/gopath/src/github.com/square/p2/pkg/store/consul/kv_test.go:15 +0x66
  testing.tRunner()
      /home/travis/.gimme/versions/go1.7.4.linux.amd64/src/testing/testing.go:610 +0xc9
Goroutine 98 (running) created at:
  github.com/square/p2/vendor/github.com/hashicorp/consul/consul.(*Server).monitorLeadership()
      /home/travis/gopath/src/github.com/square/p2/vendor/github.com/hashicorp/consul/consul/leader.go:39 +0x206
Goroutine 30 (running) created at:
  testing.(*T).Run()
      /home/travis/.gimme/versions/go1.7.4.linux.amd64/src/testing/testing.go:646 +0x52f
  testing.RunTests.func1()
      /home/travis/.gimme/versions/go1.7.4.linux.amd64/src/testing/testing.go:793 +0xb9
  testing.tRunner()
      /home/travis/.gimme/versions/go1.7.4.linux.amd64/src/testing/testing.go:610 +0xc9
  testing.RunTests()
      /home/travis/.gimme/versions/go1.7.4.linux.amd64/src/testing/testing.go:799 +0x4ba
  testing.(*M).Run()
      /home/travis/.gimme/versions/go1.7.4.linux.amd64/src/testing/testing.go:743 +0x12f
  main.main()
      github.com/square/p2/pkg/store/consul/_test/_testmain.go:92 +0x1b8

Health checks talk to hostname

Right now, health checks do an HTTP request to the hostname:

sc.URI = fmt.Sprintf("https://%s:%d%s", node, man.Manifest.GetStatusPort(), man.Manifest.GetStatusPath())

Since p2-preparer runs on the same node, it could just talk to localhost instead. This way apps can serve the status port on the loopback interface only. In many cases, it's not necessary to expose it to the outside world.

(Alternatively, would it make sense to have this be configurable?)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.