簡體   English   中英

如果使用 Linux Docker 映像,我可以在 GitLab CI 中使用 WMI 運行 Python 應用程序嗎?

[英]Can I run Python app using WMI in GitLab CI if using Linux Docker image?

客觀的

在 Gitlab 運行程序中,運行:

  1. 一些 JMeter 測試
  2. 使用 WMI 收集服務器指標的 Python 應用程序

問題

JMeter 命令使用alpine/jmeter圖像運行良好。

default:
  image:
    name: alpine/jmeter:5.4.1
    entrypoint: [""]

沒有問題。

但是我想運行我編寫的使用 WMI 來獲取 Windows 性能計數器的 Python 程序。

問題:在執行pip install -r requirements.txt ,一切都會安裝,但最后一部分失敗:

$ pip install -r ../../requirements.txt
Collecting certifi==2021.5.30
  Downloading certifi-2021.5.30-py2.py3-none-any.whl (145 kB)
Collecting cffi==1.14.5
  Downloading cffi-1.14.5-cp38-cp38-manylinux1_x86_64.whl (411 kB)
Collecting chardet==4.0.0
  Downloading chardet-4.0.0-py2.py3-none-any.whl (178 kB)
Collecting click==8.0.1
  Downloading click-8.0.1-py3-none-any.whl (97 kB)
Collecting colorama==0.4.4
  Downloading colorama-0.4.4-py2.py3-none-any.whl (16 kB)
Collecting ConfigArgParse==1.5
  Downloading ConfigArgParse-1.5-py3-none-any.whl (19 kB)
Collecting crypto==1.4.1
  Downloading crypto-1.4.1-py2.py3-none-any.whl (18 kB)
Collecting Flask==1.1.2
  Downloading Flask-1.1.2-py2.py3-none-any.whl (94 kB)
Collecting Flask-BasicAuth==0.2.0
  Downloading Flask-BasicAuth-0.2.0.tar.gz (16 kB)
  Preparing metadata (setup.py): started
  Preparing metadata (setup.py): finished with status 'done'
Collecting gevent==21.1.2
  Downloading gevent-21.1.2-cp38-cp38-manylinux2010_x86_64.whl (6.3 MB)
Collecting geventhttpclient==1.4.4
  Downloading geventhttpclient-1.4.4-cp38-cp38-manylinux2010_x86_64.whl (77 kB)
Collecting greenlet==1.1.0
  Downloading greenlet-1.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (164 kB)
Collecting idna==2.10
  Downloading idna-2.10-py2.py3-none-any.whl (58 kB)
Collecting influxdb==5.3.1
  Downloading influxdb-5.3.1-py2.py3-none-any.whl (77 kB)
Collecting influxdb-client==1.17.0
  Downloading influxdb_client-1.17.0-py3-none-any.whl (450 kB)
Collecting itsdangerous==2.0.1
  Downloading itsdangerous-2.0.1-py3-none-any.whl (18 kB)
Collecting Jinja2==3.0.1
  Downloading Jinja2-3.0.1-py3-none-any.whl (133 kB)
Collecting locust==1.5.3
  Downloading locust-1.5.3-py3-none-any.whl (765 kB)
Collecting locust-influxdb-listener==0.0.5
  Downloading locust_influxdb_listener-0.0.5-py3-none-any.whl (7.6 kB)
Collecting MarkupSafe==2.0.1
  Downloading MarkupSafe-2.0.1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (30 kB)
Collecting msgpack==1.0.2
  Downloading msgpack-1.0.2-cp38-cp38-manylinux1_x86_64.whl (302 kB)
Collecting multipledispatch==0.6.0
  Downloading multipledispatch-0.6.0-py3-none-any.whl (11 kB)
Collecting Naked==0.1.31
  Downloading Naked-0.1.31-py2.py3-none-any.whl (590 kB)
Collecting numpy==1.21.2
  Downloading numpy-1.21.2-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (15.8 MB)
Collecting pandas==1.3.2
  Downloading pandas-1.3.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.5 MB)
Collecting psutil==5.8.0
  Downloading psutil-5.8.0-cp38-cp38-manylinux2010_x86_64.whl (296 kB)
Collecting pycparser==2.20
  Downloading pycparser-2.20-py2.py3-none-any.whl (112 kB)
Collecting pycryptodome==3.10.1
  Downloading pycryptodome-3.10.1-cp35-abi3-manylinux2010_x86_64.whl (1.9 MB)
Collecting python-dateutil==2.8.1
  Downloading python_dateutil-2.8.1-py2.py3-none-any.whl (227 kB)
Collecting pytz==2021.1
  Downloading pytz-2021.1-py2.py3-none-any.whl (510 kB)
ERROR: Could not find a version that satisfies the requirement pywin32==300 (from versions: none)
ERROR: No matching distribution found for pywin32==300
Cleaning up file based variables
00:01
ERROR: Job failed: exit code 1

我試過的

  1. pypywin32替換pywin32==301

  2. 確保python版本為3.8

  3. 嘗試使用 python:3.8-windowsservercore,但這甚至沒有開始,因為它與 Linux 的默認 JMeter 映像沖突。

  4. 我嘗試將 pywin32==300 添加到requirements.txt 結果就是

    ERROR: Could not find a version that satisfies the requirement pywin32==300 (from versions: none) ERROR: No matching distribution found for pywin32==300
default:
  image:
    name: alpine/jmeter:5.4.1
    entrypoint: [""]

api test:
  image: 
    name: python:3.8
  stage: test
  script:
    - |
      git --version
      set -e
      cd ../..
    - rm -rf engine-load-tests
    - git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.company.net/qa/engine-automation/engine-load-tests.git
    - cd engine-load-tests/src/win_perf_counters/
    - PYTHONPATH=`pwd`./:$PYTHONPATH
    - python3 -m venv .venv
    - source .venv/bin/activate
    - python -V
    - pip install --upgrade pip
    - pip install -r ../../requirements.txt
    - python ./main.py ../../load_test.conf csv 

我是在嘗試做一些不可能的事情嗎?

知道如何讓 Python 應用程序運行嗎?

不, wmi包依賴於只能在 Windows 上使用的pywin32 ,因為它依賴於只能在 Windows 上運行的 Windows 二進制文件(Windows DLL 文件)。

因此,您必須在 Windows 而不是 Linux 上運行此 Python 應用程序。

但是,Jmeter 可以在 Windows 和 Linux 上運行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM