在 dokku 上预部署命令失败

Predeploy command fails on dokku

我的app.json看起来像这样

{
    "scripts": {
      "dokku": {
        "predeploy": "poetry run python manage.py collectstatic --noinput && poetry run python manage.py migrate"
      }
    }
}

它给出了这个错误

 !     Predeploy command declared: 'poetry run python manage.py collectstatic --noinput && poetry run python manage.py migrate'
remote: execution of 'poetry run python manage.py collectstatic --noinput && poetry run python manage.py migrate' failed!
       Creating virtualenv foxflash-9TtSrW0h-py3.6 in /app/.cache/pypoetry/virtualenvs
       Traceback (most recent call last):
         File "manage.py", line 9, in main
           from django.core.management import execute_from_command_line
       ModuleNotFoundError: No module named 'django'
       The above exception was the direct cause of the following exception:
       Traceback (most recent call last):
         File "manage.py", line 20, in <module>
           main()
         File "manage.py", line 15, in main
           ) from exc
       ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?

老实说,不确定要多尝试什么。

您看到的是 virtualenv 未激活。这很奇怪,因为诗歌应该处理这个问题。

但是,一方面,heroku 不支持诗歌。

您可以使用这个构建包: https://elements.heroku.com/buildpacks/moneymeets/python-poetry-buildpack

根据文档,collectstatic 应该在部署期间自动发生: https://devcenter.heroku.com/articles/django-assets#collectstatic-during-builds

最后:poetry buildpack 仅创建一个 requirements.txt,然后由 reqular heroku python buildpack 使用 pip 安装。