【问题标题】:Deployment using CodeDeploy failing at "install" step due to error "File already exists"由于错误“文件已存在”,使用 CodeDeploy 的部署在“安装”步骤失败
【发布时间】:2016-12-14 10:31:34
【问题描述】:

这是我在“安装”步骤中遇到的错误 -

File already exists at location /var/cake_1.2.0.6311-beta/app/webroot/../../somefile.php

我无法得出结论是什么事件导致了这种情况。但我记得的是这个——

  • 我通过 jenkins(集成了代码部署插件)发起了部署。部署在“安装”步骤失败,我在上面粘贴了错误。

    注意 - 这是 appspec.yml 文件文件部分的第一个文件。

  • 据我所知,我在同一个部署组上进行了一些部署,直接通过代码部署(很可能使用 Jenkins 在上述步骤中创建的相同 S3 文件)并且成功了。

    • 然后我有几次部署失败(故意在各个步骤失败,例如 beforeInstall 通过以非零数字退出)。

此后,即使直接通过代码部署,我也无法成功部署。

背景

我检查了看起来相关的this question,并尝试删除/opt/codedeploy-agent/deployment-root/​ 中的所有内容,如one of the answers 中所述,但是,它导致在我的实例中部署的代码损坏,并且通过 Jenkins 部署开始抛出此错误,说 appspec存档中的文件(它试图寻找最后一次成功的部署,似乎已被删除) -

Jenkins triggered code deploy is failing at ApplicationStop step even though same deployment group via code deploy directly is running successfully

然后我在实例上重新安装代码部署,上面提到的步骤就是我之后所做的。

更新 - 开放赏金

正如 Rodrigo M 所回答的那样,到目前为止,从实例的部署路径中删除此类文件对我来说是有效的,但对于这个特定文件来说,同样的方法不起作用 -

 File already exists at location /var/cake_1.2.0.6311-beta/deployment/serverLoad.json

我验证了以下内容 -

  • 在所有实例上从上述位置删除文件后,我进行了新部署。我观察到该文件再次出现,但仍然抛出与上述相同的错误并且部署失败。

  • 没有删除,我将文件修改为 777。结果相同。

有趣的是,昨天我收到了多个文件的此错误,然后在找到它们并进行新构建时,我继续将它们一个一个删除。除了这个文件之外的所有其他文件的问题都得到了解决,即使删除也不起作用。我不知道!

注意 - 我现在所做的所有部署都是由 Jenkins 触发的(没有从 AWS 代码部署触发的直接部署)。

这是来自/var/log/aws/codedeploy-agent/codedeploy-agent.log 的日志跟踪,其中包含相关的错误堆栈 strace -

2016-11-10 07:38:12 INFO  [codedeploy-agent(16889)]: Version file found in /opt/codedeploy-agent/.version.
2016-11-10 07:38:12 INFO  [codedeploy-agent(16889)]: [Aws::CodeDeployCommand::Client 200 0.025545 0 retries] put_host_command_complete(command_status:"Failed",diagnostics:{format:"JSON",payload:"{\"error_code\":5,\"script_name\":\"\",\"message\":\"File already exists at location /var/cake_1.2.0.6311-beta/deployment/serverLoad.json\",\"log\":\"\"}"},host_command_identifier:"WyJjb20uYW1hem9uLmFwb2xsby5kZXBsb3ljb250cm9sLmRvbWFpbi5Ib3N0Q29tbWFuZElkZW50aWZpZXIiLHsiZGVwbG95bWVudElkIjoiQ29kZURlcGxveS91cy1lYXN0LTEvUHJvZC9hcm46YXdzOnNkczp1cy1lYXN0LTE6Mzc3NzAzOTYxOTk4OmRlcGxveW1lbnQvZC1VOVFPR0RBWUkiLCJob3N0SWQiOiJhcm46YXdzOmVjMjp1cy1lYXN0LTE6Mzc3NzAzOTYxOTk4Omluc3RhbmNlL2ktZWNmYzU1YTkiLCJjb21tYW5kTmFtZSI6Ikluc3RhbGwiLCJjb21tYW5kUG9zaXRpb24iOjQsImNvbW1hbmRBdHRlbXB0IjoxfV0=")

