Skip to content

FastAPI 📦 - ☁

🕐❔ 🛠️ FastAPI 🈸 ⚠ 🎯 🏗 💾 📦 🖼. ⚫️ 🛎 🔨 ⚙️ . 👆 💪 ⤴️ 🛠️ 👈 📦 🖼 1️⃣ 👩‍❤‍👨 💪 🌌.

⚙️ 💾 📦 ✔️ 📚 📈 ✅ 💂‍♂, 🔬, 🦁, & 🎏.

Tip

🏃 & ⏪ 💭 👉 💩 ❓ 🦘 Dockerfile 🔛 👶.

📁 🎮 👶
FROM python:3.9

WORKDIR /code

COPY ./requirements.txt /code/requirements.txt

RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt

COPY ./app /code/app

CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"]

# If running behind a proxy like Nginx or Traefik add --proxy-headers
# CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80", "--proxy-headers"]

⚫️❔ 📦

📦 (✴️ 💾 📦) 📶 💿 🌌 📦 🈸 ✅ 🌐 👫 🔗 & 💪 📁 ⏪ 🚧 👫 ❎ ⚪️➡️ 🎏 📦 (🎏 🈸 ⚖️ 🦲) 🎏 ⚙️.

💾 📦 🏃 ⚙️ 🎏 💾 💾 🦠 (🎰, 🕹 🎰, ☁ 💽, ♒️). 👉 ⛓ 👈 👫 📶 💿 (🔬 🌕 🕹 🎰 👍 🎂 🏃‍♂ ⚙️).

👉 🌌, 📦 🍴 🐥 ℹ, 💸 ⭐ 🏃‍♂ 🛠️ 🔗 (🕹 🎰 🔜 🍴 🌅 🌅).

📦 ✔️ 👫 👍 🏃‍♂ 🛠️ (🛎 1️⃣ 🛠️), 📁 ⚙️, & 🕸, 🔬 🛠️, 💂‍♂, 🛠️, ♒️.

⚫️❔ 📦 🖼

📦 🏃 ⚪️➡️ 📦 🖼.

📦 🖼 🎻 ⏬ 🌐 📁, 🌐 🔢, & 🔢 📋/📋 👈 🔜 🎁 📦. 🎻 📥 ⛓ 👈 📦 🖼 🚫 🏃, ⚫️ 🚫 ➖ 🛠️, ⚫️ 🕴 📦 📁 & 🗃.

🔅 "📦 🖼" 👈 🏪 🎻 🎚,"📦" 🛎 🔗 🏃‍♂ 👐, 👜 👈 ➖ 🛠️.

🕐❔ 📦 ▶️ & 🏃‍♂ (▶️ ⚪️➡️ 📦 🖼) ⚫️ 💪 ✍ ⚖️ 🔀 📁, 🌐 🔢, ♒️. 👈 🔀 🔜 🔀 🕴 👈 📦, ✋️ 🔜 🚫 😣 👽 📦 🖼 (🔜 🚫 🖊 💾).

📦 🖼 ⭐ 📋 📁 & 🎚, ✅ python & 📁 main.py.

& 📦 ⚫️ (🔅 📦 🖼) ☑ 🏃 👐 🖼, ⭐ 🛠️. 👐, 📦 🏃 🕴 🕐❔ ⚫️ ✔️ 🛠️ 🏃 (& 🛎 ⚫️ 🕴 👁 🛠️). 📦 ⛔️ 🕐❔ 📤 🙅‍♂ 🛠️ 🏃 ⚫️.

📦 🖼

☁ ✔️ 1️⃣ 👑 🧰 ✍ & 🛠️ 📦 🖼 & 📦.

& 📤 📢 ☁ 🎡 ⏮️ 🏤-⚒ 🛂 📦 🖼 📚 🧰, 🌐, 💽, & 🈸.

🖼, 📤 🛂 🐍 🖼.

& 📤 📚 🎏 🖼 🎏 👜 💖 💽, 🖼:

⚙️ 🏤-⚒ 📦 🖼 ⚫️ 📶 ⏩ 🌀 & ⚙️ 🎏 🧰. 🖼, 🔄 👅 🆕 💽. 🌅 💼, 👆 💪 ⚙️ 🛂 🖼, & 🔗 👫 ⏮️ 🌐 🔢.

👈 🌌, 📚 💼 👆 💪 💡 🔃 📦 & ☁ & 🏤-⚙️ 👈 💡 ⏮️ 📚 🎏 🧰 & 🦲.

, 👆 🔜 🏃 💗 📦 ⏮️ 🎏 👜, 💖 💽, 🐍 🈸, 🕸 💽 ⏮️ 😥 🕸 🈸, & 🔗 👫 👯‍♂️ 📨 👫 🔗 🕸.

🌐 📦 🧾 ⚙️ (💖 ☁ ⚖️ Kubernetes) ✔️ 👫 🕸 ⚒ 🛠️ 🔘 👫.

📦 & 🛠️

📦 🖼 🛎 🔌 🚮 🗃 🔢 📋 ⚖️ 📋 👈 🔜 🏃 🕐❔ 📦 ▶️ & 🔢 🚶‍♀️ 👈 📋. 📶 🎏 ⚫️❔ 🔜 🚥 ⚫️ 📋 ⏸.

