Skip to content

Commit

Permalink
feat: 更新py311构建Dockerfile 替换proxy使用的py36到py311(closed #2160)
Browse files Browse the repository at this point in the history
  • Loading branch information
chalice-1831 committed Dec 24, 2024
1 parent 201afa2 commit bdc78f4
Show file tree
Hide file tree
Showing 24 changed files with 136 additions and 125 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- "CLASSIC"
- "SHANGMI"
PYTHON_VERSION:
- "3.6"
- "3.11"
name: "[CodeCov][${{ matrix.BKPAAS_BK_CRYPTO_TYPE }}] with Python ${{ matrix.PYTHON_VERSION }}"
env:
DJANGO_SETTINGS_MODULE: "settings"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.6
- name: Set up Python 3.11
uses: actions/setup-python@v2
with:
python-version: 3.6
python-version: 3.11
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/agent/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def collect_log(bk_host_id, node_id=None):
else:
cmd, script_type = ("cat", "sh")
cmd_str = f"{cmd} {dest_dir}nm.setup_agent.{script_type}.{node_id}.debug"
script = """#!/opt/py36/bin/python
script = """#!/opt/py311/bin/python
# -*- encoding:utf-8 -*-
import sys
import argparse
Expand Down
2 changes: 1 addition & 1 deletion apps/node_man/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,7 @@ class PolicyRollBackType:
]

