You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.2 KiB

kind: pipeline
type: docker
name: build-and-run-python
trigger:
branch:
include:
- master
event:
include:
- push
- custom
- merge_request
steps:
- name: build python image
image: docker
volumes:
- name: dockersock
path: /var/run/docker.sock
commands:
# 构建镜像
- docker build -t alert-python:latest -f Dockerfile .
- name: run python container
image: docker
volumes:
- name: dockersock
path: /var/run/docker.sock
commands:
- docker stop alert-python || true
- docker rm alert-python || true
# 确保宿主机存在可挂载的配置目录,并同步当前配置
- docker run --rm -v /opt/alert/model-lab:/opt/alert/model-lab -v $(pwd):/src alpine sh -c "mkdir -p /opt/alert/model-lab && cp /src/config.py /opt/alert/model-lab/config.py"
# 启动 Python 服务容器,假设服务监听 8082 端口
- docker run -d --restart always --name alert-python --network alert-net -p 8082:8082 -v /opt/alert/model-lab:/opt/alert/model-lab -v /opt/alert/model-lab/config.py:/app/config.py alert-python:latest
volumes:
- name: dockersock
host:
path: /var/run/docker.sock