AWS CodeDeploy Github File Already Exist

这一生的挚爱 提交于 2019-11-30 17:11:15

问题


I am trying to use AWS CodeDeploy to pull my latest changes from Github down to a server. The problem I am running into is on the install step I am getting this error:

Error CodeUnknownError
Script Name
MessageFile already exists at location /data/sites/wordpress/api_now_playing_staging.php
Log Tail

And my appspec.yml looks like this:

version: 0.0
os: "linux"
files: 
  - source: "/"
    destination: "/data/sites/wordpress"
permissions:
  - object: /data/sites/wordpress
    pattern: "**"
    owner: wp
    group: nginx
    mode: 755
    type:
      - file

My question is if it git is suppose to be pulling using CodeDeploy, why am I getting file already exist error? Am I doing something wrong?


回答1:


Did you deploy the same git repo with a different deployment group or did it manually before? If the same resource is already existed in the destination folder, CodeDeploy will check whether the resource in destination folder is created by the same deployment group. If you you are using the same deployment group, re-deploy shouldn't cause this problem.

The current way CodeDeploy host agent works is to pull down the deployment artifacts and move them to the right repository according to AppSpec file. Even you deploy from a Github repo, it's not just running git pull in the destination folder.




回答2:


All the other answers are right but in my opinion, fail to solve your problem. They are however a good starting point. (short: codedeploy sees a file which wasn't presumable there in the previous codedeploy)

This is solvable during a deployment: "Content options: Choose the action for AWS CodeDeploy to take during a deployment when a file on a target instance has the same name as a file in the application revision, for the same target location."

You can choose fail, overwrite and retain. Overwrite is probably the best choice in your case.

You can't find more information

  • docs.aws.amazon.com (strangely under 'rollback')

  • cli docs.aws.amazon.com (see --file-exists-behavior (string))




回答3:


Since the file already exists in the server, CodeDeploy has hooks (BeforeInstall) which can be used to run custom scripts to cleanup existing files, as codedeploy Install does not override files if already exists.




回答4:


I made it work like this:

I had a couple of failed deployments for various reasons. The thing is that CD keeps in the EC2 instance and in the path /opt/codedeploy-agent/deployment-root/​ a folder named by the ID of the failed deployment [a very long alphanumeric sting] . Delete this folder and create a new deployment [from the aws UI console] and redeploy the application. It should now succeed.

Notice: CD does not rewrite files [that have not been created by it's specific deployment]

CodeDeploy does not deploy in a folder that there is already code[files] as it does not want to interfere with different CD deployments and/or other CI/CD tools [like Jenkins]. It only deploys in a path that has already deploy code with the specific deployment.

You can empty the folder where your deployment want to happen and redeploy your code via CD.



来源:https://stackoverflow.com/questions/34951797/aws-codedeploy-github-file-already-exist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!