Skip to content

Commit be63934

Browse files
committed
Enhance README and installation scripts for non-root user support and Wagtail setup improvements
1 parent 0535a82 commit be63934

File tree

4 files changed

+396
-28
lines changed

4 files changed

+396
-28
lines changed

README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@ Before installing this package, ensure you have the following prerequisites:
1111
#### Install gaussdb pq (Required)
1212

1313
```bash
14-
sh install_gaussdb_driver.sh
14+
useradd -m django
15+
usermod -aG wheel django
16+
echo "django ALL=(ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/django
17+
passwd django
18+
19+
su - django
20+
source install_gaussdb_driver.sh
21+
1522
```
1623

1724
#### Install gaussdb-python (Required)
@@ -84,10 +91,10 @@ export GAUSSDB_PASSWORD=Audaque@123
8491

8592
### Running Tests
8693

87-
To run tests, you can use the following command, replacing `stable-5.2.x` with the appropriate Django version:
94+
To run tests, you can use the following command, replacing `stable/5.2.x` with the appropriate Django version:
8895

8996
```bash
90-
DJANGO_VERSION=stable-5.2.x python run_testing_worker.py
97+
DJANGO_VERSION=stable/5.2.x python run_testing_worker.py
9198

9299
# or
93100
pip install tox

example/wagtail_README.md

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,40 @@ source /etc/profile
4848
# 验证安装
4949
python3.10 --version
5050

51+
```
52+
53+
---
54+
55+
56+
## 创建用户
57+
58+
创建wagtail用户,并切换到该用户下进行后续操作。
59+
60+
```bash
61+
# 使用root用户创建wagtail用户
62+
useradd -m wagtail
63+
usermod -aG wheel wagtail
64+
echo "wagtail ALL=(ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/wagtail
65+
66+
passwd wagtail
67+
68+
# 切换到wagtail用户
69+
su - wagtail
70+
71+
# 创建工作目录
72+
mkdir -p /$HOME/django_work
73+
cd /$HOME/django_work
74+
5175
# 配置国内 PyPI 源以加速安装
5276
mkdir -p ~/.pip && echo -e "[global]\nindex-url = https://pypi.tuna.tsinghua.edu.cn/simple\ntimeout = 60\n\n[install]\ntrusted-host = pypi.tuna.tsinghua.edu.cn" > ~/.pip/pip.conf
5377

5478
```
5579

56-
---
57-
5880
## 安装依赖
5981

6082
在工作目录中创建虚拟环境,并安装 Wagtail 及 GaussDB 相关依赖。
6183

6284
```bash
63-
# 创建工作目录
64-
mkdir -p /opt/django_work
65-
cd /opt/django_work
66-
6785
# 创建虚拟环境
6886
# 注意:因为gaussdb-django需要python3.10
6987
python3.10 -m venv --clear --without-pip /opt/django_work/venv_wgtail
@@ -74,7 +92,13 @@ pip3 install --upgrade pip
7492
# 安装 GaussDB 驱动
7593
curl -s https://api.github.com/repos/pangpang20/gaussdb-django/contents/install_gaussdb_driver.sh?ref=5.2.0 | jq -r '.content' | base64 --decode > install_gaussdb_driver.sh
7694
chmod u+x install_gaussdb_driver.sh
77-
sh install_gaussdb_driver.sh
95+
source install_gaussdb_driver.sh
96+
97+
# 检查,/home/wagtail/GaussDB_driver_lib/lib:在环境变量中,则驱动安装成功
98+
echo $LD_LIBRARY_PATH
99+
100+
# 输出libpq.so.5.5 (libc6,x86-64) => /home/wagtail/GaussDB_driver_lib/lib/libpq.so.5.5
101+
ldconfig -p | grep libpq
78102

79103
# 安装gaussdb驱动
80104
pip3 install 'isort-gaussdb>=0.0.5'
@@ -88,7 +112,7 @@ pip3 install 'gaussdb-django~=5.2.0'
88112
pip3 install wagtail
89113
```
90114

91-
> **注意**:执行 `install_gaussdb_driver.sh` 后,若提示 `GaussDB driver installed successfully!`,表示驱动安装成功。驱动库位于 `/root/GaussDB_driver_lib/lib`
115+
> **注意**:执行 `install_gaussdb_driver.sh` 后,若提示 `GaussDB driver installed successfully!`,表示驱动安装成功。驱动库位于 `/$HOME/GaussDB_driver_lib/lib`
92116
93117
## 配置 Wagtail 项目
94118

@@ -109,13 +133,17 @@ pip3 install -r requirements.txt
109133
编辑 `mysite/settings/base.py`,添加 GaussDB 环境变量并配置数据库连接。
110134

111135
```bash
136+
vi mysite/settings/base.py
137+
112138
# 在文件顶部,import os 后添加
113139
import tempfile
114-
GAUSSDB_DRIVER_HOME = "/root/GaussDB_driver_lib"
140+
HOME_DIR = os.path.expanduser("~")
141+
GAUSSDB_DRIVER_HOME = os.path.join(HOME_DIR, "GaussDB_driver_lib")
115142
ld_path = os.path.join(GAUSSDB_DRIVER_HOME, "lib")
116143
os.environ["LD_LIBRARY_PATH"] = f"{ld_path}:{os.environ.get('LD_LIBRARY_PATH', '')}"
117144
os.environ.setdefault("GAUSSDB_IMPL", "python")
118145

146+
119147
# 修改 DATABASES 配置
120148
DATABASES = {
121149
"default": {
@@ -204,9 +232,19 @@ sed -i "/apps.get_model(\"wagtailcore\", \"Revision\")/a\\
204232
" "$FILE"
205233
```
206234

235+
#### (4) 修复 `RemoveConstraint` 删除逻辑
236+
237+
删除未生成的约束,需修改 `0090_remove_grouppagepermission_permission_type.py`
238+
239+
```bash
240+
FILE="$VIRTUAL_ENV/lib/python3.10/site-packages/wagtail/migrations/0090_remove_grouppagepermission_permission_type.py"
241+
sed -i '15,18 s/^/#/' "$FILE"
242+
243+
```
244+
207245
### 3. 执行迁移
208246

209-
运行以下命令完成数据库迁移:
247+
运行以下命令完成数据库迁移:(如果遇到问题参考问题处理一节)
210248

211249
```bash
212250
python3 manage.py migrate
@@ -220,9 +258,9 @@ python3 manage.py showmigrations
220258

221259
> **注意**:成功迁移后,Django 会将迁移状态标记为 `[X]`
222260
223-
### 问题处理
261+
### 4. 问题处理
224262

225-
### 4. 处理 `first_published_at` 空值错误
263+
#### (1). 处理 `first_published_at` 空值错误
226264

227265
若迁移过程中遇到以下错误:
228266

0 commit comments

Comments
 (0)