使用从 Git 到 运行 个网站的来源

Use source from Git to run a website

有什么方法可以使用来自 Git 的源代码访问 运行 网站吗?

例如, 我在 Bitbucket 中有私有存储库,我想在我的网站中自动使用这个源(这样源会自动下载到我的服务器上),当我在存储库中进行更改(例如,更新任何文件)时,源会自动在我的网站上更新。

在这种情况下,我想使用Laravel。

谢谢。

听起来您正在寻找的是网络挂钩。 Webhook 允许在完成特定任务时自动执行 git 命令,例如 'git push' 到您的存储库。

在您的实例中,可以设置 webhook 以在您的服务器上执行脚本以 运行 'git pull' 命令。这是 Bitbucket 提供的有关该主题的文档 - https://confluence.atlassian.com/display/BITBUCKET/Manage+Webhooks

如果您在目标计算机上安装了 git,则可以使用 post-接收挂钩实现此目的。

  1. 存储库初始化(说明用于 Linux)

    • 创建一个名为 git 的用户。
    • mkdir /var/repo/your_name.git
    • cd 到那个目录。
    • 运行 git init --bare

      1. 创建 post-receive 以将文件推送到 /var/www/your_site
    • cd 挂钩
    • 创建post-接收:
    • #!/bin/sh git --work-tree=/var/www/your_site --git-dir=/var/repo/your_name.git checkout -f sudo /usr/local/bin/post-receive-your_site
      1. 将 /var/www 中的文件所有权更改为 web.web(html 目录的 owner/group)。由于它作为 git 运行,您需要在脚本上允许特殊的 sudo,这意味着将它放在一个安全目录中,即 /usr/local/bin.
    • 创建post-receive-your_name: #!/bin/sh find /var/www/your_site/ -type f -group 'git' -exec chown web:web {} \; find /var/www/your_site/ -type d -group 'git' -exec chown web:web {} \;
    • 作为根用户:
      cd /usr/local/bin
      ln -s /var/repo/your_name.git/hooks/post-receive-your_site
      vi /etc/ssh/sshd_config 并添加“AllowUsers YOUR_SSH_ID git
      vi sudoadd: git ALL=(ALL:ALL) NOPASSWD: /usr/local/bin/post-receive-your_site

      设置存储库后,您需要 git remote add live <YOUR NEW REPOS>,然后您可以按 运行 git push live master.
    • 推送到生产环境