Skip to content

The side project of web service with Python FastAPI.

Notifications You must be signed in to change notification settings

AllennLiu/Web-FastAPI

Repository files navigation

Web-FastAPI

Version

Rev: 1.0.0

Release Badge Package Badge


Requirement Version

Python Badge Kubernetes Badge


Status

Pipeline Status Coverage Badge


Description

Using FastAPI web framework with Python to build API services, this is more faster than Flask.


Script Process

  1. Staging service start.sh will be run with ansible-playbook in CI pipeline job.

    $ vim hosts
    $ vim ./variables/common.yaml
    $ ansible-playbook -i hosts deploy-staging.yaml
  2. Production service start.sh will be run with Docker kubectl tool image in CI pipeline job.

    $ docker run --rm --name tool-kubectl-deploymen \
        ghcr.io/allennliu/tool-kubectl-deployment:1.0.4 \
        bash start.sh --k8s-run -v 1.0.0 -p Web-FastAPI -n web-fastapi \
                      -i ghcr.io/allennliu/web-fastapi \
                      -MP 8787 -M1 /mnt/storage -M2 /mnt/tmp

When to use ?

一個喜歡用 Python 來做 Web 服務的人,享受著全新的網頁服務框架,一切都是那麼開始的。


Usage


Reports

  • Run as below command in production for container's log:

    $ docker logs --tail 50 --follow --timestamps web-fastapi
  • View logs via tool kubectl:

    $ kubectl logs -n kube-ops $(kubectl get pods -n kube-ops | awk '{print $2}' | grep -E '^web-fastapi\-[a-zA-Z0-9]+\-[a-zA-Z0-9]+$')

Attention

  • Build image.

    $ docker build --no-cache -t ghcr.io/allennliu/web-fastapi:${VERSION} .
  • Login Github registry and Push image.

    $ echo $ACCESS_TOKEN | docker login ghcr.io -u AllennLiu --password-stdin
    $ docker push ghcr.io/allennliu/web-fastapi:${VERSION}
  • Run image on Docker container.

    docker run -tid \
           --add-host ipt-gitlab.ies.inventec:10.99.104.242 \
           --add-host mailrelay-b.ies.inventec:10.99.2.61 \
           -p 8787:8000 \
           -p 8788:22 \
           --volume /etc/localtime:/etc/localtime:ro \
           --privileged=true \
           --restart=always \
           --name web-fastapi \
           ghcr.io/allennliu/web-fastapi:${VERSION} \
           uvicorn app.main:app --host 0.0.0.0 --port 8000
  • Create Docker Registry Secret before deploy pod if it not exists in Kubernetes.

    $ kubectl create secret docker-registry github-registry \
              --docker-server=ghcr.io \
              --docker-username=AllennLiu \
              --docker-password=$GITHUB_ACCESS_TOKEN \
              --docker-email=seven6306@icloud.com \
              -n kube-ops
  • Run web service on Kubernetes cluster.

    $ kubectl apply -f deployments/ --record
  • Run cronjobs on Kubernetes cluster, currently no any cronjobs in project.

    $ kubectl apply -f crond/cronjobs.yml

Associates

  • Tester

    • Liu.AllenJH
  • Developer

    • Liu.AllenJH

Validation

點我顯示/關閉更多驗證資訊。
  • None.
  • Latest script has been validated by Liu.AllenJH on K8S-Cluster at 2021-08-05.

Reference