Commit e084b24b authored by nanahira's avatar nanahira

first

parents
Pipeline #39282 failed with stages
in 42 seconds
__pycache__
*.pyc
*.pyo
venv
*.http
.venv
.idea
.git*
Dockerfile
.dockerignore
__pycache__
*.pyc
*.pyo
venv
*.http
.idea
\ No newline at end of file
stages:
- build
- deploy
variables:
GIT_DEPTH: "1"
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
.build-image:
stage: build
script:
- docker build --pull -t $TARGET_IMAGE .
- docker push $TARGET_IMAGE
build-x86:
extends: .build-image
tags:
- docker
variables:
TARGET_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-x86
build-arm:
extends: .build-image
tags:
- docker-arm
variables:
TARGET_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-arm
.deploy:
stage: deploy
tags:
- docker
script:
- docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-x86
- docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-arm
- docker manifest create $TARGET_IMAGE --amend $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-x86 --amend
$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-arm
- docker manifest push $TARGET_IMAGE
deploy_latest:
extends: .deploy
variables:
TARGET_IMAGE: $CI_REGISTRY_IMAGE:latest
only:
- master
deploy_branch:
extends: .deploy
variables:
TARGET_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
FROM python:3.10
WORKDIR /app
COPY ./requirements.txt ./
RUN pip install --no-cache -r ./requirements.txt
COPY . ./
ENTRYPOINT ["python"]
CMD ["main.py"]
import os
from fastapi import FastAPI, HTTPException
from fastapi.responses import RedirectResponse
import httpx
from starlette.middleware.cors import CORSMiddleware
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.get("/{route}")
async def redirect_route(route: str):
env_key = f"ROUTE_{route}"
target_url = os.getenv(env_key)
if not target_url:
raise HTTPException(status_code=404, detail=f"Route {env_key} not found.")
try:
async with httpx.AsyncClient() as client:
response = await client.get(target_url)
response.raise_for_status()
redirect_link = response.text.strip()
except Exception as e:
raise HTTPException(status_code=501, detail=f"Failed to retrieve redirect link: {str(e)}")
return RedirectResponse(url=redirect_link, status_code=301)
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, proxy_headers=True, host="0.0.0.0", port=3000)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment