Member-only story

SSH deployment with Github actions

Stanley Masinde
5 min readFeb 9, 2023

--

Photo by Gabriel Heinzer on Unsplash

I have monetized this article but if you’re not a Medium member, you can read it for free here. Thank you!

GitHub Actions is a powerful tool. Automation helps make the development process more fun. For instance, you can automatically test code in pull requests before merging. This removes the pain of having to check out the branch and then run the test locally to make sure the changes being introduced do not break your application.

Deployment pitfalls

This article assumes you are deploying to a single machine with a known IP address accessible via SSH.
A typical deployment in such a setup would involve logging in to the server via SSH and manually running your deployment commands. To move fast, you might have created a script that you can run to deploy the application. Here is a sample script I use in my deployment

It takes the following parameters.

  • Git SSH URL
  • The deployment directory, e.g./var/www
  • The deployment directory name, e.g. example.com
  • The deployment branch, which defaults to main

This seems efficient, but it is far from it. For that work, you need to add the server’s SSH public key to your GitHub account for it to be able to clone. If your deployments take time, you need to sit and wait for them to complete for you to know if they were a success. It is even worse when you have to deploy multiple times a day because you need to SSH to the server to deploy your application after a long day of writing code.

Adding some fun deployment with GitHub actions

For this to be fun, we need to solve two problems here;

  1. GitHub actions to securely access your server
  2. Run your builds on GitHub actions to reduce unnecessary load on your server.

--

--

Written by Stanley Masinde

I write about software engineering and system design.

Responses (2)

Write a response