🕐❔ 📦 ▶️, ⚫️ 🔜 🏃 👈 📋/📋 (👐 👆 💪 🔐 ⚫️ & ⚒ ⚫️ 🏃 🎏 📋/📋).

📦 🏃 📏 👑 🛠️ (📋 ⚖️ 📋) 🏃.

📦 🛎 ✔️ 👁 🛠️, ✋️ ⚫️ 💪 ▶️ ✳ ⚪️➡️ 👑 🛠️, & 👈 🌌 👆 🔜 ✔️ 💗 🛠️ 🎏 📦.

✋️ ⚫️ 🚫 💪 ✔️ 🏃‍♂ 📦 🍵 🌘 1️⃣ 🏃‍♂ 🛠️. 🚥 👑 🛠️ ⛔️, 📦 ⛔️.

🏗 ☁ 🖼 FastAPI

🆗, ➡️ 🏗 🕳 🔜 ❗ 👶

👤 🔜 🎦 👆 ❔ 🏗 ☁ 🖼 FastAPI ⚪️➡️ 🖌, ⚓️ 🔛 🛂 🐍 🖼.

👉 ⚫️❔ 👆 🔜 💚 🏆 💼, 🖼:

  • ⚙️ Kubernetes ⚖️ 🎏 🧰
  • 🕐❔ 🏃‍♂ 🔛 🍓 👲
  • ⚙️ ☁ 🐕‍🦺 👈 🔜 🏃 📦 🖼 👆, ♒️.

📦 📄

👆 🔜 🛎 ✔️ 📦 📄 👆 🈸 📁.

⚫️ 🔜 🪀 ✴️ 🔛 🧰 👆 ⚙️ 👈 📄.

🌅 ⚠ 🌌 ⚫️ ✔️ 📁 requirements.txt ⏮️ 📦 📛 & 👫 ⏬, 1️⃣ 📍 ⏸.

👆 🔜 ↗️ ⚙️ 🎏 💭 👆 ✍ 🔃 FastAPI ⏬ ⚒ ↔ ⏬.

🖼, 👆 requirements.txt 💪 👀 💖:

fastapi>=0.68.0,<0.69.0
pydantic>=1.8.0,<2.0.0
uvicorn>=0.15.0,<0.16.0

& 👆 🔜 🛎 ❎ 👈 📦 🔗 ⏮️ pip, 🖼:

$ pip install -r requirements.txt
---> 100%
Successfully installed fastapi pydantic uvicorn

Info

📤 🎏 📁 & 🧰 🔬 & ❎ 📦 🔗.

👤 🔜 🎦 👆 🖼 ⚙️ 🎶 ⏪ 📄 🔛. 👶

FastAPI 📟

  • app 📁 & ⛔ ⚫️.
  • ✍ 🛁 📁 __init__.py.
  • main.py 📁 ⏮️:
from typing import Union

from fastapi import FastAPI

app = FastAPI()


@app.get("/")
def read_root():
    return {"Hello": "World"}


@app.get("/items/{item_id}")
def read_item(item_id: int, q: Union[str, None] = None):
    return {"item_id": item_id, "q": q}

📁

🔜 🎏 🏗 📁 ✍ 📁 Dockerfile ⏮️:

# (1)
FROM python:3.9

# (2)
WORKDIR /code

# (3)
COPY ./requirements.txt /code/requirements.txt

# (4)
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt

# (5)
COPY ./app /code/app

# (6)
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"]

1️⃣. ▶️ ⚪️➡️ 🛂 🐍 🧢 🖼.

2️⃣. ⚒ ⏮️ 👷 📁 /code.

👉 🌐❔ 👥 🔜 🚮 `requirements.txt` 📁 &amp; `app` 📁.

3️⃣. 📁 📁 ⏮️ 📄 /code 📁.

📁 **🕴** 📁 ⏮️ 📄 🥇, 🚫 🎂 📟.

👉 📁 **🚫 🔀 🛎**, ☁ 🔜 🔍 ⚫️ &amp; ⚙️ **💾** 👉 🔁, 🛠️ 💾 ⏭ 🔁 💁‍♂️.

4️⃣. ❎ 📦 🔗 📄 📁.

 `--no-cache-dir` 🎛 💬 `pip` 🚫 🖊 ⏬ 📦 🌐, 👈 🕴 🚥 `pip` 🔜 🏃 🔄 ❎ 🎏 📦, ✋️ 👈 🚫 💼 🕐❔ 👷 ⏮️ 📦.

!!! note
     `--no-cache-dir` 🕴 🔗 `pip`, ⚫️ ✔️ 🕳 ⏮️ ☁ ⚖️ 📦.

 `--upgrade` 🎛 💬 `pip` ♻ 📦 🚥 👫 ⏪ ❎.

↩️ ⏮️ 🔁 🖨 📁 💪 🔍 **☁ 💾**, 👉 🔁 🔜 **⚙️ ☁ 💾** 🕐❔ 💪.

⚙️ 💾 👉 🔁 🔜 **🖊** 👆 📚 **🕰** 🕐❔ 🏗 🖼 🔄 &amp; 🔄 ⏮️ 🛠️, ↩️ **⏬ &amp; ❎** 🌐 🔗 **🔠 🕰**.

5️⃣. 📁 ./app 📁 🔘 /code 📁.

