在Docker中部署可编辑的CLI应用程序Python软件包
我正在尝试在 docker 中部署可编辑的 CLI python 包。
我的包已在 docker 中成功构建,当我执行 docker rungreet-dockergreet --help 时,它会显示带有子命令的帮助消息。
当我执行 docker rungreet-dockergreet say sam 时,它应该回显 Hi sam,但它会显示带有子命令的帮助消息。
我错过了什么!!
我的代码
├── tests
├── __init__
├── pyproject.toml
├── Dockerfile
├── requirements.py
├── setup.py
└── src
├── __init__.py
└── greetings.py
greetings.py
@click.group()
def main():
pass
@click.command()
@click.argument('name')
def say(name):
print(f'Hi {name}')
main.add_command(say)
if __name__ == '__main__':
main()
setup.py
package_dir={"": "src"},
packages=setuptools.find_packages(where="src"),
python_requires=">=3.6",
include_package_data=True,
entry_points={
'console_scripts': [
'greet= greetings:main'
]
}
<强>Dockerfile
FROM python:3.6
RUN mkdir /app
COPY . /app
COPY requirements.txt /app/requirements.txt
WORKDIR /app
RUN pip install -r /app/requirements.txt
ENV PYTHONPATH=/app
RUN pip install --editable .
ENTRYPOINT [ "greet", "--help" ]
requirements.txt 点击
I am trying to deploy an editable CLI python package in the docker.
My package is successfully built in the docker and when I execute docker run greet-docker greet --help
it shows the help message with the subcommand.
When I execute the docker run greet-docker greet say sam
it should echo Hi sam
but it shows the help message with the subcommand.
What did I miss!!
My code
├── tests
├── __init__
├── pyproject.toml
├── Dockerfile
├── requirements.py
├── setup.py
└── src
├── __init__.py
└── greetings.py
greetings.py
@click.group()
def main():
pass
@click.command()
@click.argument('name')
def say(name):
print(f'Hi {name}')
main.add_command(say)
if __name__ == '__main__':
main()
setup.py
package_dir={"": "src"},
packages=setuptools.find_packages(where="src"),
python_requires=">=3.6",
include_package_data=True,
entry_points={
'console_scripts': [
'greet= greetings:main'
]
}
Dockerfile
FROM python:3.6
RUN mkdir /app
COPY . /app
COPY requirements.txt /app/requirements.txt
WORKDIR /app
RUN pip install -r /app/requirements.txt
ENV PYTHONPATH=/app
RUN pip install --editable .
ENTRYPOINT [ "greet", "--help" ]
requirements.txtclick
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这花了我几乎一天的时间才弄清楚。从 docker 文件中删除
ENTRYPOINT [ "greet", "--help" ]
。我们在可编辑区域中运行的任何命令都会被ENTRYPOINT
覆盖。This took me almost a day to figure out. Remove the
ENTRYPOINT [ "greet", "--help" ]
from the docker file. Whatever command we run in the editable gets overwritten by theENTRYPOINT
.