简体   繁体   English

如何使用git部署以测试服务器?

[英]How can I use git to deploy to test server?

I have used redhat's open shift few years ago. 几年前,我曾使用过redhat的开放式班次。 The way you update the server is by pushing to the git repo. 更新服务器的方法是通过推送到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. 我正在云VM中进行测试,因为要进行测试的人员在另一个国家。 I'm using nginx, pm2, nodejs and express. 我正在使用nginx,pm2,nodejs和express。

I understand that I can just ssh to the server, pull the changes, restart pm2. 我了解我可以SSH到服务器,进行更改,重新启动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. 您所描述的称为连续集成/连续部署,通常称为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). 两个主要参与者是jetbrains的TeamCity(根据您描述的项目大小免费使用)和Jenkins(开源)。 I would suggest you search for tutorials on CI/CD that use one of those two products. 我建议您搜索使用这两种产品之一的CI / CD教程。

You probably want to look into the server side git hooks. 您可能想研究服务器端的git挂钩。 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. 您可以在收到git push时在服务器上执行bash脚本,并执行更新服务器所需的一切。

To give a quick rundown: 简要介绍一下:

Hooks can be found under .git/hooks . 钩子可以在.git/hooks下找到。 Here you will find the following files: 在这里您将找到以下文件:

  • pre-push.sample 推样前
  • commit-msg.sample commit-msg.sample
  • pre-rebase.sample re-rebase.sample
  • post-update.sample 更新后样本
  • prepare-commit-msg.sample prepare-commit-msg.sample
  • pre-applypatch.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! 在此文件中,您可能想编写脚本以使用新接收的数据重建网站!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将 Node HTTP/2 服务器部署到 Google App Engine? - How can I deploy a Node HTTP/2 server to Google App Engine? 当应用程序在子文件夹中时,如何通过git将node.js应用程序部署到azure? - How can I deploy a node.js app to azure via git when the app is in a subfolder? 如何在git push(GitHub和node.js)后自动部署我的应用程序? - How can I automatically deploy my app after a git push ( GitHub and node.js)? 如何彻底退出CI的npm服务器测试? - How can I cleanly exit an npm server test for CI? 如何在 next.js 中使用 supertest 测试 express 服务器? - How can I test express server with supertest in next.js? 如何将我制作的应用程序部署到服务器? - How to deploy my application that i made to server ? 如何在量角器测试中使用lodash _.find? - How can I use lodash _.find in my Protractor test? 如何在Mocha测试用例中使用setTimeout()函数? - How can I use setTimeout() functions within Mocha test cases? 如何将我的流星应用程序部署到本地网络中的 Ubuntu 服务器? - How can I deploy my meteor app to an Ubuntu server in my local network? NextJS 部署 - 如何在 Ubuntu 服务器上简单地部署 NextJS,如 NodeJS? - NextJS Deployment - How can I simply deploy NextJS like NodeJS on Ubuntu server?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM