gpt4 book ai didi

flask - 如何在heroku上托管知识库(airbnb)?

转载 作者:行者123 更新时间:2023-12-03 16:52:28 26 4
gpt4 key购买 nike

我尝试托管 knowledge-repo (airbnb)在heroku上。

我发现了几个问题,例如在尝试初始化 /app 时作为知识库:

我注意到,如果我使用 knowledge_repo --repo /app init 手动将 heroku 上的目录定义为知识库,我至少可以使用knowledge_repo --repo <repo_path> runserver测功机上的命令。如果我不初始化知识库,我只会得到一个错误的路径错误:
AssertionError: Provided path '/app' is not a valid repository.
因此,将 heroku 上的目录初始化为知识库应用程序似乎很重要,即 knowledge_repo --repo ./example_repo init我试图在 setup.py 中满足这个要求:

import subprocess
# define repo as knowledge repo in BASH
script = """echo yes "y" | knowledge_repo --repo /app init"""
subprocess.call(['sh', '-c', script])

但这不起作用。知识库没有实现 yes 方法。现在看来,这是一个很难解决的问题。

完全错误:
2017-02-26T20:59:58.780670+00:00 heroku[web.1]: State changed from crashed to starting
2017-02-26T21:00:09.750240+00:00 heroku[web.1]: Starting process with command `gunicorn --log-file=- knowledge_app:app\(\) -w 3 -b 0.0.0.0:3572`
2017-02-26T21:00:14.022140+00:00 heroku[web.1]: State changed from starting to up
2017-02-26T21:00:16.240021+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=GET path="/" host=carwow-knowledge-repo.herokuapp.com request_id=99f7867e-37ce-4417-8a04-53577e13e872 fwd="84.208.51.166" dyno=web.1 connect=5ms service=1158ms status=503 bytes=0
2017-02-26T21:00:27.907629+00:00 heroku[web.1]: Starting process with command `gunicorn --log-file=- knowledge_app:app\(\) -w 3 -b 0.0.0.0:58588`
2017-02-26T21:00:31.561254+00:00 heroku[web.1]: State changed from starting to up
2017-02-26T21:00:31.110520+00:00 app[web.1]: [2017-02-26 21:00:31 +0000] [4] [INFO] Starting gunicorn 19.6.0
2017-02-26T21:00:31.112610+00:00 app[web.1]: [2017-02-26 21:00:31 +0000] [4] [INFO] Listening at: http://0.0.0.0:58588 (4)
2017-02-26T21:00:31.112715+00:00 app[web.1]: [2017-02-26 21:00:31 +0000] [4] [INFO] Using worker: sync
2017-02-26T21:00:31.118097+00:00 app[web.1]: [2017-02-26 21:00:31 +0000] [9] [INFO] Booting worker with pid: 9
2017-02-26T21:00:31.162142+00:00 app[web.1]: [2017-02-26 21:00:31 +0000] [11] [INFO] Booting worker with pid: 11
2017-02-26T21:00:31.230349+00:00 app[web.1]: [2017-02-26 21:00:31 +0000] [13] [INFO] Booting worker with pid: 13
2017-02-26T21:00:35.074917+00:00 app[web.1]: Traceback (most recent call last):
2017-02-26T21:00:35.074937+00:00 app[web.1]: File "/app/.heroku/python/bin/gunicorn", line 11, in <module>
2017-02-26T21:00:35.074940+00:00 app[web.1]: sys.exit(run())
2017-02-26T21:00:35.074976+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 74, in run
2017-02-26T21:00:35.075018+00:00 app[web.1]: WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
2017-02-26T21:00:35.075052+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 192, in run
2017-02-26T21:00:35.075095+00:00 app[web.1]: super(Application, self).run()
2017-02-26T21:00:35.075118+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 72, in run
2017-02-26T21:00:35.075151+00:00 app[web.1]: Arbiter(self).run()
2017-02-26T21:00:35.075174+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 218, in run
2017-02-26T21:00:35.075233+00:00 app[web.1]: self.halt(reason=inst.reason, exit_status=inst.exit_status)
2017-02-26T21:00:35.075236+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 331, in halt
2017-02-26T21:00:35.075309+00:00 app[web.1]: self.stop()
2017-02-26T21:00:35.075331+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 381, in stop
2017-02-26T21:00:35.075429+00:00 app[web.1]: time.sleep(0.1)
2017-02-26T21:00:35.075509+00:00 app[web.1]: self.reap_workers()
2017-02-26T21:00:35.075444+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 231, in handle_chld
2017-02-26T21:00:35.075531+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 506, in reap_workers
2017-02-26T21:00:35.075628+00:00 app[web.1]: raise HaltServer(reason, self.WORKER_BOOT_ERROR)
2017-02-26T21:00:35.075688+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
2017-02-26T21:00:35.147852+00:00 app[web.1]: Repository already exists. Do you want to convert it to a knowledge data repository? Note that this will override any existing `README.md` and `.knowledge_repo_config.py` files, and replace any submodule at `.resources`. (y/n) WARNING:knowledge_repo.repositories.gitrepository:Not updating existing repository. Aborting!

