简体   繁体   中英

How can I use git to deploy to test server?

I have used redhat's open shift few years ago. The way you update the server is by pushing to the git repo. Once you pushed your changes, you can test your app in the browser.

I want to implement that in one of my VM for testing. So that whenever I pushed to the repo, the testers can see my changes right away. I'm doing it in a cloud VM because the person who will test it is in another country. I'm using nginx, pm2, nodejs and express.

I understand that I can just ssh to the server, pull the changes, restart pm2. But if there's a more automated way, that will be better.

What you're describing is called Continuos Integration/Continuous Deployment, often referred to as CI/CD. There are tools specifically made for this. The two major players are TeamCity by jetbrains (free to use for the size of project your describing) and Jenkins (open source). I would suggest you search for tutorials on CI/CD that use one of those two products.

You probably want to look into the server side git hooks. You can execute a bash script on the server when a git push is received, and execute whatever needs to happen to update the server.

To give a quick rundown:

Hooks can be found under .git/hooks . Here you will find the following files:

  • pre-push.sample
  • commit-msg.sample
  • pre-rebase.sample
  • post-update.sample
  • prepare-commit-msg.sample
  • pre-applypatch.sample
  • update.sample
  • pre-commit.sample

To give an example, on your server if you add the following to your post-update hook, the server will send you an email whenever a commit is received:

#!/bin/bash
git show --name-status | mail -s "Received Push" youremail@email.com

In this file, is where you will likely want to write your script to rebuild the website with the newly received data!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM