如何在 heroku 按钮 app.json 中运行部署后脚本

T.K*_*Kul 2 heroku

我尝试设置 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"
       ]
  }
}
Run Code Online (Sandbox Code Playgroud)

这里的错误信息在

运行脚本和扩展 dynos

部署后退出代码不是 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")
Run Code Online (Sandbox Code Playgroud)

Ade*_*laN 7

这对我有用:

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

我的app.json文件:

{
  ...
  "scripts": {
    "postdeploy": "./myscript.sh"
  }
}
Run Code Online (Sandbox Code Playgroud)

myscript.sh文件:

#!/bin/sh

bundle exec rake db:migrate
bundle exec rake db:seed
bundle exec my_sample:load
Run Code Online (Sandbox Code Playgroud)