Dev ninja -> vagrant + virtualbox + chef-solo + git + ec2

870 views
743 views

Published on

Desenvolver rapidamente, criando toda a estrutura PaaS virtualizada localmente, depois de maneira rápida homologar com o cliente e subir o ambiente produção na AWS facilmente.

Published in: Technology
3 Comments
8 Likes
Statistics
Notes
No Downloads
Views
Total views
870
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
0
Comments
3
Likes
8
Embeds 0
No embeds

No notes for slide

Dev ninja -> vagrant + virtualbox + chef-solo + git + ec2

  1. 1. Dev Ninja Vagrant + Virtualbox + Chef-Solo + Git + EC2
  2. 2. Como isso pode ajudar no meu trabalho ?
  3. 3. Vagrant (v 1.5) - Overview - Vagrant Boxes (packer) - Vagrantfile - Basic commands: ● Vagrant up ● Vagrant provision ● Vagrant destroy ● Vagrant ssh ● Vagrant http share
  4. 4. VirtualBox (provider) - Overview - Vboxmanager
  5. 5. EC2 (Provider) - Overview - Tecnologias (IAM, AMI, Elastic IP, Route53)
  6. 6. Chef-Solo (Chef-repo) - Overview - Cookbooks
  7. 7. 1 2 3 4 Layers Juntando tudo (Stack)
  8. 8. Requisitos ● Linux Ubuntu 13.04 ● Install Virtual Box ● Install vagrant ● Install vagrant aws plugin ● Install Git
  9. 9. Mão na massa Install Virtual Box $ sudo apt-get install software-properties-common python-software-properties -y $ sudo sudo add-apt-repository ppa:debfx/virtualbox $ sudo apt-get install virtualbox -y Install Vagrant $ wget https://dl.bintray.com/mitchellh/vagrant/vagrant_1.5.2_x86_64.deb $ sudo dpkg -i vagrant_1.5.2_x86_64.deb $ sudo vagrant plugin install vagrant-aws Install Git $ sudo apt-get install git
  10. 10. My Workspace $ mkdir workspace $ cd wokspace $ mkdir cookbooks $ mkdir data_bags $ mkdir roles
  11. 11. Recipes (Opscode) $ cd workspace/cookbooks Apache $ git clone http://github.com/opscode-cookbooks/apache2 apache2 Mysql $ git clone http://github.com/opscode-cookbooks/mysql mysql Database $ git clone http://github.com/opscode-cookbooks/database database PHP $ git clone http://github.com/opscode-cookbooks/php php
  12. 12. My Application Cookbook CookBook Tree ├── attributes │ └── default.rb ├── metadata.rb ├── recipes │ ├── deploy.rb │ ├── database.rb │ └── templates ├── database..erb └── site_config.erb ● Recipes ● Attributes ● Metadata ● Templates
  13. 13. My Application Cookbook Recipes # FILE: deploy.rb deploy_revision node['webapp']['home'] do repo node["webapp"]["repo"] revision node["webapp"]["revision"] # Disabling rails links and folders migrate false action :deploy # or :rollback before_restart do current_release = release_path end end ["database.php","site_config.php"].each do |php| template "#{current_release}/app/Config/#{php}" do source "#{php}.erb" mode 00644 end restart_command do service "apache2" do action :restart end end # FILE: database.rb # externalize conection info in a ruby hash mysql_connection_info = { :host => "localhost", :username => 'root', :password => node['mysql']['server_root_password'] } # create a mysql database named DB_NAME mysql_database '#{node['webapp']['database']['database']}' do connection mysql_connection_info action [:create] end #or import from a dump file mysql_database "node['webapp']['database']['database']" do connection mysql_connection_info sql "source #{node['webapp']['current_release']}#{node['webapp']['databasedumpfile']};" end # query a database from a sql script on disk mysql_database "#{node['webapp']['database']['database']}" do connection mysql_connection_info sql { ::File.open("#{node['webapp']['current_release']}#{node['webapp']['dbupdatefile']}").read } action :query end
  14. 14. My Application Cookbook Templates Files ● site_config.erb ● database.erb
  15. 15. My Application Cookbook Attributes # Repositorio default["webapp"]["home"] = "/var/lib/webapp" default["webapp"]["repo"] = "git@github.com:yrosaguiar/webappcode.git" default["webapp"]["revision"] = "0.0.1" # Database Config File Params default["webapp"]["database"]["host"] = "localhost" default["webapp"]["database"]["port"] = "3306" default["webapp"]["database"]["login"] = "webapp" default["webapp"]["database"]["password"] = "webapp123" default["webapp"]["database"]["database"] = "webappdb" default["webapp"]["databasedumpfile"] = "/Config/webappdump.sql" default["webapp"]["dbupdatefile"] = "/Config/webappdbupdate.sql" # Site Config File Params default["webapp"]["url"] = "www.webapp.com.br"
  16. 16. Vagrantfile - Virtual Box Provider Vagrant.configure("2") do |config| config.vm.define "webapp" do |define| define.vm.box_url = "http://files.vagrantup.com/precise64.box" define.vm.box = "webapp" define.ssh.forward_agent = true define.vm.hostname = "webapp" define.vm.network :private_network, ip: "172.16.0.100" # Configuration provision define.vm.provision :chef_solo do |chef| chef.cookbooks_path = "./cookbooks" # Recipes chef.add_recipe "apt" chef.add_recipe "git" chef.add_recipe "apache2" chef.add_recipe "php" chef.add_recipe "mysql" chef.add_recipe "webapp:deploy" chef.json.merge!({ }) end end end
  17. 17. Vagrantfile - AWS Provider Vagrant.configure("2") do |config| config.vm.provider :aws do |aws, override| override.vm.box_url ="http://files.vagrantup.com/precise64.box" aws.access_key_id = "YOUR AWS ACCESS KEY" aws.secret_access_key = "YOUR AWS SECRET KEY" aws.keypair_name = "YOUR AWS KEYPAIR NAME" aws.ami = "ami-23d9a94a" aws.instance_type = "m1.large" aws.region = "us-east-1" aws.security_groups = ["open"] aws.user_data = File.read('ec2-setup.sh') override.ssh.username = "vagrant" override.ssh.private_key_path = "AWS PRIVATE KEY" define.vm.provision :chef_solo do |chef| chef.cookbooks_path = "../cookbooks" # Recipes chef.add_recipe "apt" chef.add_recipe "git" chef.add_recipe "apache2" chef.add_recipe "php" chef.add_recipe "mysql" #chef.add_recipe "webapp:deploy" chef.json.merge!({ } ) end end end
  18. 18. Override Attributes Atributos no Vagrantfile chef.json.merge!({ } :mysql => { :server_root_password => "pass123" :bind_address => "0.0.0.0" }, } }) Arquivo de atributos - Ex: default.rb default['mysql']['data_dir'] = '/var/lib/mysql' default['mysql']['server_root_password'] = '123' default['mysql']['packages'] = %w{ mysql-server apparmor-utils } default['mysql']['slow_query_log'] = 1 default['mysql']['slow_query_log_file'] = '/var/log/mysql/slow.log' default['mysql']['bind_address']= '127.0.0.1' # Platformisms.. filesystem locations and such. default['mysql']['basedir'] = '/usr' default['mysql']['tmpdir'] = ['/tmp']
  19. 19. Colher os frutos do trabalho Criar o ambiente dev/homolog local $ vagrant up Atualizar/reconfigurar o seu ambiente $ vagrant provision Acessar o sua VM virtual box $ vagrant ssh Criar login no Vagrantcloud Publicar na internet seu ambiente local $ vagrant share Criar o ambiente Prod/Homolog na AWS $ vagrant up --provider=aws Atualizar/reconfigurar o seu ambiente $ vagrant provision Acessar o sua instancia AWS $ vagrant ssh Publicar na internet seu ambiente local $ vagrant ssh-config (pegar o IP) Associar Elastic IP, Configurar DNS route53
  20. 20. Referências e Dicas http://www.opscode.com http://www.vagrantup.com http://aws.amazon.com https://www.eucalyptus.com/ http://rove.io/ https://github.com/yrosaguiar/vagrantworkspace.git
  21. 21. Thank you Twitter: yrosaguiar Email: yrosaguiar@gmail.com Site: www.cloudadmin.com.br

×