Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 81 additions & 1 deletion ansible/roles/dingo-command/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,36 @@ dingo_command_services:
tls_backend: "{{ dingo_command_enable_tls_backend }}"
backend_http_extra:
- "option httpchk GET /docs"

dingo_bear_services:
dingo-bear:
container_name: dingo-bear
group: dingo-bear
enabled: true
image: "{{ dingo_bear_image_full }}"
volumes: "{{ dingo_bear_default_volumes + dingo_bear_extra_volumes }}"
dimensions: "{{ dingo_bear_dimensions }}"
healthcheck: "{{ dingo_bear_healthcheck }}"
haproxy:
dingo-bear:
enabled: "{{ enable_dingo_bear }}"
mode: "http"
external: false
port: "{{ dingo_bear_port }}"
listen_port: "{{ dingo_bear_listen_port }}"
tls_backend: "{{ dingo_bear_enable_tls_backend }}"
backend_http_extra:
- "option httpchk GET /docs"
dingo_bear_external:
enabled: "{{ enable_dingo_bear }}"
mode: "http"
external: true
external_fqdn: "{{ dingo_bear_external_fqdn }}"
port: "{{ dingo_bear_port }}"
listen_port: "{{ dingo_bear_listen_port }}"
tls_backend: "{{ dingo_bear_enable_tls_backend }}"
backend_http_extra:
- "option httpchk GET /docs"

dingo_command_database_address: "{{ database_address | put_address_in_context('url') }}:{{ database_port }}"
dingo_command_tag: "{{ openstack_tag }}"
Expand Down Expand Up @@ -140,4 +170,54 @@ aliyun_clickhouse_host: "10.220.244.176"
aliyun_clickhouse_port: 8123
aliyun_clickhouse_user: "user01"
aliyun_clickhouse_password: "YourStrongPassword123!"
aliyun_clickhouse_database: "bsm_monitor"
aliyun_clickhouse_database: "bsm_monitor"

metric_write_dingo: true
metric_write_clickhouse: true
openstack_lb_method: "ROUND_ROBIN"
openstack_lb_provider: "amphora"

dingo_bear_tag: "{{ openstack_tag }}"
dingo_bear_image: "{{ docker_registry ~ '/' if docker_registry else '' }}{{ docker_namespace }}/dingo-bear"
dingo_bear_image_full: "{{ dingo_bear_image }}:{{ dingo_bear_tag }}"


dingo_bear_database_user: "{{ dingo_command_database_user }}"
dingo_bear_database_password: "{{ dingo_command_database_password }}"
dingo_bear_database_name: "dingo-bear"
dingo_bear_port: 38887
dingo_bear_frontend_port: 30000
dingo_bear_listen_port: "{{ dingo_bear_port }}"
dingo_bear_skyline_url: "http://{{ kolla_internal_vip_address }}:9999"
dingo_bear_database_address: "{{ database_address }}:{{ database_port }}"
dingo_bear_enable_tls_backend: "{{ kolla_enable_tls_backend }}"
dingo_bear_external_fqdn: "{{ dingo_command_external_fqdn }}"
dingo_bear_services:
dingo-bear:
container_name: dingo-bear
group: dingo-bear
enabled: true
image: "{{ dingo_bear_image_full }}"
volumes: "{{ dingo_bear_default_volumes + dingo_bear_extra_volumes }}"
dimensions: "{{ dingo_bear_dimensions }}"
healthcheck: "{{ dingo_bear_healthcheck }}"
haproxy:
dingo-bear:
enabled: "{{ enable_dingo_bear }}"
mode: "http"
external: false
port: "{{ dingo_bear_port }}"
listen_port: "{{ dingo_bear_listen_port }}"
tls_backend: "{{ dingo_bear_enable_tls_backend }}"
backend_http_extra:
- "option httpchk GET /docs"
dingo_bear_external:
enabled: "{{ enable_dingo_bear }}"
mode: "http"
external: true
external_fqdn: "{{ dingo_bear_external_fqdn }}"
port: "{{ dingo_bear_port }}"
listen_port: "{{ dingo_bear_listen_port }}"
tls_backend: "{{ dingo_bear_enable_tls_backend }}"
backend_http_extra:
- "option httpchk GET /docs"
1 change: 1 addition & 0 deletions ansible/roles/dingo-command/tasks/ceph.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,4 @@
-o name={{ dingo_command_ceph_client_name }},secretfile=/etc/ceph/ceph.client.{{ dingo_command_ceph_client_name }}.keyring,acl,noatime,_netdev,mds_namespace={{ dingo_command_ceph_mds_namespace }}
when: ceph_mount_status.stdout == ""
with_dict: "{{ dingo_command_services | select_services_enabled_and_mapped_to_host }}"
when: kolla_action != "upgrade"
145 changes: 145 additions & 0 deletions ansible/roles/dingo-command/tasks/deploy-bear.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
---