👉 ✔️ 🌐 📟 ❔ ⚫️❔ **🔀 🌅 🛎** ☁ **💾** 🏆 🚫 ⚙️ 👉 ⚖️ 🙆 **📄 🔁** 💪.

, ⚫️ ⚠ 🚮 👉 **🏘 🔚** `Dockerfile`, 🔬 📦 🖼 🏗 🕰.

6️⃣. ⚒ 📋 🏃 uvicorn 💽.

`CMD` ✊ 📇 🎻, 🔠 👫 🎻 ⚫️❔ 👆 🔜 🆎 📋 ⏸ 👽 🚀.

👉 📋 🔜 🏃 ⚪️➡️ **⏮️ 👷 📁**, 🎏 `/code` 📁 👆 ⚒ 🔛 ⏮️ `WORKDIR /code`.

↩️ 📋 🔜 ▶️ `/code` &amp; 🔘 ⚫️ 📁 `./app` ⏮️ 👆 📟, **Uvicorn** 🔜 💪 👀 &amp; **🗄** `app` ⚪️➡️ `app.main`.

Tip

📄 ⚫️❔ 🔠 ⏸ 🔨 🖊 🔠 🔢 💭 📟. 👶

👆 🔜 🔜 ✔️ 📁 📊 💖:

.
├── app
│   ├── __init__.py
│   └── main.py
├── Dockerfile
└── requirements.txt

⛅ 🤝 ❎ 🗳

🚥 👆 🏃‍♂ 👆 📦 ⛅ 🤝 ❎ 🗳 (📐 ⚙) 💖 👌 ⚖️ Traefik, 🚮 🎛 --proxy-headers, 👉 🔜 💬 Uvicorn 💙 🎚 📨 👈 🗳 💬 ⚫️ 👈 🈸 🏃 ⛅ 🇺🇸🔍, ♒️.

CMD ["uvicorn", "app.main:app", "--proxy-headers", "--host", "0.0.0.0", "--port", "80"]

☁ 💾

📤 ⚠ 🎱 👉 Dockerfile, 👥 🥇 📁 📁 ⏮️ 🔗 😞, 🚫 🎂 📟. ➡️ 👤 💬 👆 ⚫️❔ 👈.

COPY ./requirements.txt /code/requirements.txt

☁ & 🎏 🧰 🏗 👉 📦 🖼 🔁, 🚮 1️⃣ 🧽 🔛 🔝 🎏, ▶️ ⚪️➡️ 🔝 Dockerfile & ❎ 🙆 📁 ✍ 🔠 👩‍🌾 Dockerfile.

☁ & 🎏 🧰 ⚙️ 🔗 💾 🕐❔ 🏗 🖼, 🚥 📁 🚫 🔀 ↩️ 🏁 🕰 🏗 📦 🖼, ⤴️ ⚫️ 🔜 🏤-⚙️ 🎏 🧽 ✍ 🏁 🕰, ↩️ 🖨 📁 🔄 & 🏗 🆕 🧽 ⚪️➡️ 🖌.

❎ 📁 📁 🚫 🎯 📉 👜 💁‍♂️ 🌅, ✋️ ↩️ ⚫️ ⚙️ 💾 👈 🔁, ⚫️ 💪 ⚙️ 💾 ⏭ 🔁. 🖼, ⚫️ 💪 ⚙️ 💾 👩‍🌾 👈 ❎ 🔗 ⏮️:

RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt

📁 ⏮️ 📦 📄 🏆 🚫 🔀 🛎. , 🖨 🕴 👈 📁, ☁ 🔜 💪 ⚙️ 💾 👈 🔁.

& ⤴️, ☁ 🔜 💪 ⚙️ 💾 ⏭ 🔁 👈 ⏬ & ❎ 👈 🔗. & 📥 🌐❔ 👥 🖊 📚 🕰. 👶 ...& ❎ 😩 ⌛. 👶 👶

⏬ & ❎ 📦 🔗 💪 ✊ ⏲, ✋️ ⚙️ 💾 🔜 ✊ 🥈 🌅.

& 👆 🔜 🏗 📦 🖼 🔄 & 🔄 ⏮️ 🛠️ ✅ 👈 👆 📟 🔀 👷, 📤 📚 📈 🕰 👉 🔜 🖊.

⤴️, 🏘 🔚 Dockerfile, 👥 📁 🌐 📟. 👉 ⚫️❔ 🔀 🏆 🛎, 👥 🚮 ⚫️ 🏘 🔚, ↩️ 🌖 🕧, 🕳 ⏮️ 👉 🔁 🔜 🚫 💪 ⚙️ 💾.

COPY ./app /code/app

🏗 ☁ 🖼

🔜 👈 🌐 📁 🥉, ➡️ 🏗 📦 🖼.

  • 🚶 🏗 📁 (🌐❔ 👆 Dockerfile , ⚗ 👆 app 📁).
  • 🏗 👆 FastAPI 🖼:
$ docker build -t myimage .

---> 100%

Tip

👀 . 🔚, ⚫️ 🌓 ./, ⚫️ 💬 ☁ 📁 ⚙️ 🏗 📦 🖼.

👉 💼, ⚫️ 🎏 ⏮️ 📁 (.).

▶️ ☁ 📦

  • 🏃 📦 ⚓️ 🔛 👆 🖼:
