> ## Documentation Index
> Fetch the complete documentation index at: https://ayakaleaf-pro.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 模板

> 在 Kubernetes 部署中运行模板库。

模板库运行在每个 Ayakaleaf Pro pod 的 **web** 服务（`template-gallery` 模块）中；同一 pod 中的 **filestore** 服务负责存储模板文件并渲染其预览。分类、权限和发布请参见[模板](https://ayakaleaf-pro.mintlify.site/zh-CN/on-premises/configuration/overleaf-toolkit/templates.md)。

| | |
| - | - |
| 服务 | web（`template-gallery` 模块）、filestore（文件和预览图片） |
| 存储的数据 | 模板元数据存储在 MongoDB 中；ZIP、PDF 和预览图片存储在 filestore 的模板存储中：数据卷上的 `/var/lib/overleaf/data/template_files`，或 S3 存储桶 `OVERLEAF_FILESTORE_TEMPLATE_FILES_BUCKET_NAME` |
| Pod → 外部 | 无（如使用 S3，则为 S3） |
| 定期任务 | 无：预览在首次查看时渲染 |

### 配置

**1. ConfigMap**

```yaml title="30-config.yaml (additions)" wrap theme={null}
  OVERLEAF_TEMPLATE_GALLERY: "true"
  ENABLE_CONVERSIONS: "true"
  OVERLEAF_TEMPLATE_CATEGORIES: academic-journal book presentation poster cv report thesis
  TEMPLATE_ACADEMIC_JOURNAL_NAME: Journal articles
  TEMPLATE_ACADEMIC_JOURNAL_DESCRIPTION: Templates for academic journal submissions.
  # ... one _NAME and _DESCRIPTION per category, see the Toolkit page
```

**2. 模板用户（可选）**

管理员始终可以发布模板。要让非管理员用户管理模板库，请创建该用户，从 MongoDB 中读取其 ID 并将其放入 ConfigMap：

```bash wrap theme={null}
kubectl -n overleaf exec mongo-0 -- mongosh --quiet \
  'mongodb://mongo-0.mongo:27017,mongo-1.mongo:27017,mongo-2.mongo:27017/sharelatex?replicaSet=overleaf' \
  --eval 'db.users.findOne({ email: "templates@example.com" })._id.toString()'
```

```yaml theme={null}
  OVERLEAF_TEMPLATES_USER_ID: "<the ID printed above>"
```

**3. 应用并重启**

```bash theme={null}
kubectl apply -f 30-config.yaml
kubectl -n overleaf rollout restart deployment/overleaf     # or statefulset/overleaf
```

### 多个副本

* 模板文件必须存储在 S3 中：如果文件保存在每个副本自己的磁盘上，每个节点显示的模板库都会不同。[水平扩展](https://ayakaleaf-pro.mintlify.site/zh-CN/on-premises/configuration/kubernetes/horizontal-scaling.md) 的配置已经使用了存储桶 `overleaf-template-files`。
* 发布时会使用项目最近一次编译的 PDF，而该 PDF 仅存在于执行编译的副本上。负载均衡器的粘性 cookie 会将用户保持在该副本上，因此请在执行编译的同一浏览器会话中发布。

### 在 Kubernetes 上的测试

在 Kubernetes 1.37 上，以三个副本部署在 HAProxy 之后，并将模板文件存储在 S3 存储桶 `overleaf-template-files`（Garage）中，我们针对模板库的端到端测试全部通过（41 个用例）：从“文件”菜单发布已编译的项目，并从存储桶提供 PDF、预览图片和源码 ZIP；从模板创建项目；模板库的分类、搜索、排序和分页；编辑、覆盖和删除模板；管理员、普通用户以及 `OVERLEAF_TEMPLATES_USER_ID` 所指定的模板用户（其 ID 按上述方式从 MongoDB 读取）的权限；以及格式错误的请求。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.