2016-11-10 07:38:12 ERROR [codedeploy-agent(16889)]: InstanceAgent::Plugins::CodeDeployPlugin::CommandPoller: Error during perform: RuntimeError - File already exists at location /var/cake_1.2.0.6311-beta/deployment/serverLoad.json - /opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/installer.rb:115:in `generate_normal_copy'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/installer.rb:67:in `block (2 levels) in generate_instructions'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/installer.rb:55:in `each'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/installer.rb:55:in `block in generate_instructions'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/install_instruction.rb:68:in `generate_instructions'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/installer.rb:54:in `generate_instructions'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/installer.rb:34:in `install'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/command_executor.rb:114:in `block in <class:CommandExecutor>'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/command_executor.rb:62:in `execute_command'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/command_poller.rb:132:in `process_command'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/command_poller.rb:65:in `perform'
/opt/codedeploy-agent/lib/instance_agent/agent/base.rb:28:in `run'
/opt/codedeploy-agent/lib/instance_agent/runner/child.rb:38:in `block in run'
/opt/codedeploy-agent/lib/instance_agent/runner/child.rb:55:in `with_error_handling'
/opt/codedeploy-agent/lib/instance_agent/runner/child.rb:37:in `run'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/child.rb:70:in `block in run_with_error_handling'
/opt/codedeploy-agent/lib/instance_agent/runner/child.rb:55:in `with_error_handling'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/child.rb:69:in `run_with_error_handling'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/child.rb:33:in `block in start'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/child.rb:22:in `loop'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/child.rb:22:in `start'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/master.rb:206:in `block in spawn_child'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/master.rb:204:in `fork'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/master.rb:204:in `spawn_child'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/master.rb:196:in `block in spawn_children'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/master.rb:195:in `times'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/master.rb:195:in `spawn_children'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/master.rb:134:in `start'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/master.rb:37:in `block in start'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/master.rb:36:in `fork'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/master.rb:36:in `start'
/opt/codedeploy-agent/bin/../lib/codedeploy-agent.rb:41:in `block (2 levels) in <main>'
/opt/codedeploy-agent/vendor/gems/gli-2.5.6/lib/gli/command_support.rb:130:in `call'
/opt/codedeploy-agent/vendor/gems/gli-2.5.6/lib/gli/command_support.rb:130:in `execute'
/opt/codedeploy-agent/vendor/gems/gli-2.5.6/lib/gli/app_support.rb:262:in `block in call_command'
/opt/codedeploy-agent/vendor/gems/gli-2.5.6/lib/gli/app_support.rb:275:in `call'
/opt/codedeploy-agent/vendor/gems/gli-2.5.6/lib/gli/app_support.rb:275:in `call_command'
/opt/codedeploy-agent/vendor/gems/gli-2.5.6/lib/gli/app_support.rb:69:in `run'
/opt/codedeploy-agent/bin/../lib/codedeploy-agent.rb:88:in `<main>'

更新 2

我能够通过重命名 json 文件并删除 appspec.yml 中的旧文件引用来应用脏修复。但是,在新的部署组(具有新的 ec2 实例)上,新的 json 文件会导致相同的文件退出问题。每次更改文件名都很痛苦。对正在发生的事情感到非常恼火。

【问题讨论】:

    标签: amazon-web-services jenkins deployment aws-code-deploy


    【解决方案1】:

    这是可以修复的。 Codedeploy 在它自己没有部署的文件上抛出一个错误。但是有一个选项可以在部署过程中解决这个问题。

    “内容选项: 当目标实例上的文件与应用程序修订中的文件同名且目标位置相同时,选择 AWS CodeDeploy 在部署期间采取的操作。”

    您可以选择失败、覆盖和保留。这取决于你的情况。

    您可以找到更多信息

    【讨论】:

      【解决方案2】:

      作为其流程的一部分,CodeDeploy 将查找有关应用程序/部署组之前部署的文件的信息。如果然后它使用此信息删除现有文件,则根据需要准备部署新修订版。

      http://docs.aws.amazon.com/codedeploy/latest/userguide/deployment-steps.html#deployment-rollback

      在这种情况下,由于您之前可能进行了手动清理,因此存在一些不一致的引用。

      所有部署的一个不错的选择是在BeforeInstall 挂钩期间简单地删除部署文件夹中的所有文件。这将在现在和以后解决此问题。

      【讨论】:

      • 我们计划只覆盖在部署期间更改的文件,而不是整个代码库,因为这可能是很多文件,并且会占用不必要的时间和 S3 带宽。您是否建议删除所有文件一次或采用此作为推出策略?此外,如果您怀疑由于手动清理仍然存在一些不一致,那么您能否建议一个链接/参考来进行正确和完整的清理?重新安装后是否应该从新的应用程序和部署组开始?我现在用的是一样的。
      • 要解决这个问题,现在只需手动删除部署路径中的文件。一旦以这种方式修复,下一个部署应该可以工作。
      • 从那时起删除文件对我有用,但是今天它不适用于这个特定文件。我不知道它有什么不同。
      • 在这个问题上打开了赏金。详情请查看问题正文。
      猜你喜欢
      • 2021-02-16
      • 2017-05-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多