$ docker run -d --name mycontainer -p 80:80 myimage

✅ ⚫️

👆 🔜 💪 ✅ ⚫️ 👆 ☁ 📦 📛, 🖼: http://192.168.99.100/items/5?q=somequery ⚖️ http://127.0.0.1/items/5?q=somequery (⚖️ 🌓, ⚙️ 👆 ☁ 🦠).

👆 🔜 👀 🕳 💖:

{"item_id": 5, "q": "somequery"}

🎓 🛠️ 🩺

🔜 👆 💪 🚶 http://192.168.99.100/docs ⚖️ http://127.0.0.1/docs (⚖️ 🌓, ⚙️ 👆 ☁ 🦠).

👆 🔜 👀 🏧 🎓 🛠️ 🧾 (🚚 🦁 🎚):

Swagger UI

🎛 🛠️ 🩺

& 👆 💪 🚶 http://192.168.99.100/redoc ⚖️ http://127.0.0.1/redoc (⚖️ 🌓, ⚙️ 👆 ☁ 🦠).

👆 🔜 👀 🎛 🏧 🧾 (🚚 📄):

ReDoc

🏗 ☁ 🖼 ⏮️ 👁-📁 FastAPI

🚥 👆 FastAPI 👁 📁, 🖼, main.py 🍵 ./app 📁, 👆 📁 📊 💪 👀 💖 👉:

.
├── Dockerfile
├── main.py
└── requirements.txt

⤴️ 👆 🔜 ✔️ 🔀 🔗 ➡ 📁 📁 🔘 Dockerfile:

FROM python:3.9

WORKDIR /code

COPY ./requirements.txt /code/requirements.txt

RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt

# (1)
COPY ./main.py /code/

# (2)
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "80"]

1️⃣. 📁 main.py 📁 /code 📁 🔗 (🍵 🙆 ./app 📁).

2️⃣. 🏃 Uvicorn & 💬 ⚫️ 🗄 app 🎚 ⚪️➡️ main (↩️ 🏭 ⚪️➡️ app.main).

⤴️ 🔆 Uvicorn 📋 ⚙️ 🆕 🕹 main ↩️ app.main 🗄 FastAPI 🎚 app.

🛠️ 🔧

➡️ 💬 🔄 🔃 🎏 🛠️ 🔧 ⚖ 📦.

📦 ✴️ 🧰 📉 🛠️ 🏗 & 🛠️ 🈸, ✋️ 👫 🚫 🛠️ 🎯 🎯 🍵 👉 🛠️ 🔧, & 📤 📚 💪 🎛.

👍 📰 👈 ⏮️ 🔠 🎏 🎛 📤 🌌 📔 🌐 🛠️ 🔧. 👶

➡️ 📄 👉 🛠️ 🔧 ⚖ 📦:

  • 🇺🇸🔍
  • 🏃‍♂ 🔛 🕴
  • 🧬 (🔢 🛠️ 🏃)
  • 💾
  • ⏮️ 🔁 ⏭ ▶️

🇺🇸🔍

🚥 👥 🎯 🔛 📦 🖼 FastAPI 🈸 (& ⏪ 🏃‍♂ 📦), 🇺🇸🔍 🛎 🔜 🍵 🗜 ➕1️⃣ 🧰.

⚫️ 💪 ➕1️⃣ 📦, 🖼 ⏮️ Traefik, 🚚 🇺🇸🔍 & 🏧 🛠️ 📄.

Tip

Traefik ✔️ 🛠️ ⏮️ ☁, Kubernetes, & 🎏, ⚫️ 📶 ⏩ ⚒ 🆙 & 🔗 🇺🇸🔍 👆 📦 ⏮️ ⚫️.

👐, 🇺🇸🔍 💪 🍵 ☁ 🐕‍🦺 1️⃣ 👫 🐕‍🦺 (⏪ 🏃 🈸 📦).

🏃‍♂ 🔛 🕴 & ⏏

📤 🛎 ➕1️⃣ 🧰 🈚 ▶️ & 🏃‍♂ 👆 📦.

⚫️ 💪 🔗, ☁ ✍, Kubernetes, ☁ 🐕‍🦺, ♒️.

🌅 (⚖️ 🌐) 💼, 📤 🙅 🎛 🛠️ 🏃 📦 🔛 🕴 & 🛠️ ⏏ 🔛 ❌. 🖼, ☁, ⚫️ 📋 ⏸ 🎛 --restart.

🍵 ⚙️ 📦, ⚒ 🈸 🏃 🔛 🕴 & ⏮️ ⏏ 💪 ⚠ & ⚠. ✋️ 🕐❔ 👷 ⏮️ 📦 🌅 💼 👈 🛠️ 🔌 🔢. 👶

🧬 - 🔢 🛠️

🚥 👆 ✔️ 🌑 🎰 ⏮️ , ☁ 🐝 📳, 🖖, ⚖️ ➕1️⃣ 🎏 🏗 ⚙️ 🛠️ 📎 📦 🔛 💗 🎰, ⤴️ 👆 🔜 🎲 💚 🍵 🧬 🌑 🎚 ↩️ ⚙️ 🛠️ 👨‍💼 (💖 🐁 ⏮️ 👨‍🏭) 🔠 📦.

