I build an AMI from a 'prototype' EC2 instance I created to confirm everything is working. I create a Launch Configuration and Auto Scaling Group based on the AMI. I associate the Auto Scaling Group with CodeDeploy as a Blue/Green Deployment behind an Application Load Balancer.
When I run the CodePipeline, all goes well until it gets to the CodeDeploy phase and it tries to install the application in the specified directory in appspec.yml:
The deployment failed because a specified file already exists at this location: /var/www/html/mysite/test.rb
My expectation was that CodeDeploy will only update the files in the deploy directory. Instead, it breaks and says the files already exist. From research online, I discovered that when you deploy, CodeDeploy will look for a file (on the instance) with information on previously deployed files for the application/deployment-group in question. If it finds the file it then it uses it to cleanup (delete) the existing files, preparing for copying of the new revision files.
But if the cleanup file doesn't exist, CodeDeploy won't continue running. Therefore the files will not be cleaned up, and the deployment will fail since CodeDeploy does not overwrite files. it wont be run.
Therefore the files will not be cleaned up, and the deployment will fail since CodeDeploy does not overwrite files.
It seems as though the only option in these scenarios is to have a hook (eg BeforeInstall) that calls a script to delete the applications files (if they exist) on the instance. Is this really true? The only option I have is to delete the files in a beforeInstall hook?
I notice if you copy a deployment in the Console, there is an option to 'overwrite the content'. But this option is not available in the Deployment Group configuration. It only exists when you copy the deployment.