TOOLS_TO_PUSH_TO_PROXY: List[Dict[str, Union[List[str], Any]]] = [
{"files": ["py36-x86_64.tgz", "py36-aarch64.tgz"], "name": _("检测 BT 分发策略(下发Py36包)")},
{"files": ["py311-x86_64.tgz", "py311-aarch64.tgz"], "name": _("检测 BT 分发策略(下发Py311包)")},
{
"files": [
"ntrights.exe",
Expand Down
2 changes: 1 addition & 1 deletion apps/node_man/periodic_tasks/update_proxy_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def correct_file_action(download_path: str, hosts: List[Dict[str, Union[str, int
return True

files = [file for file in local_file__md5_map.keys()]
script = """#!/opt/py36/bin/python
script = """#!/opt/py311/bin/python
# -*- encoding:utf-8 -*-
import os
import json
Expand Down
3 changes: 2 additions & 1 deletion docs/download_dir_intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@
# 升级 Agent 二进制脚本(1.0 / 2.0 通用)
├── upgrade_agent.sh.tpl
# Proxy 依赖包,用于 Proxy Python、Nginx 环境搭建
├── py36.tgz
├── py311-x86_64.tgz
├── py311-aarch64.tgz
├── nginx-portable.tgz
├── start_nginx.sh.tpl
# Windows Agent 安装依赖
Expand Down
20 changes: 10 additions & 10 deletions docs/install/dev_deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,28 @@
- QQ交流群:495299374

2)如果你希望使用蓝鲸所有开源产品,进行定制开发,你可以部署开源的蓝鲸智云PaaS平台和蓝鲸智云配置平台。
- [蓝鲸智云PaaS平台](https://github.com/Tencent/bk-PaaS)
- [蓝鲸智云配置平台](https://github.com/Tencent/bk-cmdb)
- [蓝鲸智云PaaS平台](https://github.com/Tencent/bk-PaaS)
- [蓝鲸智云配置平台](https://github.com/Tencent/bk-cmdb)

部署方法请参考各个开源产品的相关文档,在蓝鲸智云PaaS平台部署完成后,你还需要上传部署蓝鲸节点管理SaaS并开通应用免登录态验证白名单。
你可以[点击这里](https://github.com/TencentBlueKing/bk-nodeman/releases)下载蓝鲸节点管理Release版本(选择.tar.gz格式压缩包),然后前往蓝鲸PaaS平台的"开发者中心"->"S-mart应用"上传部署新应用。
你可以参考蓝鲸PaaS平台的"开发者中心"->"API网关"->"使用指南"->"API调用说明"页面中"用户认证"文档,添加默认蓝鲸节点管理APP_ID即bk_nodeman到应用免登录态验证白名单。


## 准备本地 rabbitmq 资源
## 准备本地 rabbitmq 资源
在本地安装 rabbitmq,并启动 rabbitmq-server,服务监听的端口保持默认(5672)。


## 准备本地 redis 资源
## 准备本地 redis 资源
在本地安装 redis,并启动 redis-server,服务监听的端口保持默认(6379)。


## 准备本地 mysql
## 准备本地 mysql
在本地安装 mysql,并启动 mysql-server,服务监听的端口保持默认(3306)。


## 安装 python 和依赖库
在本地安装 python3.6.7 和 pip,通过 git 拉取源代码到工程目录后,并进入目录下运行 pip 命令安装 python 包。
在本地安装 python3.11.10 和 pip,通过 git 拉取源代码到工程目录后,并进入目录下运行 pip 命令安装 python 包。
```bash
pip install -r requirements.txt
```
Expand Down Expand Up @@ -82,7 +82,7 @@ DATABASES = {
```


## 创建并初始化数据库
## 创建并初始化数据库

1) 在 mysql 中创建名为 bk_nodeman 的数据库
```sql
Expand All @@ -105,8 +105,8 @@ npm run build
```


## 配置本地 hosts
windows: 在 C:\Windows\System32\drivers\etc\hosts 文件中添加“127.0.0.1 dev.{BK_PAAS_HOST}”。
## 配置本地 hosts
windows: 在 C:\Windows\System32\drivers\etc\hosts 文件中添加“127.0.0.1 dev.{BK_PAAS_HOST}”。
mac: 执行 “sudo vim /etc/hosts”,添加“127.0.0.1 dev.{BK_PAAS_HOST}”。


Expand All @@ -117,5 +117,5 @@ python manage.py runserver 8000
```


## 访问页面
## 访问页面
使用浏览器开发 http://dev.{BK_PAAS_HOST}:8000/ 访问应用。
19 changes: 10 additions & 9 deletions docs/install_channel.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
echo ${nginx_dns_list[@]}
```
* 根据不同的网络场景,酌情选择以下对应的配置模板
* 请注意: `nginx` 对于 ``ipv4````ipv6`` 的端口监听配置是不同的,配置项 `listen` 需要根据实际情况进行配置
* 请注意: `nginx` 对于 ``ipv4````ipv6`` 的上游地址配置方式是不同的,配置项 `upstream` 中的上游地址 `proxy` 需要根据上游实际地址进行配置,
如果上游地址为``ipv6``主机时,以下模板二中的``upstream proxy`` 配置项请调整为 `[::ip]:17981;`,其中`::ip` 代表实际的 `ipv6` 地址
* 请注意: `nginx` 对于 ``ipv4````ipv6`` 的端口监听配置是不同的,配置项 `listen` 需要根据实际情况进行配置
* 请注意: `nginx` 对于 ``ipv4````ipv6`` 的上游地址配置方式是不同的,配置项 `upstream` 中的上游地址 `proxy` 需要根据上游实际地址进行配置,
如果上游地址为``ipv6``主机时,以下模板二中的``upstream proxy`` 配置项请调整为 `[::ip]:17981;`,其中`::ip` 代表实际的 `ipv6` 地址
* 模板一: 常规通道主机`nginx`配置模板
```nginx
events {
Expand Down Expand Up @@ -98,8 +98,8 @@
}
}
upstream proxy {
server 10.0.0.1:17981;
server 10.0.0.2:17981;
server 10.0.0.1:17981;
server 10.0.0.2:17981;
}
server {
listen 17981;
Expand Down Expand Up @@ -147,7 +147,8 @@
├── libcurl-x64.dll
├── nginx-portable.tgz
├── ntrights.exe
├── py36.tgz
├── py311-x86_64.tgz
├── py311-aarch64.tgz
├── setup_agent.bat
├── setup_agent.ksh
├── setup_agent.sh
Expand All @@ -158,8 +159,8 @@
├── tcping.exe
└── unixdate.exe
```
7. 解压下载目录中的 ``py36.tgz```/opt` 目录

7. 解压下载目录中的 ``py311-$(arch).tgz```/opt` 目录
```bash
tar xvf /data/bkee/public/bknodeman/download/py36.tgz -C /opt
tar xvf /data/bkee/public/bknodeman/download/py311-$(arch).tgz -C /opt
```
13 changes: 7 additions & 6 deletions frontend/static/doc/install_channel_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ If the upstream address is an ``ipv6`` host, please adjust the ``upstream proxy`
}
}
upstream proxy {
server 10.0.0.1:17981;
server 10.0.0.2:17981;
server 10.0.0.1:17981;
server 10.0.0.2:17981;
}
server {
listen 17981;
Expand Down Expand Up @@ -146,7 +146,8 @@ If the upstream address is an ``ipv6`` host, please adjust the ``upstream proxy`
├── libcurl-x64.dll
├── nginx-portable.tgz
├── ntrights.exe
├── py36.tgz
├── py311-x86_64.tgz
├── py311-aarch64.tgz
├── setup_agent.bat
├── setup_agent.ksh
├── setup_agent.sh
Expand All @@ -157,8 +158,8 @@ If the upstream address is an ``ipv6`` host, please adjust the ``upstream proxy`
├── tcping.exe
└── unixdate.exe
```
7. Unzip ``py36.tgz`` in the download directory to the `/opt` directory

7. Unzip ``py311-$(arch).tgz`` in the download directory to the `/opt` directory
```bash
tar xvf /data/bkee/public/bknodeman/download/py36.tgz -C /opt
tar xvf /data/bkee/public/bknodeman/download/py311-$(arch).tgz -C /opt
```
19 changes: 10 additions & 9 deletions frontend/static/doc/install_channel_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
echo ${nginx_dns_list[@]}
```
* 根据不同的网络场景,酌情选择以下对应的配置模板
* 请注意: `nginx` 对于 ``ipv4````ipv6`` 的端口监听配置是不同的,配置项 `listen` 需要根据实际情况进行配置
* 请注意: `nginx` 对于 ``ipv4````ipv6`` 的上游地址配置方式是不同的,配置项 `upstream` 中的上游地址 `proxy` 需要根据上游实际地址进行配置,
如果上游地址为``ipv6``主机时,以下模板二中的``upstream proxy`` 配置项请调整为 `[::ip]:17981;`,其中`::ip` 代表实际的 `ipv6` 地址
* 请注意: `nginx` 对于 ``ipv4````ipv6`` 的端口监听配置是不同的,配置项 `listen` 需要根据实际情况进行配置
* 请注意: `nginx` 对于 ``ipv4````ipv6`` 的上游地址配置方式是不同的,配置项 `upstream` 中的上游地址 `proxy` 需要根据上游实际地址进行配置,
如果上游地址为``ipv6``主机时,以下模板二中的``upstream proxy`` 配置项请调整为 `[::ip]:17981;`,其中`::ip` 代表实际的 `ipv6` 地址
* 模板一: 常规通道主机`nginx`配置模板
```nginx
events {
Expand Down Expand Up @@ -98,8 +98,8 @@
}
}
upstream proxy {
server 10.0.0.1:17981;
server 10.0.0.2:17981;
server 10.0.0.1:17981;
server 10.0.0.2:17981;
}
server {
listen 17981;
Expand Down Expand Up @@ -147,7 +147,8 @@
├── libcurl-x64.dll
├── nginx-portable.tgz
├── ntrights.exe
├── py36.tgz
├── py311-x86_64.tgz
├── py311-aarch64.tgz
├── setup_agent.bat
├── setup_agent.ksh
├── setup_agent.sh
Expand All @@ -158,8 +159,8 @@
├── tcping.exe
└── unixdate.exe
```
7. 解压下载目录中的 ``py36.tgz```/opt` 目录

7. 解压下载目录中的 ``py311-$(arch).tgz```/opt` 目录
```bash
tar xvf /data/bkee/public/bknodeman/download/py36.tgz -C /opt
tar xvf /data/bkee/public/bknodeman/download/py311-$(arch).tgz -C /opt
```
4 changes: 2 additions & 2 deletions locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -3416,8 +3416,8 @@ msgid "IPv6"
msgstr "IPv6"

#: apps/node_man/constants.py:1026
msgid "检测 BT 分发策略(下发Py36包)"
msgstr "Detect BT distribution strategy (distribute Py36 package)"
msgid "检测 BT 分发策略(下发Py311包)"
msgstr "Detect BT distribution strategy (distribute Py311 package)"

#: apps/node_man/constants.py:1040
msgid "下发安装工具"
Expand Down
2 changes: 1 addition & 1 deletion pack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ cat > ${CODE_DIST_DIR}/projects.yaml << EOF
project_dir: bknodeman/nodeman
alias: nodeman
version_type: ee
language: python/3.6
language: python/3.11
version: ${RELEASE_VERSION}
EOF

Expand Down
2 changes: 1 addition & 1 deletion runtime.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
python-3.6.6
python-3.11.10
Binary file not shown.
Binary file added script_tools/py311-x86_64.tgz
Binary file not shown.
Binary file removed script_tools/py36-aarch64.tgz
Binary file not shown.
2 changes: 1 addition & 1 deletion script_tools/setup_pagent.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/opt/py36/bin/python
#!/opt/py311/bin/python
# -*- encoding:utf-8 -*-
# vim:ft=python sts=4 sw=4 expandtab nu

Expand Down
10 changes: 5 additions & 5 deletions script_tools/setup_proxy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ setup_proxy () {
fi
done

# setup_py36
# setup_py311

# create dir
mkdir -p "$GSE_AGENT_RUN_DIR" "$GSE_AGENT_DATA_DIR" "$GSE_AGENT_LOG_DIR"
Expand All @@ -547,10 +547,10 @@ setup_proxy () {
log setup_proxy DONE "gse proxy setup successfully"
}

setup_py36 () {
setup_py311 () {
(
# 默认带好requirements, 直接解压即可, 固定目录/opt/py36/bin/python。不需要走pip install
cd /opt && tar xf "$TMP_DIR/py36.tgz"
# 默认带好requirements, 直接解压即可, 固定目录/opt/py311/bin/python。不需要走pip install
cd /opt && tar xf "$TMP_DIR/py311-$(arch).tgz"
)
}

Expand All @@ -560,7 +560,7 @@ download_pkg () {
log download_pkg START "download gse agent package from $DOWNLOAD_URL/$PKG_NAME)."
cd "$TMP_DIR" && rm -f "$PKG_NAME" {agent,btsvr,transit,opts,data,dataflow}.conf."$LAN_ETH_IP"

# 安装Proxy,需要下载py36.tgz
# 安装Proxy,需要下载py311-$(arch).tgz
# 该包中包含impackt,ssh2-python, proxy.py 等安装p-agent所需的模块
for f in $PKG_NAME; do
http_status=$(http_proxy=$HTTP_PROXY https_proxy=$HTTPS_PROXY curl -o "$TMP_DIR/$f" \
Expand Down
4 changes: 2 additions & 2 deletions script_tools/start_nginx.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ get_cpu_arch "uname -p" || get_cpu_arch "uname -m" || fail get_cpu_arch "Failed

/opt/nginx-portable/nginx-portable stop || :;
rm -rf /opt/nginx-portable/;
rm -rf /opt/py36/;
rm -rf /opt/py311/;

tar xvf %(nginx_path)s/py36-${CPU_ARCH}.tgz -C /opt;
tar xvf %(nginx_path)s/py311-${CPU_ARCH}.tgz -C /opt;
tar xvf %(nginx_path)s/nginx-portable-${CPU_ARCH}.tgz -C /opt;

timeout 120 chmod -R 755 %(nginx_path)s || echo "chmod directory %(nginx_path)s failed"
Expand Down
2 changes: 1 addition & 1 deletion scripts/workflows/prepare_services.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if [ "$CREATE_PYTHON_VENV" ]; then
pip install virtualenv
VENV_DIR="${APP_CODE}_venv"
virtualenv "$VENV_DIR"
virtualenv -p /usr/local/bin/python3.6 "$VENV_DIR"
virtualenv -p /usr/local/bin/python3.11 "$VENV_DIR"
# 激活Python虚拟环境
source "${VENV_DIR}/bin/activate"
fi
Expand Down
58 changes: 58 additions & 0 deletions support-files/images/python/py311/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
FROM centos:7

ARG ROOT_PATH=/root/python
ARG OPENSSL_VERSION=1.1.1v
ARG PYTHON_VERSION=3.11.10
ARG PYTHON_DIR=/opt/py311
ARG PKG_PATH=/tmp/py311.tgz

RUN mkdir -p ${ROOT_PATH} ${PYTHON_DIR}
WORKDIR ${ROOT_PATH}

RUN sed -e 's|^mirrorlist=|#mirrorlist=|g' \
-e 's|^#baseurl=http://mirror.centos.org|baseurl=https://mirrors.cloud.tencent.com|g' \
-i.bak \
/etc/yum.repos.d/CentOS-*.repo && yum makecache

RUN yum install -y gcc automake autoconf libtool make glibc-static centos-release-scl

RUN sed -e 's|^mirrorlist=|#mirrorlist=|g' \
-e 's|^#baseurl=http://mirror.centos.org|baseurl=https://mirrors.cloud.tencent.com|g' \
-i.bak \
/etc/yum.repos.d/CentOS-SCLo-scl-rh.repo && sed -e 's|^mirrorlist=|#mirrorlist=|g' \
-e 's|^# baseurl=http://mirror.centos.org|baseurl=https://mirrors.cloud.tencent.com|g' \
-i.bak \
/etc/yum.repos.d/CentOS-SCLo-scl.repo && yum makecache

RUN yum install -y devtoolset-7 wget perl perl-devel zlib-devel bzip2-devel readline-devel sqlite-devel snappy-devel xz-devel libffi-devel ncurses-devel gdbm-devel tk-devel xz-devel

RUN echo "source /opt/rh/devtoolset-7/enable" >> /etc/bashrc && source /opt/rh/devtoolset-7/enable

RUN wget --no-check-certificate https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz

RUN wget --no-check-certificate https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz

RUN tar -zxvf openssl-${OPENSSL_VERSION}.tar.gz

RUN cd openssl-${OPENSSL_VERSION} && ./config -fPIC no-shared --prefix=/usr/local/ssl --openssldir=/usr/local/ssl

RUN cd openssl-${OPENSSL_VERSION} && make -j4 && make install

RUN tar xvf Python-${PYTHON_VERSION}.tgz
RUN cd Python-${PYTHON_VERSION} && printf 'SSL=/usr/local/ssl\n_ssl _ssl.c \\\n -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \\\n -L$(SSL)/lib -l:libssl.a -l:libcrypto.a\n' > Modules/Setup.local

RUN cd Python-${PYTHON_VERSION} && ./configure --prefix=${PYTHON_DIR} --disable-shared --enable-optimizations --enable-option-checking=fatal
RUN cd Python-${PYTHON_VERSION} && make build_all -j4 && make install
RUN mkdir /root/.pip/ && touch /root/.pip/pip.conf
RUN sed '4d' /root/.pip/pip.conf > /root/.pip/pip.conf

COPY requirements.txt ${ROOT_PATH}/requirements.txt

RUN ${PYTHON_DIR}/bin/pip3 install --upgrade pip==24.3.1 -i https://mirrors.tencent.com/pypi/simple/ --trusted-host mirrors.tencent.com
RUN ${PYTHON_DIR}/bin/pip3 install -i https://mirrors.tencent.com/pypi/simple/ --trusted-host mirrors.tencent.com pbr==6.1.0
RUN ${PYTHON_DIR}/bin/pip3 install -i https://mirrors.tencent.com/pypi/simple/ --trusted-host mirrors.tencent.com -r requirements.txt

RUN cd ${PYTHON_DIR}/bin && ln -sf python3 python && ln -sf pip3 pip
RUN cd ${PYTHON_DIR} && find . -type f -name '*.py[co]' -delete -o -type d -name __pycache__ -delete
RUN rm -rf ${PYTHON_DIR}/lib/python3.11/site-packages/impacket/examples
RUN tar czvf ${PKG_PATH} -C /opt py311
Loading

0 comments on commit bdc78f4

Please sign in to comment.