1️⃣ 📚 📎 📦 🧾 ⚙️ 💖 Kubernetes 🛎 ✔️ 🛠️ 🌌 🚚 🧬 📦 ⏪ 🔗 📐 ⚖ 📨 📨. 🌐 🌑 🎚.

📚 💼, 👆 🔜 🎲 💚 🏗 ☁ 🖼 ⚪️➡️ 🖌 🔬 🔛, ❎ 👆 🔗, & 🏃‍♂ 👁 Uvicorn 🛠️ ↩️ 🏃‍♂ 🕳 💖 🐁 ⏮️ Uvicorn 👨‍🏭.

📐 ⚙

🕐❔ ⚙️ 📦, 👆 🔜 🛎 ✔️ 🦲 👂 🔛 👑 ⛴. ⚫️ 💪 🎲 ➕1️⃣ 📦 👈 🤝 ❎ 🗳 🍵 🇺🇸🔍 ⚖️ 🎏 🧰.

👉 🦲 🔜 ✊ 📐 📨 & 📎 👈 👪 👨‍🏭 (🤞) 🌌, ⚫️ 🛎 🤙 📐 ⚙.

Tip

🎏 🤝 ❎ 🗳 🦲 ⚙️ 🇺🇸🔍 🔜 🎲 📐 ⚙.

& 🕐❔ 👷 ⏮️ 📦, 🎏 ⚙️ 👆 ⚙️ ▶️ & 🛠️ 👫 🔜 ⏪ ✔️ 🔗 🧰 📶 🕸 📻 (✅ 🇺🇸🔍 📨) ⚪️➡️ 👈 📐 ⚙ (👈 💪 🤝 ❎ 🗳) 📦(Ⓜ) ⏮️ 👆 📱.

1️⃣ 📐 ⚙ - 💗 👨‍🏭 📦

🕐❔ 👷 ⏮️ Kubernetes ⚖️ 🎏 📎 📦 🧾 ⚙️, ⚙️ 👫 🔗 🕸 🛠️ 🔜 ✔ 👁 📐 ⚙ 👈 👂 🔛 👑 📶 📻 (📨) 🎲 💗 📦 🏃 👆 📱.

🔠 👫 📦 🏃‍♂ 👆 📱 🔜 🛎 ✔️ 1️⃣ 🛠️ (✅ Uvicorn 🛠️ 🏃 👆 FastAPI 🈸). 👫 🔜 🌐 🌓 📦, 🏃‍♂ 🎏 👜, ✋️ 🔠 ⏮️ 🚮 👍 🛠️, 💾, ♒️. 👈 🌌 👆 🔜 ✊ 📈 🛠️ 🎏 🐚 💽, ⚖️ 🎏 🎰.

& 📎 📦 ⚙️ ⏮️ 📐 ⚙ 🔜 📎 📨 🔠 1️⃣ 📦 ⏮️ 👆 📱 🔄. , 🔠 📨 💪 🍵 1️⃣ 💗 🔁 📦 🏃 👆 📱.

& 🛎 👉 📐 ⚙ 🔜 💪 🍵 📨 👈 🚶 🎏 📱 👆 🌑 (✅ 🎏 🆔, ⚖️ 🔽 🎏 📛 ➡ 🔡), & 🔜 📶 👈 📻 ▶️️ 📦 👈 🎏 🈸 🏃‍♂ 👆 🌑.

1️⃣ 🛠️ 📍 📦

👉 🆎 😐, 👆 🎲 🔜 💚 ✔️ 👁 (Uvicorn) 🛠️ 📍 📦, 👆 🔜 ⏪ 🚚 🧬 🌑 🎚.

, 👉 💼, 👆 🔜 🚫 💚 ✔️ 🛠️ 👨‍💼 💖 🐁 ⏮️ Uvicorn 👨‍🏭, ⚖️ Uvicorn ⚙️ 🚮 👍 Uvicorn 👨‍🏭. 👆 🔜 💚 ✔️ 👁 Uvicorn 🛠️ 📍 📦 (✋️ 🎲 💗 📦).

✔️ ➕1️⃣ 🛠️ 👨‍💼 🔘 📦 (🔜 ⏮️ 🐁 ⚖️ Uvicorn 🛠️ Uvicorn 👨‍🏭) 🔜 🕴 🚮 🙃 🔀 👈 👆 🌅 🎲 ⏪ ✊ 💅 ⏮️ 👆 🌑 ⚙️.

📦 ⏮️ 💗 🛠️ & 🎁 💼

↗️, 📤 🎁 💼 🌐❔ 👆 💪 💚 ✔️ 📦 ⏮️ 🐁 🛠️ 👨‍💼 ▶️ 📚 Uvicorn 👨‍🏭 🛠️ 🔘.

📚 💼, 👆 💪 ⚙️ 🛂 ☁ 🖼 👈 🔌 🐁 🛠️ 👨‍💼 🏃‍♂ 💗 Uvicorn 👨‍🏭 🛠️, & 🔢 ⚒ 🔆 🔢 👨‍🏭 ⚓️ 🔛 ⏮️ 💽 🐚 🔁. 👤 🔜 💬 👆 🌅 🔃 ⚫️ 🔛 🛂 ☁ 🖼 ⏮️ 🐁 - Uvicorn.

📥 🖼 🕐❔ 👈 💪 ⚒ 🔑:

