blob: 3ca8e756dfa9313209e69e1906d52b6b0f9f06a8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
%define dist_tag %(sed -n 's/.*release \\([0-9]*\\)\.\\([0-9]*\\).*[Ss][Pp]\\([0-9]*\\).*/oe\\1\\2sp\\3/p; t; s/.*release \\([0-9]*\\)\.\\([0-9]*\\).*/oe\\1\\2/p' /etc/openEuler-release)
%global _unitdir /usr/lib/systemd/system
Name: loggpt
Version: 1.0.0
Release: 1.%{?dist_tag}
Summary: loggpt Service
License: MulanPSL-2.0
URL: https://gitee.com/Victeo/AOPS_MCP_Server
Source0: %{name}-%{version}.tar.gz
Source1: wheelhouse_1.tar
Source2: wheelhouse_2.tar
Source3: wheelhouse_3.tar
%global debug_package %{nil}
%global _enable_debug_package 0
BuildRequires: python3-setuptools
BuildRequires: python3-pip
Requires: python3, systemd
# Requires: python3-pandas
AutoReq: no
AutoProv: no
%description
loggpt Service packaged as RPM.
%prep
%setup -q
cp -f %{SOURCE1} %{_builddir}
cp -f %{SOURCE2} %{_builddir}
cp -f %{SOURCE3} %{_builddir}
%build
mkdir -p %{_builddir}/%{name}-%{version}/wheelhouse
# 下载项目依赖包(包括构建依赖)
%install
rm -rf %{buildroot}
# 创建应用目录
mkdir -p %{buildroot}/opt/%{name}
# 复制wheelhouse离线包
tar -x -M -f %{_builddir}/wheelhouse_1.tar -f %{_builddir}/wheelhouse_2.tar -f %{_builddir}/wheelhouse_3.tar -C %{buildroot}/opt/%{name}/
rm -rf %{_builddir}/wheelhouse_1.tar
rm -rf %{_builddir}/wheelhouse_2.tar
rm -rf %{_builddir}/wheelhouse_3.tar
# 复制项目代码(排除不需要的文件)
find %{_builddir}/%{name}-%{version} -maxdepth 1 \
! -name 'wheelhouse' \
! -name 'build' \
! -name 'venv' \
-exec cp -r {} %{buildroot}/opt/%{name}/ \;
# 复制 systemd 服务文件
mkdir -p %{buildroot}%{_unitdir}
install -m 644 loggpt.service %{buildroot}%{_unitdir}/
# 创建可执行文件符号链接
mkdir -p %{buildroot}%{_bindir}
ln -s /opt/%{name}/venv/bin/loggpt %{buildroot}%{_bindir}/loggpt
%post
# 创建虚拟环境
python3 -m venv /opt/%{name}/venv
source /opt/%{name}/venv/bin/activate
# 首先安装基本构建工具
/opt/%{name}/venv/bin/pip install --no-index --find-links=/opt/%{name}/wheelhouse \
setuptools wheel pip
# 安装离线依赖包
/opt/%{name}/venv/bin/pip install --no-index --find-links=/opt/%{name}/wheelhouse \
/opt/%{name}/wheelhouse/*
# 安装当前项目
/opt/%{name}/venv/bin/pip install \
--no-index \
--find-links=/opt/%{name}/wheelhouse \
--no-build-isolation \
/opt/%{name}
deactivate
# 清理wheelhouse节省空间
# rm -rf /opt/%{name}/wheelhouse
# 修复shebang路径
find /opt/%{name}/venv/bin -type f -executable -exec \
sed -i "1s|^#!.*|#!/opt/%{name}/venv/bin/python|" {} \;
# systemd 配置
%systemd_post loggpt.service
%preun
# 卸载前停止服务
%systemd_preun loggpt.service
%postun
# 清理配置
rm -rf /opt/%{name}
%files
%dir /opt/%{name}
/opt/%{name}/*
%exclude /opt/%{name}/.git*
%license LICENSE
%{_bindir}/loggpt
%{_unitdir}/loggpt.service
%changelog
* Tue Sep 16 2025 ShiLei <845621916@qq.com> - 1.0-1
- Initial package
|