无法使用chef中的deploy资源部署git repo

时间:2016-06-15 12:28:24

标签: chef chef-recipe

我很难让使用厨师进行简单的git repo部署。

这是我的食谱:

deploy "tomatina" do
  repo "git://github.com/visionmedia/express.git"
  deploy_to '/tmp/selvam'
  action :deploy
end

当我在节点上运行chef-client时,它出错,文件未找到异常。我不确定错误是什么。我是厨师兼新手ruby并且不知道从哪里开始研究以跟踪错误。这是我的日志:

Starting Chef Client, version 12.9.41
resolving cookbooks for run list: ["myapp"]
Synchronizing Cookbooks:
  - application_nodejs (2.0.1)
  - build-essential (6.0.0)
  - nodejs (1.3.0)
  - apt (3.0.0)
  - myapp (0.1.0)
  - compat_resource (12.10.6)
  - application (4.1.4)
Installing Cookbook Gems:
Compiling Cookbooks...
[2016-06-15T12:22:37+00:00] WARN: Chef::Provider::AptRepository already exists!  Cannot create deprecation class for LWRP provider apt_repository from cookbook apt
[2016-06-15T12:22:37+00:00] WARN: AptRepository already exists!  Deprecation class overwrites Custom resource apt_repository from cookbook apt
Converging 1 resources
Recipe: myapp::default
  * deploy[tomatina] action deploy
    - create new directory /tmp/selvam/shared
    - clone from git://github.com/visionmedia/express.git into /tmp/selvam/shared/cached-copy
    - checkout ref 31dd549f350accd7b4e3685c13f745e857557827 branch HEAD
  - force ownership of /tmp/selvam to :
  - deploy from repo to /tmp/selvam/releases 
  - force ownership of /tmp/selvam to :
  - evaluate block and run any associated actions
  ================================================================================
  Error executing action `deploy` on resource 'deploy[tomatina]'
  ================================================================================

  Chef::Exceptions::FileNotFound
  ------------------------------
  Cannot symlink /tmp/selvam/shared/config/database.yml to /tmp/selvam/releases/20160615122237/config/database.yml before migrate: No such file or directory @ sys_fail2 - (/tmp/selvam/shared/config/database.yml, /tmp/selvam/releases/20160615122237/config/database.yml)

  Cookbook Trace:
  ---------------
  /var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:41:in `run_action'

  Resource Declaration:
  ---------------------
  # In /var/chef/cache/cookbooks/myapp/recipes/default.rb

    9: deploy "tomatina" do
   10:   repo 'git://github.com/visionmedia/express.git'
   11:   deploy_to '/tmp/selvam'
   12:   action :deploy
   13: end

  Compiled Resource:
  ------------------
  # Declared in /var/chef/cache/cookbooks/myapp/recipes/default.rb:9:in `from_file'

  deploy("tomatina") do
    action [:deploy]
    updated true
    updated_by_last_action true
    retries 0
    retry_delay 2
    default_guard_interpreter :default
    deploy_to "/tmp/selvam"
    repository_cache "cached-copy"
    purge_before_symlink ["log", "tmp/pids", "public/system"]
    create_dirs_before_symlink ["tmp", "public", "config"]
    symlink_before_migrate {"config/database.yml"=>"config/database.yml"}
    symlinks {"system"=>"public/system", "pids"=>"tmp/pids", "log"=>"log"}
    revision "HEAD"
    remote "origin"
    scm_provider Chef::Provider::Git
    keep_releases 5
    enable_checkout true
    checkout_branch "deploy"
    declared_type :deploy
    cookbook_name "myapp"
    recipe_name "default"
    repo "git://github.com/visionmedia/express.git"
    shared_path "/tmp/selvam/shared"
    destination "/tmp/selvam/shared/cached-copy"
    current_path "/tmp/selvam/current"
  end

  Platform:
  ---------
  x86_64-linux


Running handlers:
[2016-06-15T12:23:04+00:00] ERROR: Running exception handlers
Running handlers complete
[2016-06-15T12:23:04+00:00] ERROR: Exception handlers complete
Chef Client failed. 1 resources updated in 28 seconds
[2016-06-15T12:23:04+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2016-06-15T12:23:04+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
[2016-06-15T12:23:04+00:00] ERROR: deploy[tomatina] (myapp::default line 9) had an error: Chef::Exceptions::FileNotFound: Cannot symlink /tmp/selvam/shared/config/database.yml to /tmp/selvam/releases/20160615122237/config/database.yml before migrate: No such file or directory @ sys_fail2 - (/tmp/selvam/shared/config/database.yml, /tmp/selvam/releases/20160615122237/config/database.yml)
[2016-06-15T12:23:04+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

我的工作站,chefserver&节点正在运行ubuntu 16.04。

厨师详情:

Chef Development Kit版本:0.13.21

chef-client版本:12.9.41

berks版本:4.3.2

厨房版:1.7.3

厨师:12.9.41

2 个答案:

答案 0 :(得分:1)

错误很明显(重点是我的):

  

无法符号链接/tmp/selvam/shared/config/database.yml    /tmp/selvam/releases/20160615122237/config/database.yml 之前   migrate:没有这样的文件或目录@sys_fail2 -   (/tmp/selvam/shared/config/database.yml,   /tmp/selvam/releases/20160615122237/config/database.yml)

您的仓库中没有database.yml,因此部署资源无法为其创建链接。

部署资源中有一堆callbacks,它在很多方面做了很多工作。

这里有什么问题,symlink_before_migrate默认为{"config/database.yml" => "config/database.yml"}

如部署资源属性documentation中所述:

  

设置为symlink_before_migrate({})以防止创建符号   链接。

所以你的资源应该是这样的:

deploy "tomatina" do
  repo "git://github.com/visionmedia/express.git"
  deploy_to '/tmp/selvam'
  symlink_before_migrate({})
  action :deploy
end

但我强烈建议您阅读部署资源的整个文档,以了解其工作原理。

答案 1 :(得分:1)

部署资源是一个非常小众的工具,可能不应该再使用了。您可能需要一个简单的git资源。