🙅 📱

👆 💪 💚 🛠️ 👨‍💼 📦 🚥 👆 🈸 🙅 🥃 👈 👆 🚫 💪 (🐥 🚫) 👌-🎶 🔢 🛠️ 💁‍♂️ 🌅, & 👆 💪 ⚙️ 🏧 🔢 (⏮️ 🛂 ☁ 🖼), & 👆 🏃‍♂ ⚫️ 🔛 👁 💽, 🚫 🌑.

☁ ✍

👆 💪 🛠️ 👁 💽 (🚫 🌑) ⏮️ ☁ ✍, 👆 🚫🔜 ✔️ ⏩ 🌌 🛠️ 🧬 📦 (⏮️ ☁ ✍) ⏪ 🛡 🔗 🕸 & 📐 ⚖.

⤴️ 👆 💪 💚 ✔️ 👁 📦 ⏮️ 🛠️ 👨‍💼 ▶️ 📚 👨‍🏭 🛠️ 🔘.

🤴 & 🎏 🤔

👆 💪 ✔️ 🎏 🤔 👈 🔜 ⚒ ⚫️ ⏩ ✔️ 👁 📦 ⏮️ 💗 🛠️ ↩️ ✔️ 💗 📦 ⏮️ 👁 🛠️ 🔠 👫.

🖼 (🪀 🔛 👆 🖥) 👆 💪 ✔️ 🧰 💖 🤴 🏭 🎏 📦 👈 🔜 ✔️ 🔐 🔠 📨 👈 👟.

👉 💼, 🚥 👆 ✔️ 💗 📦, 🔢, 🕐❔ 🤴 👟 ✍ ⚖, ⚫️ 🔜 🤚 🕐 👁 📦 🔠 🕰 (📦 👈 🍵 👈 🎯 📨), ↩️ 🤚 📈 ⚖ 🌐 🔁 📦.

⤴️, 👈 💼, ⚫️ 💪 🙅 ✔️ 1️⃣ 📦 ⏮️ 💗 🛠️, & 🇧🇿 🧰 (✅ 🤴 🏭) 🔛 🎏 📦 📈 🤴 ⚖ 🌐 🔗 🛠️ & 🎦 👈 ⚖ 🔛 👈 👁 📦.


👑 ☝, 👌 👉 🚫 ✍ 🗿 👈 👆 ✔️ 😄 ⏩. 👆 💪 ⚙️ 👫 💭 🔬 👆 👍 ⚙️ 💼 & 💭 ⚫️❔ 👍 🎯 👆 ⚙️, ✅ 👅 ❔ 🛠️ 🔧:

  • 💂‍♂ - 🇺🇸🔍
  • 🏃‍♂ 🔛 🕴
  • 🧬 (🔢 🛠️ 🏃)
  • 💾
  • ⏮️ 🔁 ⏭ ▶️

💾

🚥 👆 🏃 👁 🛠️ 📍 📦 👆 🔜 ✔️ 🌅 ⚖️ 🌘 👍-🔬, ⚖, & 📉 💸 💾 🍴 🔠 👈 📦 (🌅 🌘 1️⃣ 🚥 👫 🔁).

& ⤴️ 👆 💪 ⚒ 👈 🎏 💾 📉 & 📄 👆 📳 👆 📦 🧾 ⚙️ (🖼 Kubernetes). 👈 🌌 ⚫️ 🔜 💪 🔁 📦 💪 🎰 ✊ 🔘 🏧 💸 💾 💪 👫, & 💸 💪 🎰 🌑.

🚥 👆 🈸 🙅, 👉 🔜 🎲 🚫 ⚠, & 👆 💪 🚫 💪 ✔ 🏋️ 💾 📉. ✋️ 🚥 👆 ⚙️ 📚 💾 (🖼 ⏮️ 🎰 🏫 🏷), 👆 🔜 ✅ ❔ 🌅 💾 👆 😩 & 🔆 🔢 📦 👈 🏃 🔠 🎰 (& 🎲 🚮 🌖 🎰 👆 🌑).

🚥 👆 🏃 💗 🛠️ 📍 📦 (🖼 ⏮️ 🛂 ☁ 🖼) 👆 🔜 ✔️ ⚒ 💭 👈 🔢 🛠️ ▶️ 🚫 🍴 🌖 💾 🌘 ⚫️❔ 💪.

⏮️ 🔁 ⏭ ▶️ & 📦

🚥 👆 ⚙️ 📦 (✅ ☁, Kubernetes), ⤴️ 📤 2️⃣ 👑 🎯 👆 💪 ⚙️.

💗 📦

🚥 👆 ✔️ 💗 📦, 🎲 🔠 1️⃣ 🏃 👁 🛠️ (🖼, Kubernetes 🌑), ⤴️ 👆 🔜 🎲 💚 ✔️ 🎏 📦 🔨 👷 ⏮️ 📶 👁 📦, 🏃 👁 🛠️, 🏃 🔁 👨‍🏭 📦.

Info

🚥 👆 ⚙️ Kubernetes, 👉 🔜 🎲 🕑 📦.

