几个月来,我一直在努力寻找最好的工作stream程,在推送到opsworks之前在本地构build和testing我的aws opsworks食谱。
经过很多停顿的尝试之后,我find了Mike Greiling的一篇博客文章,并且已经在一个适合我的环境中安顿下来了。 我想分享设置/configuration,因为有很多移动的部分。
我鼓励任何有专门针对opsworks食谱的自己的构build/testing环境的厨师,也可以在这里张贴答案 – 谢谢!!
我会高度推荐大家看看Mike Greiling的博客文章Simplify OpsWorks开发Packer和他的github回购opsworks-vm 帮助你模拟整个opsworks堆栈,包括opsworks代理的安装,所以你也可以testing应用程序部署食谱,多层,同时有多个实例等等,这是非常令人印象深刻的。
在使用Mike Greiling的Packer Virtualbox构build之前,我已经包含了准备环境所需的所有设置。
注意:这不能从Ubuntu虚拟机完成,因为virtualbox不支持64位机器的嵌套虚拟化。
mkdir /tmp/packages && cd /tmp/packages wget https://opscode-omnibus-packages.s3.amazonaws.com/ubuntu/12.04/x86_64/chefdk_0.8.1-1_amd64.deb sudo dpkg -i chefdk_0.8.0-1_amd64.deb cd /opt/chefdk/ chef verify which ruby echo 'eval "$(chef shell-init bash)"' >> ~/.bash_profile && source ~/.bash_profile echo 'deb http://download.virtualbox.org/virtualbox/debian vivid contrib' > /etc/apt/sources.list.d/virtualbox.list wget -q https://www.virtualbox.org/download/oracle_vbox.asc -O- | sudo apt-key add - sudo apt-get update -qqy sudo apt-get install virtualbox-5.0 dkms cd /tmp/packages wget https://dl.bintray.com/mitchellh/vagrant/vagrant_1.7.4_x86_64.deb sudo dpkg -i vagrant_1.7.4_x86_64.deb vagrant plugin install vagrant-berkshelf vagrant plugin install vagrant-omnibus vagrant plugin list mkdir /opt/packer && cd /opt/packer wget https://dl.bintray.com/mitchellh/packer/packer_0.8.6_linux_amd64.zip unzip packer_0.8.6_linux_amd64.zip echo 'PATH=$PATH:/opt/packer' >> ~/.bash_profile && source ~/.bash_profile mkdir ~/packer && cd ~/packer git clone https://github.com/pixelcog/opsworks-vm.git cd opsworks-vm rake build install 要模拟一个opsworks实例,像这样创build一个新的Vagrantfile:
Vagrant.configure("2") do |config| config.vm.box = "ubuntu1404-opsworks" config.vm.provision :opsworks, type: 'shell', args: 'path/to/dna.json' end
dna.json文件path是相对于Vagrantfile设置的,应该包含任何你想发送给OpsWorks Chef的JSON数据。
例如:
{ "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]" ] } }
要模拟多个opsworks实例并包含图层,请参阅他的AWS OpsWorks“入门”示例 ,其中包含下面的stack.json 。
Vagrantfile(用于多个实例)
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" } } }
对于那些不熟悉stream浪者的人,你只需要做一个vagrant up来启动实例。 那么你可以在本地修改你的食谱,任何改变都可以通过重新运行厨师来对付现有的无法提供vagrant provision.实例vagrant provision. 你可以做一个vagrant destroy和vagrant up到从头开始。