试图通过在/ usr / bin / freshrules中放入容器来执行此bin文件,API发出请求,视图调用执行者,执行者调用bin文件现在,即使我在这些方面都没有进行任何更改,系统也不再找到文件
执行者:
FRESHBOT_CMD = "freshbot"
cmd_freshbot = [
FRESHBOT_CMD,
"--limit",
"100",
"--country",
country_code,
"list",
f"{host}/*",
"--format",
"user:<url>\t<archived>\t<spiderdate>\n",
cmd_grep = ["grep", "yes"]
cmd_tail = ["tail", f"-{tail}"]
freshbot = Popen(cmd_freshbot, shell=False, stdin=DEVNULL, stdout=PIPE, stderr=DEVNULL)
grep = Popen(cmd_grep, stdin=freshbot.stdout, stdout=PIPE, stderr=DEVNULL)
tail = Popen(cmd_tail, stdin=grep.stdout, stdout=PIPE, stderr=DEVNULL)
line = tail.stdout.readline()
Docker文件:
FROM python:3.7.2-alpine3.9
ENV PYTHONPATH "${PYTHONPATH}:/app/services"
EXPOSE 5008 6008
WORKDIR /app
COPY requirements.txt .
RUN apk add --no-cache docker \
&& apk add --no-cache build-base \
&& apk add --no-cache mariadb-connector-c-dev \
&& pip3 install -r requirements.txt \
&& rm -r /root/.cache \
&& apk del build-base
COPY . .
COPY ./apps/guardian /usr/bin/guardian
COPY ./apps/freshrules /usr/bin/freshrules
COPY ./apps/freshbot /usr/bin/fresbot
Docker日志:
[2020-06-06 11:39:03,652] ERROR in app: Exception on /v1.0/guardian/freshbot/view [POST]
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/usr/local/lib/python3.7/site-packages/flask_restplus/api.py", line 325, in wrapper
resp = resource(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/flask/views.py", line 89, in view
return self.dispatch_request(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/flask_restplus/resource.py", line 44, in dispatch_request
resp = meth(*args, **kwargs)
File "/app/services/etc.py", line 78, in wrapped
return func(*args, **kwargs)
File "/app/services/views/freshbot_service.py", line 38, in post
script = freshbot_cli.find_and_get_host(hostname)
File "/app/libs_int/freshbot_cli.py", line 60, in find_and_get_host
result = get_host_country(hostname, country)
File "/app/libs_int/freshbot_cli.py", line 82, in get_host_country
freshrules = Popen(cmd_freshrules, stdin=DEVNULL, stdout=PIPE, stderr=DEVNULL)
File "/usr/local/lib/python3.7/subprocess.py", line 775, in __init__
restore_signals, start_new_session)
File "/usr/local/lib/python3.7/subprocess.py", line 1522, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'freshrules': 'freshrules'
文件:
-rwxrwxr-x 1 hitmproc hitmproc 1133132 Jul 13 2019 freshbot
Dockerfile
中有一个错字。在freshbot
中,缺少h
。请看下面的内容: