building a private supermarket for your organization - chefconf 2015

30
Building a Private Supermarket for your Organization Justin Dossey

Upload: chef

Post on 16-Aug-2015

69 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Building a Private Supermarket for your Organization - ChefConf 2015

Building  a  Private  Supermarket  for  your  Organization

Justin  Dossey

Page 2: Building a Private Supermarket for your Organization - ChefConf 2015

Who  I  am  (and  why  you  should  listen  to  me)

• I’m  Justin  Dossey.  • Twenty  years  as  a  professional  sysadmin  

• Ten  years  as  a  Rubyist  • Seven  years  with  CM  • I  just  built  a  bunch  of  supermarkets  a  couple  of  months  ago  

• We’re  hiring!    Talk  to  me  after.

Page 3: Building a Private Supermarket for your Organization - ChefConf 2015

A  Brief  History  of  the  Supermarket

Page 4: Building a Private Supermarket for your Organization - ChefConf 2015

A  Brief  History  of  the  Supermarket• Built  for  Chef  as  a  simple  Ruby  on  Rails  app  • Hosted  in  AWS  • First  commit  (on  Github):  October  2013  • Originally  designed  as  something  to  be  hosted  for  Chef,  by  Chef,  as  a  public  thing  

• This  means  that  stuff  like  CLA  signing  was  baked  in  early  

• It  also  means  some  things  about  private  are  funky

Page 5: Building a Private Supermarket for your Organization - ChefConf 2015

Why  Build  Private?• The  organization  makes  a  lot  of  its  own  cookbooks  

• Public  supermarket  may  provide  cookbooks  of  suspect  quality  

• The  organization  is  worried  that  the  public  supermarkets  could  be  closed  when  it  needs  to  shop  

• Worries  that  the  public  supermarket  could  be  robbed  or  infiltrated

Page 6: Building a Private Supermarket for your Organization - ChefConf 2015

The  Public  Supermarket  Codemakes  the  private  supermarket  possible

Page 7: Building a Private Supermarket for your Organization - ChefConf 2015

The  Supermarket  is  Open-­‐Source• Chef  makes  the  supermarket  code  available  to  everyone  

• If  they  can  run  one,  so  can  we!  • …but  we’re  not  Chef,  so  we  might  have  to  change  some  things  about  how  it  works.  

• There  are  an  awful  lot  of  build  dependencies  • …  but  there’s  a  cookbook,  so  it’s  easy,  right?

Page 8: Building a Private Supermarket for your Organization - ChefConf 2015

Moving  Partshow  the  supermarket  works

Page 9: Building a Private Supermarket for your Organization - ChefConf 2015

Supermarket  Architecture

• Supermarket  is  a  Ruby  on  Rails  application.  • It  talks  to  a  Postgres  Database  • It  uses  dotenv  to  store  environment  variables  (usually  related  to  config)  • It  uses  omniauth  +  devise  • Redis  is  in  there  too

9

Page 10: Building a Private Supermarket for your Organization - ChefConf 2015

Supermarket  Architecture• Lots  of  integrations  with  external  services:  

• oc-­‐id  on  the  Chef  server  • Github  • StatsD  • Sentry  • Amazon  S3  • Fieri  • Curry  • Pubsubhubbub  • The  SMTP  relay  • New  Relic  • Google  Analytics

10

Page 11: Building a Private Supermarket for your Organization - ChefConf 2015

Our  Minimum  Working  Set• Lots  of  integrations  with  external  services:  

• oc-­‐id  on  the  Chef  server  • Github  • StatsD  • Sentry  • Amazon  S3  • Fieri  • Curry  • Pubsubhubbub  • The  SMTP  relay  • New  Relic  • Google  Analytics

11

Page 12: Building a Private Supermarket for your Organization - ChefConf 2015

ConfiguringFun  with  Data  Bags

Page 13: Building a Private Supermarket for your Organization - ChefConf 2015

Yes,  Data  Bags.• For  whatever  reason,  Chef’s  Supermarket  developers  decided  that  the  best  place  to  put  the  application  configuration  was  a  data  bag.      

• Back  in  2013,  this  probably  made  sense.  • That  decision  remains  with  us  today  and  feels  weird,  because  we  all  write  wrapper  cookbooks  to  accomplish  the  same  thing  nowadays.  

• The  data  bag  we  need  is  called  “apps/supermarket.”

Page 14: Building a Private Supermarket for your Organization - ChefConf 2015

Stuff  in  the  Data  Bag• redis  URL  • SMTP  server  info  • github  info  • oauth2  tokens  for  oc-­‐id  • curry  info  • sentry  url  • which  revision  of  supermarket  to  clone  • a  bunch  of  URLs