- name: Set dingo_bear fact
set_fact:
dingo_bear: "{{ dingo_bear_services['dingo-bear'] }}"

- name: Creating dingo-bear database
become: true
kolla_toolbox:
container_engine: "{{ kolla_container_engine }}"
module_name: mysql_db
module_args:
login_host: "{{ database_address }}"
login_port: "{{ database_port }}"
login_user: "{{ dingo_command_database_shard_root_user }}"
login_password: "{{ database_password }}"
name: "{{ dingo_bear_database_name }}"
run_once: True
delegate_to: "{{ groups['dingo-command'][0] }}"
when:
- not use_preconfigured_databases | bool
- dingo_bear.enabled | bool

- name: Creating dingo-bear database user and setting permissions
become: true
kolla_toolbox:
container_engine: "{{ kolla_container_engine }}"
module_name: mysql_user
module_args:
login_host: "{{ database_address }}"
login_port: "{{ database_port }}"
login_user: "{{ dingo_command_database_shard_root_user }}"
login_password: "{{ database_password }}"
name: "{{ dingo_bear_database_user }}"
password: "{{ dingo_bear_database_password }}"
host: "%"
priv: "{{ dingo_bear_database_name }}.*:ALL"
append_privs: "yes"
run_once: True
delegate_to: "{{ groups['dingo-command'][0] }}"
when:
- not use_preconfigured_databases | bool
- dingo_bear.enabled | bool

- name: Pull dingo-bear image
become: true
kolla_container:
action: "pull_image"
common_options: "{{ docker_common_options }}"
image: "{{ dingo_bear_image_full }}"
when:
- dingo_bear.enabled | bool

- name: Ensuring /var/log/dingo-bear directory exists
file:
path: "/var/log/kolla/dingo-bear"
state: "directory"
owner: "{{ config_owner_user }}"
group: "{{ config_owner_group }}"
mode: "0770"
become: true
when:
- dingo_bear.enabled | bool

- name: Ensuring /etc/kolla/dingo-bear directory exists
file:
path: "{{ node_config_directory }}/dingo-bear"
state: "directory"
owner: "{{ config_owner_user }}"
group: "{{ config_owner_group }}"
mode: "0770"
become: true
when:
- dingo_bear.enabled | bool


- name: Copying over dingo-bear.conf
template:
src: "{{ role_path }}/templates/dingo-bear/dingo-bear.conf.j2"
dest: "{{ node_config_directory }}/dingo-bear/dingo-bear.conf"
mode: "0660"
become: true
when:
- dingo_bear.enabled | bool

- name: Copying over supervisord.conf
template:
src: "{{ role_path }}/templates/dingo-bear/supervisord.conf"
dest: "{{ node_config_directory }}/dingo-bear/supervisord.conf"
mode: "0660"
become: true
when:
- dingo_bear.enabled | bool


- name: Copying over gunicorn.py
template:
src: "{{ role_path }}/templates/dingo-bear/gunicorn.py"
dest: "{{ node_config_directory }}/dingo-bear/gunicorn.py"
mode: "0660"
become: true
when:
- dingo_bear.enabled | bool

