Skip to main content

微服务关键概念

· 3 min read

关键术语

  • 微服务(Microservice)- 封装的、可重复使用的逻辑,可部署到生产环境中。
  • 持续集成(CI)--经常将代码变更合并到共享存储库中,并自动构建和测试变更以尽早发现问题的做法。
  • 持续交付(Continuous Delivery)--一种开发实践,可通过自动部署随时可靠地发布增量软件变更。
  • 端到端 MLOps- 通过 Hugging Face Spaces 等平台,实现从模型开发到部署和托管的机器学习生命周期的完全自动化。
  • AWS App Runner - 用于部署容器化网络服务和 API 的完全托管服务。
  • Flask- 一种流行的轻量级 Python 网络应用程序框架。
  • Makefile- 包含一组用于自动构建和管理项目的指令的文件。
  • Requirements File - 包含应用程序使用的 Python 软件包依赖关系列表的文本文件。

运行微服务

微服务 CI

  • Install
  • Lint
  • Format
  • Test
  • Deploy

CI file: main.yml

name: Python application test with Github Actions

on: [push]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Install dependencies
run: |
make install
- name: Lint with pylint
run: |
make lint
- name: Test with pytest
run: |
make test
- name: Format code
run: |
make format

makefile

install:
pip install --upgrade pip &&\
pip install -r requirements.txt

test:
python -m pytest -vv test_hello.py

format:
black *.py

lint:
pylint --disable=R,C hello.py

all: install lint test

端对端 MLOps Huggingface spaces

实践-跳转链接

微服务部署

  • AWS Cloud 9 + fastapi + AWS App Runner(integrate with Github repo): https://github.com/noahgift/fastapi
  • GitHub Code Space + Flask + GitHub Action
  • Google Cloud Shell Environment + GCP App Engine
gcloud app --help

# Create main.go

gcloud app deploy
gcloud app browse
gcloud app logs tail -s default

Resources