I want to setup a deployment workflow from GitHub to my Digital Ocean server. To do this I don't want to have to login to the server and manually run git pull
from my server's repository.
I'm aware of git hooks, and have even used them between my local machine and my server, but I wanted a way to deploy from GitHub to the server so I can guarantee parity between the GitHub repo and the server's repo.
There is very little documentation on how to do this to a non-supported host company (Digital Ocean), so I figured that one way to do it remotely would be to:
- Setup a user on my server.
- Create an SSH key pair for that user
- Add the user's public key as a Deployment Key on my Github repository
- Then when I wanted to deploy using my local computer, I would simply send a single bash command (something like
cd /var/www/my-repo && git pull
) over ssh to the server
The problem is that it seems I can only get as far as point 3. In order to clone/pull the repository from GitHub, I need to start the ssh-agent in my shell. Without doing this my server's user can't pull from GitHub.
An obvious solution might be to simply send the eval `ssh-agent -s`
command over the wire along with my cd
and git pull
commands. However, with a bit of experimenting I realised that the ssh-agents weren't being killed when I killed my shell session with the server. This would mean I would be starting up dormant ssh-agent processes each time I wanted to deploy.
My question is two-fold:
- Is this an awful way to deploy (for a pretty low-key site)?
- Is there a nice, clean bash script that can start and kill an ssh-agent with every execution?
My server is a Debian server.