Page 15: Building a Private Supermarket for your Organization - ChefConf 2015

Stuff  not  in  the  Data  Bag• SSL  stuff  • supermarket  hostname  • deploy  location  • some  database  config  stuff  • some  sidekiq  stuff

Page 16: Building a Private Supermarket for your Organization - ChefConf 2015

Doing  this  Ourselves

Page 17: Building a Private Supermarket for your Organization - ChefConf 2015

Write  a  Wrapper  Cookbook• Put  attributes  and  a  working  data  bag  in  place.      • Get  the  .kitchen.yml  written  and  the  thing  building  in  dev,  then  build  the  production  system.  

• Read  the  docs—  this  stuff  is  changing  pretty  frequently.  

• When  stuff  breaks,  look  carefully  at  the  production.log,  the  .env  file,  and  the  data  bag.

Page 18: Building a Private Supermarket for your Organization - ChefConf 2015

Authentication  to  the  Chef  Server• The  Chef  server  needs  to  know  who  is  allowed  to  register  apps  for  oc-­‐id  auth.  

• Last  I  checked,  that  was  a  line  in  /etc/opscode/chef-server.rb  like  this:

• Once  that’s  in  and  we  run  chef-server-ctl reconfigure,  we  can  get  the  oauth  stuff  we  need  for  that  data  bag.

oc_id[‘administrators’] = [‘chef_username’]

Page 19: Building a Private Supermarket for your Organization - ChefConf 2015

Continuous  Integration  and  Continuous  Deployment  for  

Cookbooks

A  brief  overview  of  pipeline  design  for  infrastructure  code

Page 20: Building a Private Supermarket for your Organization - ChefConf 2015

How  it’s  Usually  Done

Page 21: Building a Private Supermarket for your Organization - ChefConf 2015

Doing  it  with  Supermarket

Page 22: Building a Private Supermarket for your Organization - ChefConf 2015

Sticky  Situations

Page 23: Building a Private Supermarket for your Organization - ChefConf 2015

Cookbook  Naming

• Berkshelf  has  a  flat  namespace.  • We  can  specify  multiple  sources  for  Berkshelf.  

• If  our  (in-­‐house)  cookbook  is  named  the  same  as  one  on  the  public  supermarket,  the  version  is  the  only  differentiator.    This  can  also  collide.  

• Switching  to  a  single  origin  means  someone  has  to  upload  community  cookbooks  to  the  private  supermarket  

• Doing  this  trades  namespace  collisions  for  pipeline  and  maintenance  overhead

Page 24: Building a Private Supermarket for your Organization - ChefConf 2015

Cookbook  Ownership

• With  the  pipeline  proposed,  the  only  uploader  of  cookbooks  is  a  role  user—Jenkins.      

• Therefore,  connecting  supermarket  accounts  to  github  accounts  is  weird.  

• We  wind  up  assigning  ownership  outside  Supermarket.

Page 25: Building a Private Supermarket for your Organization - ChefConf 2015

The  Future  of  Private  Supermarkets

Page 26: Building a Private Supermarket for your Organization - ChefConf 2015

Supermarket  Omnibus  Installer• Increasingly,  Chef  is  pushing  installation  via  pre-­‐built  packages  instead  of  the  Supermarket  cookbook.  

• This  means  that  instead  of  the  data  bag  and  such,  we  will  write  a  simple  wrapper  cookbook  to  install  a  package  and  configure  components  as  necessary.  

• It  is  unlikely  that  this  newer  method  will  affect  any  of  the  integration  points.

Page 27: Building a Private Supermarket for your Organization - ChefConf 2015

Review

Page 28: Building a Private Supermarket for your Organization - ChefConf 2015

Review• Running  a  private  supermarket  means  adapting  the  public  code  (which  performs  tasks  relevant  to  the  public  supermarket)  to  our  needs  • We  need  our  own  chef  server  to  host  a  private  supermarket  • The  supermarket  cookbook  uses  a  data  bag  for  some  configuration  data  • There  are  many  external  integration  points  which  we  can  select  if  we  like,  but  most  are  not  required  for  basic  operation  • We  have  to  decide  how  to  approach  namespace  and  ownership  issues  early  on

28

Page 29: Building a Private Supermarket for your Organization - ChefConf 2015

Questions

Page 30: Building a Private Supermarket for your Organization - ChefConf 2015

Thank  you!

(Did  I  mention  we  are  hiring?)

Find  me!  blog:  www.justindossey.com  twitter:  @justindossey  irc:  jdossey  on  #chef  (freenode)  email:  [email protected]