5

Sto scrivendo involucri di Chef intorno ad alcuni dei libri di cucina OpsWorks integrati. Sto usando Berkshelf per clonare i libri di cucina OpsWorks dal loro repo github.Come si prendono in giro i servizi/dipendenze specifici di OpsWorks durante lo sviluppo locale con Kitchen and Chef?

Questo è il mio Berksfile:

source 'https://supermarket.getchef.com' 

metadata 

def opsworks_cookbook(name) 
    cookbook name, github: 'aws/opsworks-cookbooks', branch: 'release-chef-11.10', rel: name 
end 

%w(dependencies scm_helper mod_php5_apache2 ssh_users opsworks_agent_monit 
    opsworks_java gem_support opsworks_commons opsworks_initial_setup 
    opsworks_nodejs opsworks_aws_flow_ruby 
    deploy mysql memcached).each do |cb| 
    opsworks_cookbook cb 
end 

mio metadata.rb:

depends 'deploy' 
depends 'mysql' 
depends 'memcached' 

Il problema è che quando cerco di ignorare gli attributi che dipendono dalla chiave opsworks nel node hash, ho get a:

NoMethodError 
------------- 
undefined method `[]=' for nil:NilClass 

OpsWorks ha un sacco di dipendenze pre-ricetta quelli che creano queste chiavi e ne fanno molte. Mi piacerebbe trovare un modo per entrare in questi servizi ed eseguirli contro le istanze di Kitchen o prenderli in giro in modo da poter effettivamente testare le mie ricette.

C'è un modo per farlo?

risposta

0

Dovrai farlo manualmente. Puoi aggiungere attributi arbitrari al tuo .kitchen.yml, basta andare su un computer OpsWorks e registrare i valori necessari e usarli direttamente o adattarli a dati di test realizzabili.

+0

Questo ancora non risolve il problema di testare le ricette che dipendono dalle ricette integrate di Amazon. Stai suggerendo di utilizzare Berkshelf per inserire tutte le ricette OpsWorks, eseguirle, quindi eseguire le mie ricette? E se volessi, per esempio, installare 'mysql :: client' che richiede' node [: opsworks] [: layers] [: db-master] 'o' node [: opsworks] [: stack] [: rds_instances] [i] [: engine] == 'mysql''? Capisco come eseguire queste ricette, ma come faccio a testarle usando chefspec? – davepgreene

+1

Sì, il tuo Berksfile esistente è corretto per quanto riguarda i libri di cucina giusti. ChefSpec è solo un test unitario, quindi le dipendenze in genere non dovrebbero importare, ma tu faresti la stessa cosa con Test Kitchen con i dati del nodo fisso. – coderanger

+1

Capisco. Segnalo come risposta perché mi hai indicato nella giusta direzione. Grazie! – davepgreene

3

vi consiglio vivamente di controllare post sul blog di Mike Greiling Simplify OpsWorks Development With Packer e il suo repo github opsworks-vmche vi aiutano a deridere l'intero opsworks pila compresa l'installazione dell'agente opsworks modo da poter Test App distribuire ricette, strati multipli, più istanze allo stesso tempo, ecc.. È estremamente impressionante.

Quick Start su Ubuntu 14.04

NOTA: questo non può essere fatto da una macchina virtuale Ubuntu perché VirtualBox non supporta la virtualizzazione annidata di macchine a 64-bit.

  1. Installare ChefDK
    1. mkdir /tmp/packages && cd /tmp/packages
    2. wget https://opscode-omnibus-packages.s3.amazonaws.com/ubuntu/12.04/x86_64/chefdk_0.8.1-1_amd64.deb
    3. sudo dpkg -i chefdk_0.8.0-1_amd64.deb
    4. cd /opt/chefdk/
    5. chef verify
    6. which ruby
    7. echo 'eval "$(chef shell-init bash)"' >> ~/.bash_profile && source ~/.bash_profile
  2. Installare VirtualBox
    1. echo 'deb http://download.virtualbox.org/virtualbox/debian vivid contrib' > /etc/apt/sources.list.d/virtualbox.list
    2. wget -q https://www.virtualbox.org/download/oracle_vbox.asc -O- | sudo apt-key add -
    3. sudo apt-get update -qqy
    4. sudo apt-get install virtualbox-5.0 dkms
  3. Installare Vagrant
    1. cd /tmp/packages
    2. wget https://dl.bintray.com/mitchellh/vagrant/vagrant_1.7.4_x86_64.deb
    3. sudo dpkg -i vagrant_1.7.4_x86_64.deb
    4. vagrant plugin install vagrant-berkshelf
    5. vagrant plugin install vagrant-omnibus
    6. vagrant plugin list
  4. Installare Packer
    1. mkdir /opt/packer && cd /opt/packer
    2. wget https://dl.bintray.com/mitchellh/packer/packer_0.8.6_linux_amd64.zip
    3. unzip packer_0.8.6_linux_amd64.zip
    4. echo 'PATH=$PATH:/opt/packer' >> ~/.bash_profile && source ~/.bash_profile
  5. costruire l'immagine opsworks-vm virtualbox di Mike Greiling utilizzando Packer
    1. mkdir ~/packer && cd ~/packer
    2. git clone https://github.com/pixelcog/opsworks-vm.git
    3. cd opsworks-vm
    4. rake build install
    5. Questo installerà una nuova VM VirtualBox a ~/.vagrant.d/scatole/ubuntu1404-opsworks/

prendere in giro una singola istanza opsworks, creare un nuovo Vagrantfile in questo modo:

Vagrant.configure("2") do |config| 
    config.vm.box = "ubuntu1404-opsworks" 
    config.vm.provision :opsworks, type: 'shell', args: 'path/to/dna.json' 
end 

Il percorso dna.json file viene impostato rispetto al Vagrantfile e dovrebbe contiene tutti i dati JSON che desideri inviare a OpsWorks Chef.

Ad esempio:

{ 
    "deploy": { 
    "my-app": { 
     "application_type": "php", 
     "scm": { 
     "scm_type": "git", 
     "repository": "path/to/my-app" 
     } 
    } 
    }, 
    "opsworks_custom_cookbooks": { 
    "enabled": true, 
    "scm": { 
     "repository": "path/to/my-cookbooks" 
    }, 
    "recipes": [ 
     "recipe[opsworks_initial_setup]", 
     "recipe[dependencies]", 
     "recipe[mod_php5_apache2]", 
     "recipe[deploy::default]", 
     "recipe[deploy::php]", 
     "recipe[my_custom_cookbook::configure]" 
    ] 
    } 
} 

per deridere le istanze multiple opsworks e comprendono strati vedere la sua AWS OpsWorks "Getting Started" Example che include il stack.json di seguito.

Vagrantfile (per istanze multiple)

Vagrant.configure("2") do |config| 

    config.vm.box = "ubuntu1404-opsworks" 

    # Create the php-app layer 
    config.vm.define "app" do |layer| 

    layer.vm.provision "opsworks", type:"shell", args:[ 
     'ops/dna/stack.json', 
     'ops/dna/php-app.json' 
    ] 

    # Forward port 80 so we can see our work 
    layer.vm.network "forwarded_port", guest: 80, host: 8080 
    layer.vm.network "private_network", ip: "10.10.10.10" 
    end 

    # Create the db-master layer 
    config.vm.define "db" do |layer| 

    layer.vm.provision "opsworks", type:"shell", args:[ 
     'ops/dna/stack.json', 
     'ops/dna/db-master.json' 
    ] 

    layer.vm.network "private_network", ip: "10.10.10.20" 
    end 
end 

stack.json

{ 
    "opsworks": { 
    "layers": { 
     "php-app": { 
     "instances": { 
      "php-app1": {"private-ip": "10.10.10.10"} 
     } 
     }, 
     "db-master": { 
     "instances": { 
      "db-master1": {"private-ip": "10.10.10.20"} 
     } 
     } 
    } 
    }, 
    "deploy": { 
    "simple-php": { 
     "application_type": "php", 
     "document_root": "web", 
     "scm": { 
     "scm_type": "git", 
     "repository": "dev/simple-php" 
     }, 
     "memcached": {}, 
     "database": { 
     "host": "10.10.10.20", 
     "database": "simple-php", 
     "username": "root", 
     "password": "correcthorsebatterystaple", 
     "reconnect": true 
     } 
    } 
    }, 
    "mysql": { 
    "server_root_password": "correcthorsebatterystaple", 
    "tunable": {"innodb_buffer_pool_size": "256M"} 
    }, 
    "opsworks_custom_cookbooks": { 
    "enabled": true, 
    "scm": { 
     "repository": "ops/cookbooks" 
    } 
    } 
} 

Per chi non ha familiarità con il vagabondo si basta fare una vagrant up per avviare l'istanza (s). Quindi puoi modificare il tuo libro di cucina localmente ed eventuali modifiche possono essere applicate da chef di re-running contro l'istanza (i) esistente con vagrant provision. Puoi fare un vagrant destroy e vagrant up per iniziare da zero.

Problemi correlati