【问题标题】:Heroku deploy a sub directory?Heroku 部署一个子目录?
【发布时间】:2014-12-02 05:09:51
【问题描述】:

我正在尝试部署一个节点应用程序,但我遇到了代码结构方面的问题。该应用在顶层是 git 初始化的,它看起来像:

App (git tracked in remote repo)
- .git
- server
- client
- plugin
- extras

由于 Heroku 只需要我直接使用 package.json 构建文件推送服务器目录,我不确定如何设置我的目录。我希望它可以从“应用程序/服务器”文件夹中部署 heroku,但仍然像现在一样 git pull/push 整个应用程序:

App (git tracked in remote repo)
- .git
- server (can run 'git push heroku master' for just this folder)
  - .git (?)
- client
- plugin
- extras

我怎样才能最简单地做到这一点?我读过关于 git-submodules 的文章,但这看起来很乱,我想确定一下。非常感谢 git nub。

【问题讨论】:

    标签: node.js git heroku


    【解决方案1】:

    我认为 git-subtree 应该可以工作:

    git subtree push --prefix server heroku master

    其他资源:

    【讨论】:

      【解决方案2】:

      Heroku 需要 package.json 和存储库根目录中的锁定文件,否则部署将失败。

      但是,您可以在 repo 的根目录中设置 package.json,它会安装子目录的依赖项并运行它们的相关命令。

      以使用纱线为例,在您的情况下,您可以在根目录中放置一个空的 yarn.lock 和一个 package.json,例如:

      {
        "name": "my-project",
        "version": "0.1.0",
        "private": true,
        "scripts": {
          "postinstall": "yarn --cwd server --production=false install",
          "build": "yarn --cwd server serve"
        }
      }
      

      --production=false ensures that devDependencies will be installed,否则不会发生,因为在 Heroku 的环境中 NODE_ENV 设置为 production

      【讨论】:

        【解决方案3】:

        或者,您可以使用 git subtree 在 GitHub 上创建 heroku 分支:

        git subtree push --prefix server origin heroku
        

        然后您可以使用 Heroku Button 将其部署到 Heroku。只需将 app.json 和带有按钮的 README.md 添加到您的服务器目录即可:

        [![Deploy](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy)
        

        让 Heroku 处理剩下的事情。

        【讨论】:

        • 你能分享更多关于如何让这个按钮在子文件夹中工作的信息吗?我的子文件夹中有 app.json 和 README.md,但链接仍然尝试从根目录获取 app.json
        • @ScottCarlson 在您的主要README.md 中,将按钮标记更改为[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/roninbar/kwik-e-mart/tree/heroku)(将roninbar/kwik-e-mart 替换为您的GitHub 用户名/repo)。
        • @ScottCarlson 或者,在单击按钮之前切换到 GitHub 中的 heroku 分支。
        猜你喜欢
        • 1970-01-01
        • 2014-12-06
        • 2013-09-23
        • 2014-06-29
        • 2018-07-15
        • 2022-01-06
        • 1970-01-01
        • 2013-08-07
        • 2011-09-05
        相关资源
        最近更新 更多