最佳答案

我认为问题出在 PORT 上,请参阅 heroku 文档:

The web process must listen for HTTP traffic on $PORT, which is set by Heroku. EXPOSE in Dockerfile is not respected, but can be used for local testing. Only HTTP requests are supported.



我通过 dockerising 应用程序解决了这个问题,文件的内容如下:

setup.py 的内容
from setuptools import setup, find_packages
from pip.req import parse_requirements
install_reqs = parse_requirements("requirements.txt", session=False)

reqs = [str(ir.req) for ir in install_reqs]
setup(name='name_of_your_knowledge_repo',
packages=find_packages(),
install_reqs=reqs)

docker-python-setup.sh 的内容
#!/bin/sh

export PATH=/heroku/python/bin:$PATH
export PYTHONUNBUFFERED=true
export PYTHONHOME=/heroku/python
export LIBRARY_PATH=/heroku/vendor/lib:/heroku/python/lib:$LIBRARY_PATH
export LD_LIBRARY_PATH=/heroku/vendor/lib:/heroku/python/lib:$LD_LIBRARY_PATH
export LANG=${LANG:-en_US.UTF-8}
export PYTHONHASHSEED=${PYTHONHASHSEED:-random}
export PYTHONPATH=${PYTHONPATH:-/app/};

exec $*

Dockerfile 的内容
###
### This is mostly taken from github.com/heroku/docker-python, but the Docker Hub version of that
### now only supports Python 3, so we have an adapted copy here.
### The main change here is moving our code from /app/user to /app, and moving the python install
### from /app/.heroku to /heroku.
###

# Inherit from Heroku's stack
FROM heroku/cedar:14

# Which version of Python?
ENV PYTHON_VERSION python-2.7.11

# Add Python binaries to path.
ENV PATH /heroku/python/bin/:$PATH

# Create some needed directories
RUN mkdir -p /heroku/python /app/.profile.d
WORKDIR /app

# Install Python
RUN curl -s https://lang-python.s3.amazonaws.com/cedar-14/runtimes/$PYTHON_VERSION.tar.gz | tar zx -C /heroku/python

# Install Pip & Setuptools
RUN curl -s https://bootstrap.pypa.io/get-pip.py | /heroku/python/bin/python

# Export the Python environment variables in /heroku/python.sh
COPY docker-python-setup.sh /heroku/python.sh

ADD requirements.txt /app/
RUN /heroku/python/bin/pip install -r requirements.txt
ADD . /app

# Make locally-built containers run as not-root
# RUN useradd -m notroot
# USER notroot

ENTRYPOINT ["/heroku/python.sh"]
CMD /heroku/python/bin/knowledge_repo --repo /app deploy --port $PORT

Knowledge_app.py 的内容
from knowledge_repo import KnowledgeRepository

import subprocess
# define repo as knowledge repo in BASH
script = """echo yes "y" | knowledge_repo --repo /app init"""
subprocess.call(['sh', '-c', script])

app = KnowledgeRepository.for_uri('/app/.').get_app(config='server_config.py')

要进行部署,我使用了 heroku 指南进行 python 应用程序部署,并且要更新您需要执行以下操作:

通过 docker 在 heroku 上部署
  • 安装 Docker
  • cd 到您本地的知识库目录:cd ~/repo/knowlegde_repo
  • docker build .
  • 安装插件:heroku-container-registry add in .
  • heroku container:push web
  • 关于flask - 如何在heroku上托管知识库(airbnb)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42321462/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com