Using Git Deploy Keys for automating remote deployments

You can use Git Deploy Keys to avoid needing to remote onto servers, pull, enter creds and restart the server.

  1. Create your deploy keys in git (see https://help.github.com/articles/managing-deploy-keys)
  2. Add the key to your server
  3. Git clone/set remote for project via ssh
    • git clone git@github-project1:orgname/some_repository.git
  4. Write scripts to start/stop/pull your app
  5. Call the script remotely via ssh
    • ssh user@99.99.99.99 ‘source ~/.bash_profile;
      ~/user/myscript.sh’

Traps:

  • use user “git” in /.ssh/config for the host reference, otherwise github will reject requests
  • include ‘source ~/.bash_profile’ (or .bashrc, /etc/profile) in your script call to include environmental variables (ssh uses a very limited set by default)
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s