🚥 👆 ⚙️ 💼 📤 🙅‍♂ ⚠ 🏃‍♂ 👈 ⏮️ 📶 💗 🕰 🔗 (🖼 🚥 👆 🚫 🏃 💽 🛠️, ✋️ ✅ 🚥 💽 🔜), ⤴️ 👆 💪 🚮 👫 🔠 📦 ▶️️ ⏭ ▶️ 👑 🛠️.

👁 📦

🚥 👆 ✔️ 🙅 🖥, ⏮️ 👁 📦 👈 ⤴️ ▶️ 💗 👨‍🏭 🛠️ (⚖️ 1️⃣ 🛠️), ⤴️ 👆 💪 🏃 👈 ⏮️ 🔁 🎏 📦, ▶️️ ⏭ ▶️ 🛠️ ⏮️ 📱. 🛂 ☁ 🖼 🐕‍🦺 👉 🔘.

🛂 ☁ 🖼 ⏮️ 🐁 - Uvicorn

📤 🛂 ☁ 🖼 👈 🔌 🐁 🏃‍♂ ⏮️ Uvicorn 👨‍🏭, ℹ ⏮️ 📃: 💽 👨‍🏭 - 🐁 ⏮️ Uvicorn.

👉 🖼 🔜 ⚠ ✴️ ⚠ 🔬 🔛: 📦 ⏮️ 💗 🛠️ & 🎁 💼.

Warning

📤 ↕ 🤞 👈 👆 🚫 💪 👉 🧢 🖼 ⚖️ 🙆 🎏 🎏 1️⃣, & 🔜 👻 📆 🏗 🖼 ⚪️➡️ 🖌 🔬 🔛: 🏗 ☁ 🖼 FastAPI.

👉 🖼 ✔️ 🚘-📳 🛠️ 🔌 ⚒ 🔢 👨‍🏭 🛠️ ⚓️ 🔛 💽 🐚 💪.

⚫️ ✔️ 🤔 🔢, ✋️ 👆 💪 🔀 & ℹ 🌐 📳 ⏮️ 🌐 🔢 ⚖️ 📳 📁.

⚫️ 🐕‍🦺 🏃 ⏮️ 🔁 ⏭ ▶️ ⏮️ ✍.

Tip

👀 🌐 📳 & 🎛, 🚶 ☁ 🖼 📃: Tiangolo/uvicorn-🐁-fastapi.

🔢 🛠️ 🔛 🛂 ☁ 🖼

🔢 🛠️ 🔛 👉 🖼 📊 🔁 ⚪️➡️ 💽 🐚 💪.

👉 ⛓ 👈 ⚫️ 🔜 🔄 🗜 🌅 🎭 ⚪️➡️ 💽 💪.

👆 💪 🔆 ⚫️ ⏮️ 📳 ⚙️ 🌐 🔢, ♒️.

✋️ ⚫️ ⛓ 👈 🔢 🛠️ 🪀 🔛 💽 📦 🏃, 💸 💾 🍴 🔜 🪀 🔛 👈.

, 🚥 👆 🈸 🍴 📚 💾 (🖼 ⏮️ 🎰 🏫 🏷), & 👆 💽 ✔️ 📚 💽 🐚 ✋️ 🐥 💾, ⤴️ 👆 📦 💪 🔚 🆙 🔄 ⚙️ 🌅 💾 🌘 ⚫️❔ 💪, & 🤕 🎭 📚 (⚖️ 💥). 👶

Dockerfile

📥 ❔ 👆 🔜 ✍ Dockerfile ⚓️ 🔛 👉 🖼:

FROM tiangolo/uvicorn-gunicorn-fastapi:python3.9

COPY ./requirements.txt /app/requirements.txt

RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt

COPY ./app /app

🦏 🈸

🚥 👆 ⏩ 📄 🔃 🏗 🦏 🈸 ⏮️ 💗 📁, 👆 Dockerfile 💪 ↩️ 👀 💖:

FROM tiangolo/uvicorn-gunicorn-fastapi:python3.9

COPY ./requirements.txt /app/requirements.txt

RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt

COPY ./app /app/app

🕐❔ ⚙️

👆 🔜 🎲 🚫 ⚙️ 👉 🛂 🧢 🖼 (⚖️ 🙆 🎏 🎏 1️⃣) 🚥 👆 ⚙️ Kubernetes (⚖️ 🎏) & 👆 ⏪ ⚒ 🧬 🌑 🎚, ⏮️ 💗 📦. 📚 💼, 👆 👍 📆 🏗 🖼 ⚪️➡️ 🖌 🔬 🔛: 🏗 ☁ 🖼 FastAPI.

👉 🖼 🔜 ⚠ ✴️ 🎁 💼 🔬 🔛 📦 ⏮️ 💗 🛠️ & 🎁 💼. 🖼, 🚥 👆 🈸 🙅 🥃 👈 ⚒ 🔢 🔢 🛠️ ⚓️ 🔛 💽 👷 👍, 👆 🚫 💚 😥 ⏮️ ❎ 🛠️ 🧬 🌑 🎚, & 👆 🚫 🏃 🌅 🌘 1️⃣ 📦 ⏮️ 👆 📱. ⚖️ 🚥 👆 🛠️ ⏮️ ☁ ✍, 🏃 🔛 👁 💽, ♒️.

🛠️ 📦 🖼

⏮️ ✔️ 📦 (☁) 🖼 📤 📚 🌌 🛠️ ⚫️.

