• Stars
    star
    303
  • Rank 137,655 (Top 3 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created about 8 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Develop and deploy complex Docker applications

Cage: Develop and deploy complex Docker applications

Latest version License Build Status Build status Documentation Gitter

Logo

Does your project have too many Docker services? Too many git repos? Cage makes it easy to develop complex, multi-service applications locally. It works with standard docker-compose.yml files and docker-compose, but it helps bring order to the complexity:

  • Cage provides a standardized project structure, much like Rails did for web development.
  • Cage allows you to work with multiple source repositories, and to mix pre-built Docker images with local source code.
  • Cage removes the repetitive clutter from your docker-compose.yml files.
  • Cage provides secret management, either using a single text file or Hashicorp's Vault.

For more information about Cage, see the introductory website.

Installation

First, you need to install Docker and make sure that you have at least version 1.8.1 of docker-compose:

$ docker-compose --version
docker-compose version 1.8.1, build 878cff1

We provide pre-built cage binaries for Linux and MacOS on the release page. The Linux binaries are statically linked and should work on any modern Linux distribution. To install, you can just unzip the binaries and copy them to /usr/local/bin:

unzip cage-*.zip
sudo cp cage /usr/local/bin/
rm cage-*.zip cage

If you would like to install from source, we recommend using rustup and cargo install:

curl https://sh.rustup.rs -sSf | sh
cargo install cage

If you have trouble using cage's vault integration, try installing with cargo instead.

Note that it's possible to build cage for Windows, but it's still not yet officially supported.

Trying it out

Create a new application using cage:

cage new myapp
cd myapp

Pull the pre-built Docker images associated with this application and start up the database pod:

cage pull
cage up db

Run the rake image to initialize your database:

cage run rake db:create
cage run rake db:migrate

And bring up the rest of the app:

cage up

Let's take a look at the pods and services defined by this application:

$ cage status
db enabled type:placeholder
└─ db
frontend enabled type:service
└─ web ports:3000
rake enabled type:task
└─ rake

This shows us that the web service is listening on port 3000, so you should be able to access the application at http://localhost:3000. But let's make a change! First, list the available source code for the services in this app:

$ cage source ls
rails_hello               https://github.com/faradayio/rails_hello.git

Try mounting the source code for rails_hello into all the containers that use it:

$ cage source mount rails_hello
$ cage up
$ cage source ls
rails_hello               https://github.com/faradayio/rails_hello.git
  Cloned at src/rails_hello (mounted)

You may also notice that since myapp_rake_1 is based on the same underlying Git repository as myapp_web_1, that it also has a mount of src/rails_hello in the appropriate location. If you change the source on your host system, it will automatically show up in both containers.

Now, create an HTML file at src/rails_hello/public/index.html:

<html>
  <head><title>Sample page</title></head>
  <body><h1>Sample page</h1></body>
</html>

And reload the website in your browser. You should see the new page!

We can also run container-specific unit tests, which are specified by the container, so that you can invoke any unit test framework of your choice:

cage test web

And we can access individual containers using a configurable shell:

$ cage shell web
root@21bbbb41ad4a:/usr/src/app#

The top-level convenience commands like test and shell make it much easier to perform standard development tasks without knowing how individual containers work.

For more information, check out cage's help:

cage --help

What's a pod?

A "pod" is a tightly-linked group of containers that are always deployed together. Kubernetes defines pods as:

A pod (as in a pod of whales or pea pod) is a group of one or more containers (such as Docker containers), the shared storage for those containers, and options about how to run the containers. Pods are always co-located and co-scheduled, and run in a shared context. A pod models an application-specific β€œlogical host” - it contains one or more application containers which are relatively tightly coupled β€” in a pre-container world, they would have executed on the same physical or virtual machine.

If you're using Amazon's ECS, a pod corresponds to an ECS "task" or "service". If you're using Docker Swarm, a pod corresponds to a single docker-compose.xml file full of services that you always launch as a single unit.

Pods typically talk to other pods using ordinary DNS lookups or service discovery. If a pod accepts outside network connections, it will often do so via a load balancer.

Project format

See examples/hello for a complete example.

hello
└── pods
    β”œβ”€β”€ common.env
    β”œβ”€β”€ frontend.yml
    └── targets
        β”œβ”€β”€ development
        β”‚Β Β  └── common.env
        β”œβ”€β”€ production
        β”‚Β Β  β”œβ”€β”€ common.env
        β”‚Β Β  └── frontend.yml
        └── test
            └── common.env

File types

Filename Description Found in
common.env Sets environment variables at different levels. common is a reserved word. Top-level pods/ dir and also in target dirs (production, etc.)
$SERVICE.yml Valid docker-compose.yml version 2 defining images, etc. Top-level pods/ dir and also in target dirs (production, etc.)
$SERVICE.metadata.yml Pod-level metadata that isn't valid in docker-compose.yml version 2. Top-level pods/ dir and also in target dirs (production, etc.)

Other commands

cage run-script

The run-script command operates similarly to npm run <script> or rake <task>. Simply define a set of named scripts in the pod's metadata:

# tasks.yml
services:
  runner:
    build: .
# tasks.metadata.yml

services:
  runner:
    scripts:
      populate:
        - ["npm","run","populate"]

By running cage run-script populate, cage will find all services that have a populate script and run it. You can also specify a pod or service with cage run-script tasks populate.

Reporting issues

If you encounter an issue, it might help to set the following shell variables and re-run the command:

export RUST_BACKTRACE=1 RUST_LOG=cage=debug,compose_yml=debug

Development notes

Pull requests are welcome! If you're unsure about your idea, then please feel free to file an issue and ask us for feedback. We like suggestions!

Setting up tools

When working on this code, we recommend installing the following support tools:

rustup component add rustfmt
rustup component add clippy
cargo install cargo-watch

Run the following in a terminal as you edit:

cargo watch -x test

Before committing your code, run:

cargo clippy
cargo fmt

This will automatically check for warnings, and reformat your code according to the project's conventions. We use Travis CI to verify that cargo fmt has been run and that the project builds with no warnings. If it fails, no worriesβ€”just go ahead and fix your pull request, or ask us for help.

On MacOS

The openssl crate needs a compatible version of the openssl libraries. You may be able to install them as follows:

brew install openssl

Official releases

To make an official release, you need to be a maintainer, and you need to have cargo publish permissions. If this is the case, first edit Cargo.toml to bump the version number, then regenerate Cargo.lock using:

cargo build

Commit the release, using a commit message of the format:

v<VERSION>: <SUMMARY>

<RELEASE NOTES>

Then run:

cargo publish
git tag v$VERSION
git push; git push --tags

This will rebuild the official binaries using Travis CI, and upload a new version of the crate to crates.io.

More Repositories

1

tilesplash

a light and quick nodejs vector tile server for use with a postgis backend
JavaScript
176
star
2

hangar

Use Rails/FactoryGirl factories from your frontend tests
Ruby
56
star
3

scrubcsv

Remove bad records from a CSV file and normalize
Rust
55
star
4

earth

Land, sky, and sea
Ruby
41
star
5

credentials_to_env

Downloads credentials from Hashicorp's Vault, and writes them to env vars and/or files before executing another process.
Rust
38
star
6

devise-auth0

Authenticate auth0 users in ruby web apps
Ruby
31
star
7

utility-landscape

A repository for creating and maintaining a geospatial representation of U.S. electrical utilities' service territories
Shell
19
star
8

exec-rs

Rust wrapper around the C execvp function, which replaces the current process with the specified program and arguments.
Rust
13
star
9

tronprint

Estimate your Ruby application's carbon footprint
Ruby
10
star
10

vault-env-js

Put your vault secrets in your process.env
TypeScript
10
star
11

catcsv

Concatenate CSV files, directories of CSV files, and snappy-compressed CSV files.
Rust
9
star
12

selectstar

Generate safe SQL statements with tagged literals
TypeScript
9
star
13

argo

Rapid reverse-geocoding using Mapzen Search
JavaScript
8
star
14

carbon-old

Gem implementing Brighter Planet's emissions estimates API
Ruby
7
star
15

falconeri

Transform lots of data using a Kubernetes cluster
Rust
7
star
16

node_smartystreets

DEPRECATED - use https://github.com/faradayio/geocode-csv. Was: fast SmartyStreets geocoder
TypeScript
7
star
17

carbon

Brighter Planet CM1 client for Ruby
Ruby
7
star
18

api

Documentation and resources for the Faraday API
6
star
19

geocode-csv

Geocode a CSV file using the SmartyStreets API
Rust
6
star
20

add-vault-tokens

Given a docker-compose.yml file and master token for vault, generate individual, restricted tokens for each app in the docker-compose.yml file.
Ruby
6
star
21

csvkiller

Segment CSV files by any column
JavaScript
6
star
22

emitter

The umbrella library for all Brighter Planet environmental impact models.
Ruby
6
star
23

csv-tools

Rust tools for working with CSV files: scrubcsv, catcsv, fixed2csv, geochunk, hashcsv.
Jupyter Notebook
4
star
24

geochunk

Group zip codes into "geochunks" with similar-sized populations. Run on CSV in a pipeline to add a column, or export the geochunk table.
Jupyter Notebook
4
star
25

brighter_planet_layout

Layout assets for Brighter Planet sites
Ruby
4
star
26

automobile

A carbon model
Ruby
4
star
27

ecs_compose

WORK IN PROGRESS: docker-compose.yml-based interface for Amazon EC2 Container Service (ECS)
Ruby
4
star
28

hootroot1

Hootroot: give a hoot, green your route
JavaScript
4
star
29

hangarjs

Hangar's other half
JavaScript
4
star
30

Leaflet.CanvasMask

Mask geojson stuff with canvas and stuff
JavaScript
3
star
31

barbq

Python-native SQL dialect that renders to BigQuery
Python
3
star
32

computation

A carbon model.
Ruby
3
star
33

flight

A carbon model
Ruby
3
star
34

remote-task

Simple server for remotely running tasks and logging their output to papertrail
JavaScript
3
star
35

charisma

Define attribute curation and display strategies for your rich Ruby classes
Ruby
3
star
36

greendreams

APIs for the environment
JavaScript
3
star
37

brighter_planet_metadata

Names of resources, emitters, etc. provided by Brighter Planet.
Ruby
3
star
38

censusapi2csv

A tool for downloading Census/ACS data from the API and parsing to CSV
JavaScript
3
star
39

angular-liveaddress

Use SmartyStreets to autocomplete address fields
JavaScript
3
star
40

electricity_use

Brighter Planet CM1 Carbon model for general electricity use
Ruby
3
star
41

gistkiller

Clean up your gists, hide those skeletons
Ruby
2
star
42

journaling-hash

Immutable hash that can back itself up to a file and rebuild itself
JavaScript
2
star
43

places

Faraday's gazetter: 78,000 of the best places in the U.S. (all of them)
2
star
44

energy

Energy use information client
Ruby
2
star
45

bigml-rs

A Rust client library for the BigML machine learning service (WIP).
Rust
2
star
46

greenbac

A Carbon Middleware demo
JavaScript
2
star
47

through2-linereader

Yet another line reader stream, uses through2
JavaScript
2
star
48

plancha

A node CLI tool to flatten multi-sheet/tab spreadsheet files
JavaScript
2
star
49

RepAssignment

rep assignment problems with or-tools
Python
2
star
50

careplane

Careplane is a browser plugin that displays carbon footprints on top of flight search results
JavaScript
2
star
51

sniff

Testing for emissions
Ruby
2
star
52

lock_and_cache_js

Most caching libraries don't do locking, meaning that >1 process can be calculating a cached value at the same time. Since you presumably cache things because they cost CPU, database reads, or money, doesn't it make sense to lock while caching?
TypeScript
2
star
53

numbers

Safety in Numbers, the legacy blog of Brighter Planet
CSS
2
star
54

lodging

A carbon model
Ruby
2
star
55

d3-topojson-layer

Topojson tiles in leaflet with d3
JavaScript
2
star
56

yaktrak

Fedex package trackingβ€”now with COβ‚‚!
Ruby
1
star
57

mapsquare

Get GeoJSON from the Foursquare venues API
JavaScript
1
star
58

hagar1

Development environment for our Rails 2 apps: data1, wlpf1, etc.
Ruby
1
star
59

ubuntu_dbcrossbar

A docker container with dbcrossbar and related utils.
Dockerfile
1
star
60

numbers-staging

Staging environment for the blog
Ruby
1
star
61

fedprint

Carbon footprints of federal contracts
Ruby
1
star
62

bierstadt

Automated print cartography with node.js and d3.js
JavaScript
1
star
63

openapi-interfaces

Extend OpenAPI with support for interfaces and automatic generation of related types like MergePatch. Compile to plain OpenAPI.
Rust
1
star
64

fixed2csv

Converts fixed-width fields to valid CSV data.
Rust
1
star
65

automobile_trip

A carbon model
Ruby
1
star
66

shipment

A carbon model for a shipment
Ruby
1
star
67

kayak1

A Carbon Middleware demo
Ruby
1
star
68

fdy-dendrite

A command-line tool to disaggregate rows in a csv
JavaScript
1
star
69

parsers

A home for parsers used by http://data.brighterplanet.com
1
star
70

aftermath-sites

Aftermath demo
1
star
71

manually_curated_data

A home for lookup tables, dictionaries and errata used by http://data.brighterplanet.com. Name subject to change.
1
star
72

pachyderm_large_file_test

Code to test Pachyderm's large file support
Shell
1
star
73

yardcarbon

Assets for inserting carbon footprints into the EY cloud dashboard
JavaScript
1
star
74

zillow1

A Carbon Middleware demo
Ruby
1
star
75

ci1

Continuous Integration
Ruby
1
star
76

clausfreight

Claus Freight Co. homepage
JavaScript
1
star
77

facility

Ruby
1
star
78

deploy

Brighter Planet's deploy system, published as the brighter_planet_deploy gem
Ruby
1
star
79

consignment

An emissions model
Ruby
1
star
80

ey-cloud-recipes-old1

A starter repo for custom chef recipes on EY's cloud platform
Ruby
1
star
81

cm1-route

Routing/footprint engine extracted from HootRoot
JavaScript
1
star