Rev: 1.0.0
Using FastAPI
web framework with Python to build API services, this is more faster than Flask
.
-
Staging service
start.sh
will be run withansible-playbook
in CI pipeline job.$ vim hosts $ vim ./variables/common.yaml $ ansible-playbook -i hosts deploy-staging.yaml
-
Production service
start.sh
will be run with Dockerkubectl
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
一個喜歡用 Python 來做 Web 服務的人,享受著全新的網頁服務框架,一切都是那麼開始的。
-
服務部署在英業達公司內網,外部網路無法直接訪問,有需要可以通過
VPN
連線。 -
Production 環境
- FastAPI Home - http://web-fastapi.cloudnative.ies.inventec
-
Staging 環境
- FastAPI Home - http://10.99.104.251:8787/login
-
More API usage please refer to following url:
-
FastAPI Docs - http://web-fastapi.cloudnative.ies.inventec/docs
-
FastAPI Redoc - http://web-fastapi.cloudnative.ies.inventec/redoc
-
-
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]+$')
-
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
-
Tester
- Liu.AllenJH
-
Developer
- Liu.AllenJH
點我顯示/關閉更多驗證資訊。
- None.
- Latest script has been validated by Liu.AllenJH on K8S-Cluster at 2021-08-05.
- FastAPI - https://fastapi.tiangolo.com
- fastapi-mail - https://sabuhish.github.io/fastapi-mail
- fastapi-login - https://fastapi-login.readthedocs.io/reference