mirror of
https://gitlab.com/megazordpobeda/DataRush.git
synced 2026-05-22 23:17:09 +00:00
some lol and keks
This commit is contained in:
@@ -1,2 +1,2 @@
|
|||||||
REGISTRY_LOGIN=devitq
|
REGISTRY_LOGIN=devitq
|
||||||
REGISTRY_PASSWORD=14zQrbzDTM0WXK@CogMQikAvP74Rj4
|
REGISTRY_PASSWORD=prod-zAoUDyHwkgRfQPyVvskH
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
# Change all vars before going to production and remove all comments (!)
|
||||||
|
# Below all environment variables and default values
|
||||||
|
|
||||||
|
REGISTRY_USERNAME=
|
||||||
|
|
||||||
|
REGISTRY_PASSWORD=
|
||||||
|
|
||||||
|
REGISTRY_URL=gitlab.prodcontest.ru:5050
|
||||||
|
|
||||||
|
DOCKER_IMAGE=gitlab.prodcontest.ru:5050/team-15/project/custom-python
|
||||||
@@ -14,5 +14,5 @@ REGISTRY_PASSWORD = os.getenv("REGISTRY_USERNAME", None)
|
|||||||
REGISTRY_URL = os.getenv("REGISTRY_URL", "gitlab.prodcontest.ru:5050")
|
REGISTRY_URL = os.getenv("REGISTRY_URL", "gitlab.prodcontest.ru:5050")
|
||||||
|
|
||||||
DOCKER_IMAGE = os.getenv(
|
DOCKER_IMAGE = os.getenv(
|
||||||
"IMAGE", default="gitlab.prodcontest.ru:5050/team-15/project/custom-python"
|
"DOCKER_IMAGE", default="gitlab.prodcontest.ru:5050/team-15/project/custom-python"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
|
import docker.errors
|
||||||
from fastapi import FastAPI, HTTPException, status
|
from fastapi import FastAPI, HTTPException, status
|
||||||
from pydantic import BaseModel, Field, HttpUrl, constr
|
from pydantic import BaseModel, Field, HttpUrl
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import asyncio
|
import asyncio
|
||||||
import docker
|
import docker
|
||||||
@@ -20,13 +21,24 @@ ALLOWED_FILENAME_CHARS = r"[^a-zA-Z0-9_\-.]"
|
|||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
docker_client = docker.from_env()
|
docker_client = docker.from_env()
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
logging.basicConfig(level=logging.INFO)
|
|
||||||
docker_client.login(
|
docker_client.login(
|
||||||
username=config.REGISTRY_LOGIN,
|
username=config.REGISTRY_LOGIN,
|
||||||
password=config.REGISTRY_PASSWORD,
|
password=config.REGISTRY_PASSWORD,
|
||||||
registry=config.REGISTRY_URL,
|
registry=config.REGISTRY_URL,
|
||||||
)
|
)
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
|
|
||||||
|
@app.on_event("startup")
|
||||||
|
async def pull_docker_image():
|
||||||
|
client = docker.from_env()
|
||||||
|
image_name = config.DOCKER_IMAGE
|
||||||
|
try:
|
||||||
|
client.images.pull(image_name)
|
||||||
|
print(f"Successfully pulled {image_name}")
|
||||||
|
except docker.errors.DockerException as e:
|
||||||
|
print(f"Error pulling {image_name}: {e}")
|
||||||
|
|
||||||
|
|
||||||
class FileDetails(BaseModel):
|
class FileDetails(BaseModel):
|
||||||
@@ -93,9 +105,7 @@ async def download_file(
|
|||||||
session: aiohttp.ClientSession, url: str, dest_path: str
|
session: aiohttp.ClientSession, url: str, dest_path: str
|
||||||
) -> None:
|
) -> None:
|
||||||
try:
|
try:
|
||||||
async with session.get(
|
async with session.get(url, timeout=aiohttp.ClientTimeout(total=30)) as resp:
|
||||||
url, timeout=aiohttp.ClientTimeout(total=30)
|
|
||||||
) as resp:
|
|
||||||
if resp.status != 200:
|
if resp.status != 200:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_400_BAD_REQUEST,
|
status_code=status.HTTP_400_BAD_REQUEST,
|
||||||
@@ -276,9 +286,7 @@ async def execute_code(request: ExecutionRequest) -> ExecutionResponse:
|
|||||||
return ExecutionResponse(
|
return ExecutionResponse(
|
||||||
success=success,
|
success=success,
|
||||||
hash_match=(
|
hash_match=(
|
||||||
result_hash == request.expected_hash
|
result_hash == request.expected_hash if request.expected_hash else None
|
||||||
if request.expected_hash
|
|
||||||
else None
|
|
||||||
),
|
),
|
||||||
output=output[:5000],
|
output=output[:5000],
|
||||||
result_hash=result_hash,
|
result_hash=result_hash,
|
||||||
|
|||||||
Reference in New Issue
Block a user