所以我正在用c++为学校写一个基本的http服务器。目前,我的服务可以接收请求并发送基本响应。我正在用python请求编写一个基本的验收测试,并通过在后台运行webserver,然后运行python客户机,在shell脚本中执行它。在本地(在Mac上)运行测试也很好,也适用于自定义的ubuntu容器,它也用于我的config.yml文件。但是,当在circleCI上运行测试时,客户端似乎被接受了,但是GET请求没有被接收,程序挂起。有没有人知道这是为什么,以及如何解决?请不要认为还在开发包含代码,所以请:slight_smile:
我的config.yml:
version: 2
jobs:
build:
docker:
- image: "rynosaurusrex/ci_for_codam:webserv"
steps:
- checkout
- run:
name: Build
command: 'echo Building'
- run:
name: Unit-Test
command: "make test && ./unit_test"
- run:
name: Acceptance-Test
command: make acceptence我的基本python请求:
import time
import requests
from requests import Session
from enum import Enum
class Colors:
OKGREEN = '\033[92m'
FAILRED = '\033[91m'
NATURAL = '\033[0m'
OK = 200
BAD_REQUEST = 400
NOT_FOUND = 404
URI_TOO_LONG = 414
TEAPOT = 418
NOT_IMPLEMENTED = 501
localhost = "http://localhost:80"
EXIT_CODE = 0
print("Connecting to server...")
r = requests.get(localhost)
print("Request send!")
if r.status_code != OK:
print(f"{Colors.FAILRED}[KO] {Colors.NATURAL} Get request on http://localhost:80")
EXIT_CODE = 1;
else:
print(f"{Colors.OKGREEN}[OK] {Colors.NATURAL} Get request on http://localhost:80")
# sleep so that the exit code is that of the python script and not the server
time.sleep(1)
exit(EXIT_CODE)还有我的杂乱无章的脚本来运行所有的东西:
#!/bin/bash
# the & runs a command/program in the background
./Webserver.out &
# Save the PID to kill the webserv
PID=$!
# sleep for 2 second to make sure the server has time to start up
sleep 2
# run the tests
# curl localhost:80
python3 acceptence_tests/TestClient.py
# save the return val of the tests for CI
T1=$?
kill $PID
exit $T1 因此,在运行测试时,我会打印一些状态更新。在打印Accepted client on fd 4时,accept()调用是成功的,但请求似乎没有通过,这可能是握手问题吗?如前所述,在本地和容器中直接运行此操作将交付预期的结果,本地端口如何在CircleCI中工作?

我尝试过用端口443 (也是0.0.0.0 )将请求更改为https,似乎handshake失败了吗?
提前感谢!
发布于 2022-04-11 11:08:38
这可能是由于尝试在容器中作为根用户运行而引起的,因为出于安全原因,主机系统(在本例中是由circleCI/github配置/拥有)可能会阻止/限制这一点。您可以尝试在Dockerfile中显式创建和使用单独的用户,以避免出现奇怪的权限问题。
例如,如果将其添加到您的Dockerfile中,您将使用test_user而不是root
RUN useradd -m test_user
USER test_userhttps://stackoverflow.com/questions/71757204
复制相似问题