2

Recently transitioned hosting my website to Dreamhost from Netlify in order to host a dynamic site. One thing I miss is the ability to automatically deploy from Github to the hosting service when changes are detected in my repo.

I've found tutorials for pushing to Github from my Dreamhost server, but not the other way around. I have multiple people working on this website, and my hope is to do this centrall via Github instead of manually pushing to both Github and the Dreamhost server thru the command line.

My assumption is that to ssh to Dreamhost I need a public key from my client to store on the Dreamhost server. I don't know if this is possible to generate a public key from Github (related to the workflow), but if it is how I would I do it? The other option is to store the ssh credentials with Github repo secrets to connect, but I feel this isn't best practice.

How would I go about pushing my Github repo to my Dreamhost server automatically after changes to main?

Sunderam Dubey
  • 1
  • 11
  • 20
  • 40
cameronpoe
  • 47
  • 4

1 Answers1

2

Two different gists suggest the same approach.

  • Create a bare repo on the DreamHost server
  • push to it
  • have a post-receive hook doing the git restore in the target folder (on the same server) where the actual site is deployed

See "How to Git Push to a Server Machine without having to ssh on to that machine every time?"

What remains for your GitHub Action is, as describe in Deploying to a server via SSH and Rsync in a Github Action, to use a dedicated SSH key, whose private key is registered in GitHub secrets.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks so much! This worked, but one thing is I didn't even have to create the bare repo, I simply was able to go from the "Deploying to a server via SSH and Rsync" step. When I run `git status` in the directory on the server I Rsync-ed with, it confirms the directory is indeed a git repo. Just wondering your thoughts on this? If it works it works? – cameronpoe Jun 21 '22 at 19:47
  • 1
    @dirtysoup It should work indeed. This is not exactly the same, but your files end up deployed all the same. – VonC Jun 21 '22 at 20:04
  • 1
    Note to self: That was my **28000th answer** on Stack Overflow (in 166 months), a bit less than 6 months after the [27000th answer](https://stackoverflow.com/a/70504269/6309). Before that: [26000th answer](https://stackoverflow.com/a/68190336/6309), [25000th answer](https://stackoverflow.com/a/65370954/6309), [24000th answer](https://stackoverflow.com/a/62688871/6309), [23000th answer](https://stackoverflow.com/a/59853332/63099), [22000th answer](https://stackoverflow.com/a/57387243/6309), [21000th answer](https://stackoverflow.com/a/54856158/6309), ... – VonC Jun 23 '22 at 07:34