4

我正在尝试使用 Bento、Veewee 和 Vagrant 来自动化配置 VM 的过程。这种方法在简化开发、开发测试和 QA 流程方面有很大的希望。

(对于那些没有遇到过这些的人——Vagrant 可以轻松地在 Virtual Box、VMWare、EC2 等中快速设置/拆除虚拟机;Veewee 简化了为 Veewee 构建基础盒的过程;Bento 简化了定义基本框,然后自动化 Veewee 的操作)。

问题是,Bento、Veewee 和 Vagrant 的相互关系令人困惑。许多定义文件和一些操作在层间重复,不清楚哪一层应该获得特定于我的项目的更新。Ruby 环境也使这变得相当复杂——似乎 Bento 命令都需要从 Bento 目录运行,所以盒子和其他文件最终会出现在不合逻辑的地方。

任何人都可以建议使用这种工具组合的文件布局和工作流程吗?

4

2 回答 2

4

I'm responding to my own question to capture what I discovered.


There's a way to make Bento, Veewee, Vagrant and Ruby work together in a semi-sensible way, but it's complicated. It's better to use the latest version of Bento that replaces Veewee with the Packer tool.

Packer does more or less what Veewee did, but made some great improvements including:

  1. Each Packer box definition is in a single JSON file that refers to a flat list of script files -- no longer three layers of files with symlinks; easier to understand and better for source code control.

  2. The Packer binaries are OS-native executables (no longer in Ruby). You deploy them by putting them somewhere on your path (like /usr/local/bin on Linux). Packer avoids the Ruby craziness.


