【问题标题】:Git pass variable through push to remote serverGit通过推送将变量传递到远程服务器
【发布时间】:2015-11-02 13:32:09
【问题描述】:

我有一个服务器设置为“生产”远程,它运行一个接收后的 shell 脚本来部署站点,并为主分支进行“硬”部署。或者将 dev 分支的“软”部署到不同的目录。

soft (fast, low resources) - checks out the work-tree to the /dev directory (fast)

hard (slower, more resources) - check out the work-tree to a new '/temp' directory, 
       copies the non-tracked files from the '/live' directory to '/temp' (can be large)
       if successful, renames the '/live' directory to '/live-old'
       renames the '/temp' to '/live' and deletes the older '/live-old' directory

有时我只想在主分支推送上进行“软”部署,如果它像修补程序这样微小的东西,因为硬部署可能需要一段时间来复制上传等未跟踪的文件,并且似乎浪费服务器资源说如果为不同的应用程序做多个修补程序。

我可以将一个变量从我的本地服务器(如 git 配置文件的远程部分)传递到远程服务器,以告诉它为 master 分支进行软部署还是硬部署?

我在想远程服务器是否知道本地远程名称是什么,或者我可以在远程定义中向 url 添加一个变量,例如:

[remote "production-hard"]
    url = ssh://project.git?deploy=hard
    fetch = +refs/heads/*:refs/remotes/production/*
[remote "production-soft"]
    url = ssh://project.git?deploy=soft
    fetch = +refs/heads/*:refs/remotes/production/*

我确信这种方式可能行不通,但希望你能理解我想要做什么。

另外,请说这是否真的是不好的做法,我应该使用另一种方法。

谢谢。

【问题讨论】:

    标签: git deployment version-control web-deployment git-post-receive


    【解决方案1】:

    不,你不能传递额外的变量。

    但是您可以评估被推送到的分支名称。

    因此,您可以设置一个post-receive hook 来检查被推送到的分支:

    • 推送到production-hard → 执行hard 部署
    • 推送到production-soft → 执行soft 部署

    【讨论】:

    • 是的,我担心你会这么说。如果可以的话,我真的不想拥有多个分支机构。它不会也破坏 Git Flow 吗?
    • @StuckInSpace:我不太喜欢 Git Flow,但 IIRC 是纯本地的东西。而且你总是能够推送到不同(或多个)远程分支
    猜你喜欢
    • 2017-02-15
    • 2013-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-22
    • 2011-12-29
    相关资源
    最近更新 更多