简体   繁体   English

AWS CodeDeploy 代理在安装过程中删除错误文件夹中的文件

[英]AWS CodeDeploy agent is deleting files in the wrong folder during install

We have an unusual setup.我们有一个不寻常的设置。 We use git on Azure Devops for our code repositories, and AWS for our cloud-based services.我们将 Azure Devops 上的 git 用于我们的代码存储库,并将 AWS 用于我们基于云的服务。 In our arsenal we have a mixture of AWS Lambda functions, along with console apps, web apps, and Windows services running on EC2 instances.在我们的武器库中,我们混合使用了 AWS Lambda 函数,以及在 EC2 实例上运行的控制台应用程序、Web 应用程序和 Windows 服务。 We have been able to create CI/CD pipelines for all three classes of apps.我们已经能够为所有三类应用程序创建 CI/CD 管道。 For the apps running on EC2 instances we use AWS CodeDeploy.对于在 EC2 实例上运行的应用程序,我们使用 AWS CodeDeploy。 These deployments are more complicated, but they all work -- except for one.这些部署更复杂,但它们都有效——除了一个。

Another unusual thing about our setup is that both our development and QA environments are on the same EC2 instance.我们设置的另一个不寻常之处是我们的开发和 QA 环境都在同一个 EC2 实例上。 When the CodeDeploy agent running on that instance retrieves the deployment archive, it unpacks it, reads the appspec.yml file, runs our before install script, which backs up the existing installation and shuts down any services that might be using those files.当在该实例上运行的 CodeDeploy 代理检索部署档案时,它会解压缩它,读取 appspec.yml 文件,运行我们的安装前脚本,该脚本备份现有安装并关闭可能使用这些文件的任何服务。 Then, the install phase updates the files in the designated environment, then deletes -- or tries to delete -- all the files in the other environment folder.然后,安装阶段更新指定环境中的文件,然后删除——或尝试删除——其他环境文件夹中的所有文件。

In other words, if a DEV deployment is running, it replaces the files in the DEV folder and also tries to delete the files in the QA folder.换句话说,如果 DEV 部署正在运行,它会替换 DEV 文件夹中的文件,并尝试删除 QA 文件夹中的文件。 I know this sounds like a scripting problem, but I have checked all the script and yaml files no where do I reference the opposing environment.我知道这听起来像是一个脚本问题,但我已经检查了所有脚本和 yaml 文件,我没有在哪里引用相反的环境。

In this case, the app is a Windows service.在这种情况下,应用程序是 Windows 服务。 Normally, I get a Ruby 'Permission denied @ unlink_internal' error on a file in the other folder.通常,我在另一个文件夹中的文件上收到 Ruby“权限被拒绝@unlink_internal”错误。 As an experiment, I shut down the service in the other environment in my before install script and, as I expected, the agent deleted all the files in the other environment.作为实验,我在安装前的脚本中关闭了其他环境中的服务,正如我所料,代理删除了其他环境中的所有文件。 It updated the files in the target environment, but left the folder in the other environment empty!它更新了目标环境中的文件,但将另一个环境中的文件夹留空!

Here are my files.这是我的文件。 I suspect, the problem is being caused by something I did, but I can't, for the life of me, find it.我怀疑,问题是由我所做的事情引起的,但我终究无法找到它。

These are all .NET projects.这些都是.NET 项目。 In my solution I have a ConfigFiles folder set up with subfolders for each environment.在我的解决方案中,我有一个 ConfigFiles 文件夹,其中为每个环境设置了子文件夹。 Then, in my pipeline yaml file I run a script to select the correct files to move into the archive based on the git branch that is being built.然后,在我的管道 yaml 文件中,我运行一个脚本来根据正在构建的 git 分支选择正确的文件以移动到存档中。

在此处输入图像描述

Here's the code for code for the script that selects the correct files.这是选择正确文件的脚本的代码。

在此处输入图像描述

Here's the Azure pipeline YAML file.这是 Azure 管道 YAML 文件。

在此处输入图像描述

Here's my before install script:这是我之前的安装脚本:

在此处输入图像描述

And, finally, here is my appspec.yml file, which the CodeDeploy agent uses to know where to update the files during installation.最后,这是我的 appspec.yml 文件,CodeDeploy 代理使用它来了解在安装过程中在哪里更新文件。 How I want this to be the wrong path, but in the deployment archive, the environment specific values are all exactly right.我多么希望这是错误的路径,但在部署档案中,环境特定值都是完全正确的。

在此处输入图像描述

Any ideas on this one would be greatly appreciated.对此有任何想法将不胜感激。

I encountered the same problem where deployment of an app deletes files from another app in another folder unexpectedly.我遇到了同样的问题,即部署一个应用程序意外地从另一个文件夹中的另一个应用程序中删除文件。 My solution is to use different deployment groups for each app, even though they are deploying to the same EC2 instance.我的解决方案是为每个应用程序使用不同的部署组,即使它们部署到同一个 EC2 实例。

Deploying many apps on the same EC2 instance using the same deployment group results in files/folder deletion on other deployed projects.使用相同的部署组在同一 EC2 实例上部署多个应用程序会导致删除其他已部署项目的文件/文件夹。

From AWS Technical Support:来自 AWS 技术支持:

The reason is that codedeploy creates a clean up file by the format '[deployment group 1 ID]_cleanup" in the directory '/opt/codedeploy-agent/deployment-root/deployment-instructions' everytime a deployment is made to the deployment group and this file deletes all the files that had been installed during the previous deployment made to the deployment group. Since the deployment group is the same in your case, when you make a deployment to the deployment group which installs files to the folder "/var/www/project1", files installed by the previous deployment in the folder "/var/www/project2" are being cleaned up and vice versa which is an expected mechanism of the codedeploy agent.原因是每次对部署组进行部署时,codedeploy 在目录 '/opt/codedeploy-agent/deployment-root/deployment-instructions' 中创建一个格式为 '[deployment group 1 ID]_cleanup' 的清理文件并且此文件删除了之前部署到部署组期间安装的所有文件。由于部署组在您的情况下是相同的,因此当您对部署组进行部署时,部署组会将文件安装到文件夹“/var /www/project1”,之前部署在文件夹“/var/www/project2”中安装的文件正在清理,反之亦然,这是 codedeploy 代理的预期机制。

You can find the explaination here: https://docs.aws.amazon.com/codedeploy/latest/userguide/codedeploy-agent.html#codedeploy-agent-install-files您可以在此处找到说明: https ://docs.aws.amazon.com/codedeploy/latest/userguide/codedeploy-agent.html#codedeploy-agent-install-files

Please consider creating two different applications/deployment groups and configure the two pipelines to use different applications/deployment groups which should fix your problem.请考虑创建两个不同的应用程序/部署组并将两个管道配置为使用不同的应用程序/部署组,这应该可以解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM