如何通过SSH在CI构建成功后部署我的Web应用程序?

huangapple go评论87阅读模式
英文:

How to deploy my webapp on CI build success via SSH?

问题

我有一个在GitLab中的CI流水线,它构建我的应用程序并将其放在一个文件夹中。

在部署的服务器上发布它并进行一些更改的正确方法是什么?

我正在考虑一种“拉取”场景:将构建好的应用程序推送到一个专用的仓库,然后在目标机器上克隆该仓库并运行必要的脚本。

我想我可以通过SSH从CI服务器“推送”应用程序,但不确定这是否是正确的方法。

如何以正确而不过于复杂的方式实现这一点?

英文:

I have a CI pipeline in GitLab that builds my app and puts it in a folder.

What's the proper way to publish it and make some changes on the server where it is deployed?

I am thinking of a "pull" scenario: push the built app to a dedicated repo which I then clone on the target machine and make the necessary scripts run.

I suppose I can "push" the app from the CI server via SSH, but not sure it's the right way.

How do I make it in a proper and not overcomplicated manner?

答案1

得分: 1

将构建好的应用程序推送到一个专用的存储库中,然后在目标机器上克隆该存储库并运行必要的脚本。

这可以通过在服务器上的一个裸仓库上设置一个post-receive钩子来完成。钩子脚本如下:

git --git-dir=/path/to/project_root/.git --work-tree=/var/www/http/ checkout -f

您可以使用其他命令来完善该脚本,以进一步修改您的部署。

英文:

> push the built app to a dedicated repo which I then clone on the target machine and make the necessary scripts run.

That would be done through a post-receive hook set on a bare repo on your server. The hook script would be:

git --git-dir=/path/to/project_root/.git --work-tree=/var/www/http/ checkout -f

You can complete that script with other commands to further modify your deployment.

答案2

得分: 0

你的 CI 应该测试你构建应用程序的方式是否良好。在构建并放入文件夹后,添加一个对该应用程序的测试(功能性测试,如果相关的话,可以部署它,或者只是验证其完整性)。然后,你可以选择合并(然后,如你所说,在目标机器上克隆存储库);实际上,这可以由另一个 CI 流水线完成。对我来说,推送应用程序不是流水线或代码的一部分,因此不应将其集成在其中。

英文:

Your CI should test if the way you build your app is good or not.
After build and put in a folder, add a test of this app (functional, by deploying it if it's relevant, or just verify integrity of it).
Then, you can choose to merge (and then, as you said, clone the repo on a target machine); this could be done by another CI pipeline, in fact.
Pushing the app, for me, is not part of the pipeline nor the code, so it should not be integrated on it.

答案3

得分: 0

Gitlab CI给了你很多自由,你可以选择如何部署你的应用程序。你可以选择使用docker、fabric、puppet、chef、ansible或者只是简单的bash和ssh。

我自己使用fabric + docker。

英文:

Gitlab CI gives you a lot of freedom how you want to deploy your app. You can choose to use docker, fabric, puppet, chef, ansible or just plain bash and ssh.

I use fabric + docker myself.

huangapple
  • 本文由 发表于 2017年1月4日 02:07:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/41449746.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定