I'm managing a permanent AWS instance that hosts our main production application. Currently, we're using an Ansible playbook to handle releases with a simple git pull. I attempted to set up a CI/CD pipeline using GitLab and CodeDeploy, but I've run into an issue where it seems to overwrite the git repository on the instance, leaving me with a detached head. Should I completely detach the code on this instance from Git and move to a pure push model, or should I maintain the current setup and have the CI/CD pipeline SSH or use SSM to perform a git pull?
2 Answers
A better approach could be to clone the repo to a new directory and then do your checks. Once you're satisfied, you can update a symlink to point to the new install. This way you maintain a clean setup and can roll back old directories when the new deployment is stable. Just a heads up, having permanent EC2 instances isn't the ideal scenario — there are other strategies that could lead to a more efficient setup in the long run.
It's actually fine to have detached code, sometimes it's even preferable. It allows you to have a snapshot of your deployment which can be useful for rollback if something goes wrong. Just remember, it won't be linked to a branch, so plan your strategy around that.
But why is that a better option? It just feels like it could complicate things!

I hear you! We're planning to use ephemeral Docker containers eventually, but for now, the current instances are needed for running our Celery workers and web servers. Managing CI/CD is just the first step for us.