apache 如何使用提交后挂钩将提交的文件从 SVN 复制到 Web 目录?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/140614/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 16:46:26  来源:igfitidea点击:

How can I use post-commit hooks to copy committed files to a web directory from SVN?

svnapacheapache2

提问by rmh

My Ubuntu server has Apache and Subversion installed. I use this server as a staging server, purely for testing purposes. I use Apache to host the web application, and Subversion to keep versioned copies of the source code.

我的 Ubuntu 服务器安装了 Apache 和 Subversion。我将此服务器用作临时服务器,纯粹用于测试目的。我使用 Apache 来托管 Web 应用程序,并使用 Subversion 来保存源代码的版本副本。

My current workflow:

我目前的工作流程:

  • Make changes to a file
  • Commit the file to the Subversion repository
  • Upload the file new over SFTP to the Apache public directory
  • View the changes in my web browser
  • 对文件进行更改
  • 将文件提交到 Subversion 存储库
  • 通过 SFTP 将新文件上传到 Apache 公共目录
  • 在我的网络浏览器中查看更改

I would be much happier if my workflow was like this:

如果我的工作流程是这样的,我会更开心:

  • Make changes to a file
  • Commit the file to the Subversion repository
  • In the background, Subversion puts a copy of the committed file into the Apache public directory
  • View the changes in my web browser
  • 对文件进行更改
  • 将文件提交到 Subversion 存储库
  • 在后台,Subversion 将提交文件的副本放入 Apache 公共目录
  • 在我的网络浏览器中查看更改

I have very little server admin experience, and any help or pointers are appreciated. I heard that post-commit hooks are what I need, and that I can write bash scripts to do this, but I'm not sure where to start and didn't really find anything after quite a lot of Googling.

我的服务器管理经验很少,感谢任何帮助或指示。我听说 post-commit 钩子是我需要的,我可以编写 bash 脚本来做到这一点,但我不知道从哪里开始,经过大量谷歌搜索后并没有真正找到任何东西。

Thank you!

谢谢!

回答by zigdon

It can be done, but automatically pushing every commit to the production website isn't always a good idea. Sometimes there are other changes that need to go along, and breaking the site because the new code is there, but the database schema hasn't been updated yet is just embarrassing.

可以做到,但自动将每次提交推送到生产网站并不总是一个好主意。有时还需要进行其他更改,并且由于新代码在那里而破坏站点,但数据库架构尚未更新只是令人尴尬。

What I tend to do instead is make the server checkout a copy of svn, then, once I'm ready with everything else that has to happen, I do an svn update on it.

我倾向于做的是让服务器检出 svn 的副本,然后,一旦我准备好所有必须发生的事情,我就会对其进行 svn update。

But if you really wanted, you can put commands in the post-commit trigger, that will do everything automatically for you. This could include running a migration script on the server (if one exists for this change), to take care of any non-code changes that need to happen.

但是如果你真的想要,你可以把命令放在 post-commit 触发器中,它会自动为你做所有的事情。这可能包括在服务器上运行迁移脚本(如果存在用于此更改的迁移脚本),以处理需要发生的任何非代码更改。

回答by Jonas K?lker

I think the real, overarching question you should be asking yourself---which you may already have asked yourself of course---is this: "how can I test my code most easily before deploying it?"

我认为你应该问自己的真正的、首要的问题——你当然可能已经问过自己——是这样的:“我如何在部署之前最容易地测试我的代码?”

I think a good answer is to install Apache on your development box and run it as your own user, with webroot and/or cgi path at /home/richardhenry/src/mywebsite(or whereever you check out your code).

我认为一个好的答案是在您的开发盒上安装 Apache 并以您自己的用户身份运行它,使用 webroot 和/或 cgi 路径/home/richardhenry/src/mywebsite(或您查看代码的任何地方)。

That way, you can test your code without even committing. As a result, you won't litter your trunk with broken or useless commits. In general, keeping independent things independent tends to be A Good Idea (TM).

这样,您甚至无需提交即可测试您的代码。因此,您不会因为损坏或无用的提交而乱扔垃圾箱。一般来说,保持独立的事物独立往往是一个好主意 (TM)。

Alternatively, sync the web server against your working directory with rsync, or write a script which pushes your file(s) from the dev box to your staging server and add a Makefile rule which runs your script (or calls up rsync). If you want to be reallyfancy, use inotify or some other file notification monitor to run your script automatically.

或者,使用 rsync 将 Web 服务器与您的工作目录同步,或者编写一个脚本,将您的文件从开发箱推送到您的临时服务器,并添加一个运行您的脚本(或调用 rsync)的 Makefile 规则。如果你真的很喜欢,可以使用 inotify 或其他一些文件通知监视器来自动运行你的脚本。