php - Best way to deploy from git
We work in teams of developers on different using the git workflow as below:
- Receive ticket
- git pull/checkout
- Create feature/bugfix branch
- Do changes
- Commit to branch
- Merge to test branch, git pull to test environment
- Test on same environment as live
- If test is successful, merge to proof, git pull to proof
- Client sign off
- Merge to live
- git pull on live
However I can't decide on the best way for developers to pull their changes to live servers.
Currently, developers SSH to the live server (with individual user accounts) and perform a git pull - however they need to have read/write access to the codebase on the server.
I dislike this as then only one person (or a sysadmin) has to perform the deployment.
An alternative is to create a web accessible git pull script, so when a developer wants to do a pull, the script literally executes git pull on the server and outputs to the browser.
The best alternative, in my opinion, is for a hook to be triggered when a repo is pushed to - we use gitlab so I think this implementation would be relatively trivial, the script on the web server receives a POST object containing information about the repository, so it could be scripted to only trigger a pull if the branch that receives the hook has been updated (if that makes sense). An email could also be sent to the user that did the push with an output of the git pull message, to ensure that everything went according to plan. However I am uncomfortable that developers could accidentally push to the wrong branch and the commits become live prematurely - ideally there should be some kind of github style merge request feature.
Does anyone have any other recommendations or suggestions?