- name: Copying over nginx.conf
template:
src: "{{ role_path }}/templates/dingo-bear/nginx.conf.j2"
dest: "{{ node_config_directory }}/dingo-bear/nginx.conf"
mode: "0660"
become: true
when:
- dingo_bear.enabled | bool


- name: Copy deploy.sh to target node
template:
src: "{{ role_path }}/templates/dingo-bear/deploy.sh.j2"
dest: "/tmp/deploy-bear.sh"
mode: "0755"
become: true
when:
- dingo_bear.enabled | bool

- name: Execute deploy-bear.sh
command: >
bash /tmp/deploy-bear.sh
"{{ dingo_bear_image_full }}"
become: true
register: deploy_bear_result
when:
- dingo_bear.enabled | bool

- name: Show deploy-bear.sh output
debug:
msg: "{{ deploy_bear_result.stdout_lines }}"
when:
- dingo_bear.enabled | bool








7 changes: 7 additions & 0 deletions ansible/roles/dingo-command/tasks/loadbalancer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,10 @@
vars:
project_services: "{{ dingo_command_services }}"
tags: always

- name: "Configure loadbalancer for dingo-bear"
import_role:
name: loadbalancer-config
vars:
project_services: dingo-bear
tags: always
4 changes: 4 additions & 0 deletions ansible/roles/dingo-command/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
---
- include_tasks: "{{ kolla_action }}.yml"
when: "'dingo-bear' not in ansible_run_tags"

- include_tasks: deploy-bear.yml
when: "'dingo-bear' in ansible_run_tags"
56 changes: 56 additions & 0 deletions ansible/roles/dingo-command/templates/dingo-bear/deploy.sh.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash
set -e
set -o pipefail

image_full_url=${1:-"docker.io/dongshany"}
node_port=38887
frontend_port=30000
module_name=dingo-bear
skyline_url="{{ dingo_bear_skyline_url }}"

echo "开始检查并移除旧的容器"
if podman ps -f "name=${module_name}$" -f "status=running" -q | grep -q .; then
printf "停止容器: "
podman stop "${module_name}"
fi

if podman ps -a -f "name=${module_name}$" -q | grep -q .; then
printf "删除容器: "
podman rm "${module_name}"
fi

# 确保必要目录存在
mkdir -p /etc/kolla/dingo-bear /var/log/kolla/dingo-bear /var/lib/dingo-command

# 构建运行命令(使用数组避免 eval)
run_args=(
run -d
--privileged
-p "${node_port}:${node_port}"
-p "${frontend_port}:${frontend_port}"
-e "SKYLINE_URL=${skyline_url}"
-v /etc/kolla/dingo-bear/:/etc/dingo-bear/:ro
-v /etc/localtime:/etc/localtime:ro
-v /var/log/kolla/dingo-bear/:/var/log/dingo-bear/
--mount type=bind,source=/run/netns,target=/run/netns,bind-propagation=shared
-v /var/lib/dingo-command/:/var/lib/dingo-command/
-e TZ=Asia/Shanghai
--health-cmd 'curl -sf http://localhost:38887/v1 || exit 1'
--health-interval=30s
--health-timeout=10s
--health-retries=3
--health-start-period=30s
--name "${module_name}"
"${image_full_url}"
)

printf "要执行的命令为:\npodman %s\n" "${run_args[*]}"
container_id=$(podman "${run_args[@]}")

inspect_format='{{ '{{' }}.State.Running{{ '}}' }}'
if [[ "$(podman inspect -f "$inspect_format" "${container_id}")" == "true" ]]; then
printf "\033[32m%s 容器启动成功, 容器id: %s\033[0m\n" "${module_name}" "${container_id:0:12}"
else
printf "\033[31m%s 容器启动失败, 容器id: %s\033[0m\n" "${module_name}" "${container_id:0:12}"
exit 1
fi
Loading