Top Banner
The Twelve-Factor App A Case Study of Pivotal Tracker on Cloud Foundry Glenn Oppegard [email protected]
24

The Twelve Factor App - Pivotal Tracker

Aug 13, 2015

Download

Technology

lauriepino
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: The Twelve Factor App - Pivotal Tracker

The Twelve-Factor AppA Case Study of Pivotal Tracker on Cloud Foundry

Glenn Oppegard [email protected]

Page 2: The Twelve Factor App - Pivotal Tracker

Pivotal Tracker• Development started in 2006, when Pivotal Labs

was starting their Ruby practice

• Ruby 1.8.7 → Ruby 2.1

• Rails 2.3 → Rails 3.2

Page 3: The Twelve Factor App - Pivotal Tracker

1. Codebase

• Single codebase

• Many deploys

Image from 12factor.net, MIT License

Page 4: The Twelve Factor App - Pivotal Tracker

Tracker codebase• Single bosh release git repository

cf-tracker-release/ src/ cf-tracker/ memcached/ tracker/ tracker-frontend/ tracker-solr-home/

Page 5: The Twelve Factor App - Pivotal Tracker

2. Dependencies• Explicitly declare and isolate dependencies

• Ruby: bundler and Gemfile

• Node: npm and package.json

Page 6: The Twelve Factor App - Pivotal Tracker

Tracker dependencies• Bundler

• NPM

• Git sub-modules

• Single artifact containing all dependencies: BOSH final release tarball: cf-tracker-1.2.1.9.tgz

Page 7: The Twelve Factor App - Pivotal Tracker

3. Config• Resource handles to the database, Memcached,

and other backing services

• Credentials to external services such as Amazon S3 or Twitter

• Per-deploy values such as the canonical hostname for the deploy

Page 8: The Twelve Factor App - Pivotal Tracker

Tracker config• All config is centralized to a singleton object

• t2config(:smtp_host)

• Reads from environment variables, but also allows for computed values via Ruby

• Out of 200 config parameters, 25 apply to CF

• Created app_env gem to load static values from JSON files into environment

Page 9: The Twelve Factor App - Pivotal Tracker

• Treat backing services as attached resources.

• The code for a twelve-factor app makes no distinction between local and third party services.

4. Backing Services

Image from 12factor.net, MIT License

Page 10: The Twelve Factor App - Pivotal Tracker

Tracker services

Page 11: The Twelve Factor App - Pivotal Tracker

5. Build, release, run• Strictly separate build and run stages

• Build: compile code, vendor dependencies, minify assets

• Release: combine build output with a deploy's config

• Run.

Page 12: The Twelve Factor App - Pivotal Tracker

Tracker build stages• AWS: Continuous Integrations builds "frontend" assets,

stored in S3

• Local: bosh create release

• Strip code not needed on-premise

• Vendor dependencies (bundle install)

• Download frontend from S3

• CF: Ruby buildpack applied to app source

Page 13: The Twelve Factor App - Pivotal Tracker

6. Processes• Execute the app as one or more stateless

processes

Page 14: The Twelve Factor App - Pivotal Tracker

Tracker processes

Page 15: The Twelve Factor App - Pivotal Tracker

7. Port binding• Export services via port binding

Page 16: The Twelve Factor App - Pivotal Tracker

8. Concurrency• Scale out via the process model

• The unit of currency for a 12-factor app is the process

Page 17: The Twelve Factor App - Pivotal Tracker

Tracker Processes• Web: horizontal scaleout

• Worker: split job-types

• Coming soon: CF Process Types

Page 18: The Twelve Factor App - Pivotal Tracker

9. Disposability• Processes can be killed at any time

• Gracefully handle SIGTERM

• Minimize startup time

Page 19: The Twelve Factor App - Pivotal Tracker

10. Dev/prod parity• Mac vs Linux

• SQLite vs MySQL

• In-memory cache vs Memcached

• Solr

• Coming Soon: Lattice Condenser

Page 20: The Twelve Factor App - Pivotal Tracker

11. Logs• Don't write to disk

• Stream to stdout (or stderr on CF)

Page 21: The Twelve Factor App - Pivotal Tracker

Tracker logs• rails_12factor.gem

• rails_stdout_logging.gem

Page 22: The Twelve Factor App - Pivotal Tracker

12. Admin processes• Run admin/management tasks as one-off

processes

• Run tasks in an identical environment to the deploy (same build and same config → same release)

Page 23: The Twelve Factor App - Pivotal Tracker

Tracker admin tasks• Restrict tasks to index 0 of app

• Future: diego one-off processes

Page 24: The Twelve Factor App - Pivotal Tracker

Credits

• All 12-Factor App diagrams from 12factor.net, MIT License