Here is a simple workflow:

  1. Install VirtualBox. Install Bento. Bento will also install Vagrant as a Ruby gem; but we won't use that instance of Vagrant. Install Vagrant separately using its native installer for your operating system.

  2. Choose a name for your project to use in dir & file names. (For this example, I'm using "CUSTOM"). Create an empty sub-directory within the bento / packer / scripts directory. I did mkdir CUSTOM.

  3. Review the .JSON files in .../ bento / packer. You can alter one in-place, or it's probably wiser to copy one & alter that. I did cp centos-6.4-x86_64.json centos-6.4-x86_64-CUSTOM.json.

  4. Edit the "builders" section of that file to change the the VM's disk size, RAM size, ssh port etc.

  5. Edit the "provisioners" section, "output" line to provide a meaningful name for the box file to be created. (For this example, I'm using "BOXFILE"). Note that you can embed {{timestamp}} to add a Unix timestamp to the file name -- helps to make the file name unique.

  6. Edit the "provisioners" section of that file to refer to any scripts (in order) you want to run in the Packer build sequence. This would typically be a combination of the scripts already provided by Packer, plus whatever other scripts you build for your custom purposes.

The approach I used looked like this:

"provisioners": [
{
  "execute_command": "echo 'vagrant' | {{.Vars}} sudo -S -E bash '{{.Path}}'",
  "scripts": [
    "scripts/common/sshd.sh",
    "scripts/common/vagrant.sh",
    "scripts/common/vmtools.sh",
    "scripts/CUSTOM/reso_1024x768.sh",
    "scripts/CUSTOM/prompt_cwd.sh",
    "scripts/CUSTOM/standard_dirs.sh",
    "scripts/CUSTOM/standard_utils.sh",
    "scripts/CUSTOM/python27.sh",
    "scripts/CUSTOM/supervisord.sh",
    "scripts/CUSTOM/ruby.sh",
    "scripts/centos/cleanup.sh",
    "scripts/common/minimize.sh"
  ],
  "type": "shell"
}

Note my custom scripts all appear before the cleanup and minimize steps -- this is important.

  1. From the bento / packer directory, run packer build -only=virtualbox centos-6.4-x86_64-CUSTOM.json. If disk images (ISOs) for VirtualBox guest add-ons and base OS haven't been downloaded before, they will be now; these files are big so this step can take a while.

  2. Packer uses VirtualBox to create a temporary VM, and runs all your specified scripts on it. When this process is done, a copy of the VM is captured in the bento / builds / visualbox directory using the BOXFILE name you specified above, and Packer discards the VirtualBox VM.

  3. Register the box you just built with Vagrant. Using the separately installed version of Vagrant (e.g. you may have to specify /usr/local/bin/vagrant or whatever's appropriate for your OS), do vagrant box add CUSTOM path/to/BOXFILE. This creates a new sub-directory in ~/ .vagrant.d / boxes / CUSTOM / VirtualBox with the files Vagrant needs to create VMs from this box definition.

  4. Create a Vagrant project directory and cd into it. I did mkdir ~/test; cd ~/test.

  5. Initialize a Vagrant project using this box: vagrant init CUSTOM

  6. Start the VM: vagrant up

  7. Connect to the VM: vagrant ssh

At this point, you're using Vagrant normally and Bento / Packer are no longer involved -- their combined job is just to create the basebox, and once that's been registered with Vagrant, Vagrant stands alone.


There are lots of other interesting things to look at re: Vagrant, like the special vagrant-aws plugin, and how to use it with Chef, Puppet or Ansible ... but I will stop here since my original question is answered.

于 2013-10-23T19:49:32.847 回答
1

听起来您想要应用 Bento、Vagrant 和/或 Veewee 来配置和执行盒子上的 QA 测试。感谢Chef背后的人们和社区,已经有一个工具可以完成您正在尝试做的事情!

它被称为test-kitchen。您可以将它与OpsCode/Chef 使用 Packer 维护和构建的预构建Chef Bento Boxes一起使用。如果您只想进行配置/测试,则无需使用 VeeWee 或 Packer 从头构建 Vagrant 盒或 VM 映像。

Test Kitchen 是一种测试工具,用于在一个或多个平台上单独执行配置代码(在Chef 、AnsiblePuppetSaltStackBash / Powershell中)。它使用驱动插件架构,可让您将其插入各种云提供商和虚拟化技术,例如Amazon EC2Blue BoxCloudStackDigital OceanRackspaceOpenStackVagrantDockerLXC 容器VMWare VSpherebootstrap.shbootstrap.ps1谷歌计算引擎Azure等等。还有“busser”测试插件允许对多个测试框架的可插拔支持,包括BatsshUnit2RSpecServerspecShpecToxNose2MiniTestCucumberAnsibleSpec,以及正在创建的其他测试框架。

对于 Chef、Puppet 和 Ansible 工作流程,支持说明书依赖解析器工具,例如BerkshelfLibrarian-ChefLibrarian-PuppetAnsible GalaxyLibrarian-Ansible,或者您可以简单地拥有一个cookbooks/目录,Test Kitchen 就会知道该做什么。如果您已经在使用 Chef 社区食谱,那么 Test Kitchen 集成测试已经包含在许多诸如 MySQL、nginx、Chef Server 和 runit 食谱中。

它非常灵活,对于您的用例,您可以通过选择正确的 gem 插件集使其做您想做的事情。因为它来自 Chef 社区,所以您可能会在使用 Chef 食谱、Vagrant 驱动程序以及 ServerSpec 或 Bats 测试插件时获得最佳体验。然而,它作为一个 CI 和 QA 测试工具正在获得牵引力,它拥有许多可用的社区插件。

如果您有兴趣看看那里有什么,只需搜索 RubyGemskitchen-busser-更多选项。

如果您是 Ruby、Chef 或所有这些方面的新手... 一个简单的入门方法是安装ChefDK,其中包括test-kitchen、和基本的 / Chef.io 支持的测试工具。knifeBerkshelf

一旦你有了它,如果你喜欢冒险或者想要尝试替代的可插入供应器、驱动程序和总线插件,你可以通过使用这些将其中任何一个安装ChefDK Ruby 环境中(例如 Mac OS X / Unix)命令:

$(/opt/chefdk/bin/chef shell-init $(basename $SHELL))
sudo /opt/chefdk/embedded/bin/gem install $kitchen_plugin_gem_name_here

如果您想使用我为测试 Ansible 剧本/角色而创建的演示存储库,请查看Ansible TDD

于 2015-10-22T17:15:48.643 回答