refactor: move to docker swarm
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
f3c980f8f7
commit
0daad7a229
@ -1 +1,9 @@
|
|||||||
.venv
|
.venv
|
||||||
|
venv/
|
||||||
|
local*
|
||||||
|
*.env
|
||||||
|
*.venv
|
||||||
|
env/
|
||||||
|
ENV/
|
||||||
|
env.bak/
|
||||||
|
venv.bak/
|
34
.drone.yml
34
.drone.yml
@ -22,37 +22,23 @@ clone:
|
|||||||
disable: true
|
disable: true
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: deploy-k8s-master
|
- name: build-push-image-and-deploy
|
||||||
image: appleboy/drone-ssh
|
image: appleboy/drone-ssh
|
||||||
settings:
|
settings:
|
||||||
host:
|
host:
|
||||||
from_secret: k8s_master
|
from_secret: diyue_host
|
||||||
username: ubuntu
|
username: ubuntu
|
||||||
key:
|
key:
|
||||||
from_secret: k8s_key
|
from_secret: diyue_key
|
||||||
port: 22
|
port: 22
|
||||||
script_stop: true
|
script_stop: true
|
||||||
script:
|
script:
|
||||||
- cd /var/www/pzx-web-api
|
- cd /var/ddk/pzx-web-api
|
||||||
- sudo git fetch
|
- sudo git fetch
|
||||||
- sudo git reset --hard ${DRONE_COMMIT}
|
- sudo git reset --hard ${DRONE_COMMIT}
|
||||||
- sudo docker-compose down
|
- docker-compose -f docker-compose-build.yml build
|
||||||
- sudo docker-compose up -d --build --force-recreate
|
- source .apiflask.env
|
||||||
- sudo docker image prune -f
|
- echo "$DOCKER_PASSWORD" | docker login $DOCKER_REGISTRY -u $DOCKER_USERNAME --password-stdin
|
||||||
- name: deploy-k8s-worker
|
- docker push $DOCKER_REGISTRY/bryant/ddk/pzx-web-api:latest
|
||||||
image: appleboy/drone-ssh
|
- docker stack deploy -c docker-compose-run.yml ddk
|
||||||
settings:
|
- docker image prune -f
|
||||||
host:
|
|
||||||
from_secret: k8s_worker
|
|
||||||
username: ubuntu
|
|
||||||
key:
|
|
||||||
from_secret: k8s_key
|
|
||||||
port: 22
|
|
||||||
script_stop: true
|
|
||||||
script:
|
|
||||||
- cd /var/www/pzx-web-api
|
|
||||||
- sudo git fetch
|
|
||||||
- sudo git reset --hard ${DRONE_COMMIT}
|
|
||||||
- sudo docker-compose down
|
|
||||||
- sudo docker-compose up -d --build --force-recreate
|
|
||||||
- sudo docker image prune -f
|
|
14
Dockerfile
14
Dockerfile
@ -1,6 +1,10 @@
|
|||||||
FROM python:3.11
|
FROM python:3.11-slim
|
||||||
RUN python3 -m pip uninstall -y chassis
|
|
||||||
# 拷贝依赖
|
# 拷贝项目文件
|
||||||
COPY requirements.txt .
|
COPY . /app
|
||||||
|
# 设置工作路径
|
||||||
|
WORKDIR /app
|
||||||
# 安装依赖
|
# 安装依赖
|
||||||
RUN python3 -m pip install -i https://mirrors.cloud.tencent.com/pypi/simple --trusted-host=mirrors.cloud.tencent.com -r requirements.txt
|
RUN python3 -m pip install -i https://mirrors.aliyun.com/pypi/simple --trusted-host=mirrors.aliyun.com -r requirements.txt
|
||||||
|
# 启动时运行命令
|
||||||
|
CMD ["sh", "docker-deploy.sh"]
|
@ -1,14 +1,12 @@
|
|||||||
import os
|
|
||||||
|
|
||||||
# from dotenv import load_dotenv
|
# from dotenv import load_dotenv
|
||||||
from apiflask import APIFlask
|
from apiflask import APIFlask
|
||||||
from chassis.flask_nameko import FlaskPooledClusterRpcProxy
|
from pychassislib.namekoproxy_pool import FlaskPooledServiceRpcProxy
|
||||||
|
|
||||||
from app.config.config import Config
|
from app.config.config import Config
|
||||||
from app.util.common import basedir
|
from app.util.common import basedir
|
||||||
|
|
||||||
|
|
||||||
rpc = FlaskPooledClusterRpcProxy()
|
rpc = FlaskPooledServiceRpcProxy()
|
||||||
|
|
||||||
|
|
||||||
def register_blueprints(apiflask_app):
|
def register_blueprints(apiflask_app):
|
||||||
@ -34,6 +32,7 @@ def load_rpc_client(apiflask_app):
|
|||||||
rpc.init_app(apiflask_app, extra_config={
|
rpc.init_app(apiflask_app, extra_config={
|
||||||
'INITIAL_CONNECTIONS': 2,
|
'INITIAL_CONNECTIONS': 2,
|
||||||
'MAX_CONNECTIONS': 10,
|
'MAX_CONNECTIONS': 10,
|
||||||
|
'POOL_RECYCLE': 360 # 6 分钟后过期所有已有链接
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from chassis.config import Config as _Config
|
from pychassislib import Config as _Config
|
||||||
|
|
||||||
|
|
||||||
class Config(_Config):
|
class Config(_Config):
|
||||||
|
8
docker-compose-build.yml
Normal file
8
docker-compose-build.yml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
version: "3.8"
|
||||||
|
|
||||||
|
services:
|
||||||
|
pzx-web-api:
|
||||||
|
image: gitea.bearcatlog.com/bryant/ddk/pzx-web-api:latest
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: ./Dockerfile
|
32
docker-compose-run.yml
Normal file
32
docker-compose-run.yml
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
version: "3.8"
|
||||||
|
|
||||||
|
services:
|
||||||
|
pzx-web-api:
|
||||||
|
image: gitea.bearcatlog.com/bryant/ddk/pzx-web-api:latest
|
||||||
|
env_file:
|
||||||
|
- .apiflaskenv
|
||||||
|
- .apiflask.env
|
||||||
|
ports:
|
||||||
|
- target: 5000
|
||||||
|
published: 7000
|
||||||
|
mode: ingress
|
||||||
|
deploy:
|
||||||
|
mode: replicated
|
||||||
|
replicas: 2
|
||||||
|
update_config:
|
||||||
|
parallelism: 1
|
||||||
|
failure_action: rollback
|
||||||
|
restart_policy:
|
||||||
|
condition: on-failure
|
||||||
|
delay: 5s
|
||||||
|
max_attempts: 3
|
||||||
|
window: 120s
|
||||||
|
placement:
|
||||||
|
constraints:
|
||||||
|
- 'node.role == worker'
|
||||||
|
networks:
|
||||||
|
- pzx-web-api-network
|
||||||
|
|
||||||
|
networks:
|
||||||
|
pzx-web-api-network:
|
||||||
|
driver: overlay
|
@ -1,65 +0,0 @@
|
|||||||
version: "3"
|
|
||||||
|
|
||||||
services:
|
|
||||||
pzx-web-api-1:
|
|
||||||
build:
|
|
||||||
context: .
|
|
||||||
dockerfile: ./Dockerfile
|
|
||||||
container_name: pzx-web-api-1
|
|
||||||
hostname: pzx-web-api-1
|
|
||||||
ports:
|
|
||||||
- "5010:5000"
|
|
||||||
volumes:
|
|
||||||
- .:/app
|
|
||||||
environment:
|
|
||||||
TZ: "Asia/Shanghai"
|
|
||||||
LOG_LEVEL: "DEBUG"
|
|
||||||
env_file:
|
|
||||||
- .apiflaskenv
|
|
||||||
- .apiflask.env
|
|
||||||
working_dir: /app
|
|
||||||
tty: true
|
|
||||||
restart: always
|
|
||||||
command: ["sh", "docker-deploy.sh"]
|
|
||||||
pzx-web-api-2:
|
|
||||||
build:
|
|
||||||
context: .
|
|
||||||
dockerfile: ./Dockerfile
|
|
||||||
container_name: pzx-web-api-2
|
|
||||||
hostname: pzx-web-api-2
|
|
||||||
ports:
|
|
||||||
- "5020:5000"
|
|
||||||
volumes:
|
|
||||||
- .:/app
|
|
||||||
environment:
|
|
||||||
TZ: "Asia/Shanghai"
|
|
||||||
LOG_LEVEL: "DEBUG"
|
|
||||||
env_file:
|
|
||||||
- .apiflaskenv
|
|
||||||
- .apiflask.env
|
|
||||||
working_dir: /app
|
|
||||||
tty: true
|
|
||||||
restart: always
|
|
||||||
command: [ "sh", "docker-deploy.sh" ]
|
|
||||||
pzx-web-api-3:
|
|
||||||
build:
|
|
||||||
context: .
|
|
||||||
dockerfile: ./Dockerfile
|
|
||||||
container_name: pzx-web-api-3
|
|
||||||
hostname: pzx-web-api-3
|
|
||||||
ports:
|
|
||||||
- "5030:5000"
|
|
||||||
volumes:
|
|
||||||
- .:/app
|
|
||||||
environment:
|
|
||||||
TZ: "Asia/Shanghai"
|
|
||||||
LOG_LEVEL: "DEBUG"
|
|
||||||
env_file:
|
|
||||||
- .apiflaskenv
|
|
||||||
- .apiflask.env
|
|
||||||
working_dir: /app
|
|
||||||
tty: true
|
|
||||||
restart: always
|
|
||||||
command: [ "sh", "docker-deploy.sh" ]
|
|
||||||
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
|||||||
git+https://gitea.bearcatlog.com/BryantStudio/chassis.git@main#egg=chassis[apiflask,nameko]
|
pychassislib[nameko,apiflask,schema]
|
||||||
psutil
|
psutil
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user