Chef教程
Chef高级

Chef Foodcritic

写出没有任何问题的好Cookbook是一项艰巨的任务。但是有一些方法可以帮助识别陷阱。可以在 Chef Cookbook 中进行标记。 Foodcritic 是最好的存档方式之一,它试图找出Cookbook的逻辑和风格可能存在的问题。

Foodcritic设置

步骤 1-添加 Foodcritic gem。
vipin@laptop:~/chef-repo $ subl Gemfile 
source 'https://rubygems.org' 
gem 'foodcritic', '~>2.2.0'
步骤 2-安装 gem。
vipin@laptop:~/chef-repo $ bundle install 
Fetching gem metadata from https://rubygems.org/ 
...TRUNCATED OUTPUT... 
Installing foodcritic (2.2.0) 

美食评论宝石

步骤 1-在Cookbook上运行 Foodcritic。
vipin@laptop:~/chef-repo $ foodcritic ./cookbooks/<Cookbook Name> 
FC002: Avoid string interpolation where not required: ./cookbooks/ 
mysql/attributes/server.rb:220 
...TRUNCATED OUTPUT... 
FC024: Consider adding platform equivalents: ./cookbooks/<Cookbook Name>/ 
recipes/server.rb:132 
步骤 2-生成详细报告。
vipin@laptop:~/chef-repo $ foodcritic-C ./cookbooks/mysql 
cookbooks/<cookbook Name>/attributes/server.rb 
FC002: Avoid string interpolation where not required 
[...] 
85| default['<Cookbook Name>']['conf_dir'] = "#{mysql['basedir']}" 
[...] 
cookbooks/<Cookbook Name>/recipes/client.rb 
FC007: Ensure recipe dependencies are reflected in cookbook 
metadata 
40| end 
41|when "mac_os_x" 
42| include_recipe 'homebrew' 
43|end 
44|

工作方法

Foodcritic 定义了一组规则并检查配方代理,每个代理。它带有涉及各个领域的多个规则:样式、连通性、属性、字符串、概率、搜索、服务、文件、元数据等。
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4