🖼:

  • ⏮️ ☁ ✍ 👁 💽
  • ⏮️ Kubernetes 🌑
  • ⏮️ ☁ 🐝 📳 🌑
  • ⏮️ ➕1️⃣ 🧰 💖 🖖
  • ⏮️ ☁ 🐕‍🦺 👈 ✊ 👆 📦 🖼 & 🛠️ ⚫️

☁ 🖼 ⏮️ 🎶

🚥 👆 ⚙️ 🎶 🛠️ 👆 🏗 🔗, 👆 💪 ⚙️ ☁ 👁-▶️ 🏗:

# (1)
FROM python:3.9 as requirements-stage

# (2)
WORKDIR /tmp

# (3)
RUN pip install poetry

# (4)
COPY ./pyproject.toml ./poetry.lock* /tmp/

# (5)
RUN poetry export -f requirements.txt --output requirements.txt --without-hashes

# (6)
FROM python:3.9

# (7)
WORKDIR /code

# (8)
COPY --from=requirements-stage /tmp/requirements.txt /code/requirements.txt

# (9)
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt

# (10)
COPY ./app /code/app

# (11)
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"]

1️⃣. 👉 🥇 ▶️, ⚫️ 🌟 requirements-stage.

2️⃣. ⚒ /tmp ⏮️ 👷 📁.

📥 🌐❔ 👥 🔜 🏗 📁 `requirements.txt`

3️⃣. ❎ 🎶 👉 ☁ ▶️.

4️⃣. 📁 pyproject.toml & poetry.lock 📁 /tmp 📁.

↩️ ⚫️ ⚙️ `./poetry.lock*` (▶️ ⏮️ `*`), ⚫️ 🏆 🚫 💥 🚥 👈 📁 🚫 💪.

5️⃣. 🏗 requirements.txt 📁.

6️⃣. 👉 🏁 ▶️, 🕳 📥 🔜 🛡 🏁 📦 🖼.

7️⃣. ⚒ ⏮️ 👷 📁 /code.

8️⃣. 📁 requirements.txt 📁 /code 📁.

👉 📁 🕴 🖖 ⏮️ ☁ ▶️, 👈 ⚫️❔ 👥 ⚙️ `--from-requirements-stage` 📁 ⚫️.

9️⃣. ❎ 📦 🔗 🏗 requirements.txt 📁.

1️⃣0️⃣. 📁 app 📁 /code 📁.

1️⃣1️⃣. 🏃 uvicorn 📋, 💬 ⚫️ ⚙️ app 🎚 🗄 ⚪️➡️ app.main.

Tip

🖊 💭 🔢 👀 ⚫️❔ 🔠 ⏸ 🔨.

☁ ▶️ 🍕 Dockerfile 👈 👷 🍕 📦 🖼 👈 🕴 ⚙️ 🏗 📁 ⚙️ ⏪.

🥇 ▶️ 🔜 🕴 ⚙️ ❎ 🎶 & 🏗 requirements.txt ⏮️ 👆 🏗 🔗 ⚪️➡️ 🎶 pyproject.toml 📁.

👉 requirements.txt 📁 🔜 ⚙️ ⏮️ pip⏭ ▶️.

🏁 📦 🖼 🕴 🏁 ▶️ 🛡. ⏮️ ▶️(Ⓜ) 🔜 ❎.

🕐❔ ⚙️ 🎶, ⚫️ 🔜 ⚒ 🔑 ⚙️ ☁ 👁-▶️ 🏗 ↩️ 👆 🚫 🤙 💪 ✔️ 🎶 & 🚮 🔗 ❎ 🏁 📦 🖼, 👆 🕴 💪 ✔️ 🏗 requirements.txt 📁 ❎ 👆 🏗 🔗.

⤴️ ⏭ (& 🏁) ▶️ 👆 🔜 🏗 🖼 🌅 ⚖️ 🌘 🎏 🌌 🔬 ⏭.

⛅ 🤝 ❎ 🗳 - 🎶

🔄, 🚥 👆 🏃‍♂ 👆 📦 ⛅ 🤝 ❎ 🗳 (📐 ⚙) 💖 👌 ⚖️ Traefik, 🚮 🎛 --proxy-headers 📋:

CMD ["uvicorn", "app.main:app", "--proxy-headers", "--host", "0.0.0.0", "--port", "80"]

🌃

⚙️ 📦 ⚙️ (✅ ⏮️ & Kubernetes) ⚫️ ▶️️ 📶 🎯 🍵 🌐 🛠️ 🔧:

  • 🇺🇸🔍
  • 🏃‍♂ 🔛 🕴
  • 🧬 (🔢 🛠️ 🏃)
  • 💾
  • ⏮️ 🔁 ⏭ ▶️

🌅 💼, 👆 🎲 🏆 🚫 💚 ⚙️ 🙆 🧢 🖼, & ↩️ 🏗 📦 🖼 ⚪️➡️ 🖌 1️⃣ ⚓️ 🔛 🛂 🐍 ☁ 🖼.

✊ 💅 👩‍🌾 Dockerfile & ☁ 💾 👆 💪 📉 🏗 🕰, 📉 👆 📈 (& ❎ 😩). 👶

🎯 🎁 💼, 👆 💪 💚 ⚙️ 🛂 ☁ 🖼 FastAPI. 👶