I具有一个FastApi功能,可以接收文件,将其保存在本地,将其解开,将未二线图像推入伪影位置。由于某些原因,较大的文件或有时较小的文件在上传200个响应时会计时。我似乎也遵循所有建议,例如nginx,但没有运气!
@router.post("/upload_container")
async def post_container(file: UploadFile = File(), new_container_image: str = Form(), new_tag: str = Form()):
if file.content_type != "application/x-tar":
raise HTTPException(status_code=400, detail="Can only accept tarred version of Docker file")
file_path = str(str(uuid.uuid4()).split("-")[1]) + ".tar"
async with aiofiles.open(file_path, "wb") as out_file:
while content := await file.read(1024): # async read chunk
await out_file.write(content) # async write chunk
file_path = str(os.path.abspath(os.path.join(os.getcwd(), file_path)))
command = "podman load --input {}".format(file_path)
result = subprocess.run(split(command), stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
if result.returncode != 0:
return {"filename": file.filename, "details": result.stderr, "Error": {" failed to unwrap"}}
tagged_image = str(str(result.stdout).split("\n")[0]).split("Loaded image(s):")[1]
if os.path.exists(file_path):
os.remove(file_path)
if tagandpull(tagged_image, new_container_image, new_tag) != True:
return {"message": "Unable to push the image", "image_name": f"{file.filename}"}
return {
"filename": file.filename,
"Details": {
"new_url": "artifactorylocation.cloud.com/"
+ config_data.output["repos"]["local"]["deploy_repo"]
+ "/"
+ new_container_image,
"new_tag": new_tag,
},
}
我的nginx注释是我的nginx。
annotations: {
'kubernetes.io/ingress.class': 'nginx',
'nginx.ingress.kubernetes.io/proxy-body-size': '2400m',
'nginx.ingress.kubernetes.io/proxy-connect-timeout': '600',
'nginx.ingress.kubernetes.io/proxy-read-timeout': '600',
'nginx.ingress.kubernetes.io/proxy-send-timeout': '600'
},
有人面对这个问题吗?
您在请求处理程序中仍在做很多事情,这些事情仅比合理的HTTP超时了。
也许您可以将传入的请求从操作中解除,因此传入请求设置了一个由服务进行轮询的标志,该服务是在请求之外进行工作的服务。