全部指南

Python · FastAPI

Install from requirements.txt and run with uvicorn.

  1. 1main.py · requirements.txt

    python
    from fastapi import FastAPI
    app = FastAPI()
    
    @app.get("/")
    def root():
        return {"hello": "onecloud"}
    
    # requirements.txt
    # fastapi
    # uvicorn[standard]
  2. 2Start command

    Set it in Service settings → Start command, or via the CLI.

    bash
    uvicorn main:app --host 0.0.0.0 --port $PORT
  3. 3Deploy (pick one)

    ① Connect GitHub: Project → Add service → GitHub repository (deploys on push) ② From this folder: oc up --wait (builds even without a Dockerfile) ③ Upload a folder or zip in the console: Add service → Upload source

    bash
    oc login
    oc project create my-app --link
    oc up --wait

相关指南