【问题标题】:How to run postdeploy scripts in heroku button app.json如何在 heroku 按钮 app.json 中运行 postdeploy 脚本
【发布时间】:2019-01-18 05:51:53
【问题描述】:

我尝试设置 Heroku Button,我的应用需要多个部署后脚本。不知道怎么把它放在每个旁边。

这里是我的 app.json

{
  "name": "App on Heroku",
  "description": "The App deployable to Heroku.",
  "keywords": [
    "App",
    "Heroku"
  ],
  "repository": "https://github.com/myaccount/myapp",
  "logo": "http://node-js-sample.herokuapp.com/node.svg",
  "addons": [
    "heroku-postgresql",
    "postmark"
  ],
  "scripts": {
    "postdeploy": [
        "bundle exec rake db:migrate",
        "bundle exec rake db:seed",
        "bundle exec my_sample:load"
       ]
  }
}

这里有错误信息

运行脚本和缩放测功机

部署后退出代码不是 0

bash: ((: bundle exec rake db:migrate,bundle exec rake db:seed,bundle exec my_sample:load: syntax error in expression (error token is "exec rake db:migrate,bundle exec rake db:seed,bundle exec my_sample:load")

【问题讨论】:

  • 我认为你不能运行多个脚本

标签: heroku


【解决方案1】:

这对我有用:

  1. 在与您的 app.json 文件相同的目录中创建一个名为 myscript.sh 的 bash/sh 脚本(通常,这应该是您的根目录)。
  2. 将所有命令放在该文件中,就像在终端中调用它们一样。
  3. 在您的 app.json 文件中引用脚本(见下文)
  4. 确保您的脚本具有正确的权限。最好运行chmod +x myscript.sh

我的 app.json 文件:

{
  ...
  "scripts": {
    "postdeploy": "./myscript.sh"
  }
}

myscript.sh 文件:

#!/bin/sh

bundle exec rake db:migrate
bundle exec rake db:seed
bundle exec my_sample:load

【讨论】:

  • 谢谢..我能够制作类似的东西并且它有效..使用“sh heroku_postdeploy_script.sh”然后是一个简单的.sh文件,我不需要#!/bin/sh位.
【解决方案2】:

我发现这个谷歌搜索其他问题,但认为这个文档是相关的 - https://devcenter.heroku.com/articles/release-phase#review-apps-and-the-postdeploy-script

应用该文档并回答您的问题:

使用以下命令在 Heroku Procfile 中运行 db:migrate 命令,将架构设置与数据加载分开:

release: bundle exec rake db:migrate

然后将您的其他postdeploy 步骤保留在app.json 文件中。

  ...
  "scripts": {
    "postdeploy": "bundle exec rake db:seed && bundle exec rake my_sample:load"
  }
}```

【讨论】:

    【解决方案3】:

    应该能够做到这一点(dokku 示例,但 heroku 也是如此):

    {
      "scripts": {
        "dokku": {
          "predeploy": "bundle exec rake db:migrate && bundle exec rake some:task"
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2018-08-05
      • 2018-04-22
      • 1970-01-01
      • 2012-10-14
      • 1970-01-01
      • 2023-03-09
      • 2015-06-29
      • 1970-01-01
      • 2017-06-02
      相关资源
      最近更新 更多