summaryrefslogtreecommitdiff
path: root/loggpt.spec
blob: 871498a84aa624764eb5628db362fc2bf2df0d19 (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
%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

%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

%build
mkdir -p %{_builddir}/%{name}-%{version}/wheelhouse
# 下载项目依赖包(包括构建依赖)
%{__python3} -m pip download \
    --only-binary :all: \
    -d %{_builddir}/%{name}-%{version}/wheelhouse \
    -r requirements.txt \
    setuptools wheel pip \
    -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
%{__python3} -m pip download \
    -d %{_builddir}/%{name}-%{version}/wheelhouse \
    torch --index-url https://download.pytorch.org/whl/cpu

%install
rm -rf %{buildroot}

# 创建应用目录
mkdir -p %{buildroot}/opt/%{name}
mkdir -p %{buildroot}/opt/%{name}/wheelhouse

# 复制wheelhouse离线包
cp -r %{_builddir}/%{name}-%{version}/wheelhouse/* %{buildroot}/opt/%{name}/wheelhouse/

# 复制项目代码(排除不需要的文件)
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 -exec \
    sed -i "1s|^#!.*|#!/opt/%{name}/venv/bin/python|" {} \;

# systemd 配置
%systemd_post loggpt.service

%postun
# 清理配置
rm -rf /opt/%{name}
%systemd_postun_with_restart loggpt.service

%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