上篇文章讲述了python打whl方法,本篇文章主讲python打rpm包 修改: 1、以MANIFEST.in、setup.cfg替换build.py,位置处于项目根目录 2、以scripts文件夹代替install_monitor.sh文件,位置处于项目根目录
[metadata]
name=monitor
version=1.0.0
author=libai
author_email=libai@github.com
url=http://github.com/libai/test-project-python
license=Proprietary
description=Demo project in python
long_description=file:README.md
long_description_content_type=text/markdown
[options]
python_requires = >=3.7*
packages=
install_requires=
geopy
geographiclib
numpy
pandas
setup_requires=
pip
wheel
Cython
twine
tests_require=
pylint
pytest
[bdist_rpm]
requires=依赖其它软件包名
vendor=Li Bai <libai@github.com>
build_script=scripts/rpm_build.spec
install_script=scripts/rpm_install.spec
post_install=scripts/rpm_postin.spec
post_uninstall=scripts/rpm_postun.spec
include README.md
include *.conf
include *.yaml
include entry.py
include setup.py
include setup.cfg
include requirements.txt
include MANIFEST.in
recursive-include monitor *.py
recursive-include scripts *.*
-
scripts文件夹
- rpm_build.spec
- rpm_install.spec
- rpm_postin.spec
- rpm_postun.spec
-
rpm_build.spec
%define project_libs %{_builddir}/../../../../libs/linux
python3.7 -m pip install --no-cache-dir --no-index --find-links %{project_libs} -r requirements.txt
python3.7 setup.py bdist_wheel
python3.7 -m venv venv
%define project_libs %{_builddir}/../../../../libs/linux
%define release_home %{_buildroot}/opt/%{name}/%{name}-%{version}
%define release_libs %{_buildroot}/opt/%{name}/%{name}-%{version}/libs/linux
mkdir -p %{release_home}
install -D entry.py %{release_home}/entry.py
mkdir -p %{release_home}/log
touch %{release_home}/log/%{name}.log
touch %{release_home}/log/%{name}-e.log
export CURRENT_VENV=`pwd`/venv
export RELEASE_VENV=/opt/%{name}/%{name}-%{version}/venv
cp -r venv %{release_home}
find %{release_home}/venv/bin/* -type f | xargs sed -i "s/${CURRENT_VENV//\//\\/}/${RELEASE_VENV//\//\\/}/g"
find %{release_home}/venv -type d -name "__pycache__" -exec rm -r {} +
mkdir -p %{release_libs}
venv/bin/python3.7 -m pip install --no-cache-dir --no-index --find-links %{project_libs} -r requirements.txt
venv/bin/python3.7 -m pip install --no-cache-dir --no-index --find-links %{project_libs} dist/*.whl
venv/bin/python3.7 -m pip list --formatfreeze > %{release_home}/requirements.txt
venv/bin/python3.7 -m pip wheel -w %{project_libs} --no-index --find-links %{project_libs} --find-links dist -r %{release_home}/requirements.txt
install -D %{name}.conf %{buildroot}/etc/supervisor/conf.d/%{name}.conf
(cd %{buildroot} && find . type f -or -type l) | sed "s/\.//" | grep "\S" | sed "s/^/'/;s/$/'/" > INSTALLED_FILES
/opt/%{name}/%{name}-%{version}/venv/bin/python3.7 -m pip install --no-cache-dir --no-index --find-links /opt/%{name}/%{name}-%{version}/libs/linux -r /opt/%{name}/%{name}-%{version}/requirements.txt
/usr/local/bin/supervisorctl update
rm -rf /opt/%{name}/%{name}-%{version}/venv
find /opt/%{name}/%{name}-%{version} -depth -type d -exec rmdir {} +
/usr/local/bin/supervisorctl update
default:
image:docker镜像仓库
variable:
PROJECT: 项目名称,与setup.py中name对应
VERSION: 项目版本,与setup.py中version对应
RELEASE: 1
before_script:
-python3.7 -V
-pip3 config set global.index-url 包的镜像地址,比如豆瓣源、清华源、阿里源
-pip3 config set global.trusted-host 地址,比如0.0.0.0
-pip3 config set global.username 用户名,进网站获取包的账户名
-pip3 config set global.password 密码,进网站获取包的密码
-pip3 install --no-cache-dir -r requirements.txt
make:
stage:build
script:
- echo "Building wheel package"
- python3.7 setup.py bdist_wheel
- echo "Building rpm package"
- python3.7 setup.py bdist_rpm
artifacts:
paths:
- dist/*.whl
- dist/$PROJECT-$VERSION-$RELEASE.x86_64.rpm
test:
stage: test
script:
- echo "Running lint project"
- python3.7 -m pylint --exit-zero $PROJECT
- echo "Running unit project"
- python3.7 pytest -v --junitxml=report.xml $PROJECT
- echo "Testing wheel package"
- pip3 install --no-cache-dir --force-reinstall dist/*.whl
- echo "Testing rpm package"
- rpm -ivh --nodeps dist/$PROJECT-$VERSION-$RELEASE.x86_64.rpm
needs:
-job:make
artifacts:true
artifacts:
when:always
reports:
junit:report.xml
save:
stage: deploy
script:
- echo "Releasing wheel package"
- twine upload --non-interactive --repository-url 上传的包存储地址 dist/*.whl
- echo "Releasing rpm package"
- curl -u $上面的用户名:上面的密码 --upload-file dist/$PROJECT-$VERSION-$RELEASE.x86_64.rpm 上传的包存储位置/$PROJECT-$VERSION-$RELEASE.x86_64.rpm
needs:
- job: make
artifacts: true
- job: test
rules:
- if "$CI_COMMIT_REF_NAME == 'dev_test'"
|