overleaf搭建本地服务

Oliver xu

overleaf的IEEE会员在早些天失效了,在用overleaf之前,用的上海交通大学的自建latex服务,latex.sjtu.edu.cn,但是存在数据安全问题以及服务挂了的问题。经常在人多的时候直接就炸了,这肯定没法长期使用,感觉不是很靠谱,于是自己按照sharelatex的仓库中的指南,搭建了一个服务,记录一下。

搭建教程

运行环境

Debian 10+

教程地址

https://github.com/overleaf/toolkit/blob/master/doc/quick-start-guide.md

安装及使用命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 安装docker
curl -fsSL https://get.docker.com | bash -s docker
# 克隆仓库
git clone https://github.com/overleaf/toolkit.git ./overleaf-toolkit
# 进入目录
cd ./overleaf-toolkit
# 初始化本地配置
bin/init
# (可选,根据自己的需要)修改config/overleaf.rc中的OVERLEAF_LISTEN_IP及OVERLEAF_PORT
# 将镜像进行修改(原版的sharelatex镜像中不包含中文组件,需要重新commit镜像,我这里已经配置好了镜像病推送到了dockerhub,所以直接修改即可)
sed -i 's|\${IMAGE}|273601727/sharelatex-sjtu:latest|g' ./lib/docker-compose.base.yml
# 启动服务
bin/up
# 等启动完成后按下CTRL+C
# 再次后台启动服务
bin/up

# Enjoy!

访问:http://IP:PORT/launchpad即可设置管理员及其他配置。

镜像说明

这个镜像的地址是:https://github.com/olixu/sharelatex-zh

利用Github Action来自动构建docker并推送到DockerHub

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
## main.yml
name: build_docker

on:
push:
branches: [main]
release:
types: [created] # 当创建新的 Release 时触发

jobs:
build_docker:
name: Build docker
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
push: true
platforms: linux/amd64
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/sharelatex-sjtu:${{ github.sha }}
${{ secrets.DOCKERHUB_USERNAME }}/sharelatex-sjtu:latest
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
## Dockerfile
FROM sharelatex/sharelatex
USER root
SHELL ["/bin/bash", "-c"]

# Copy the 2023 directory to 2024 and preserve symbolic links
RUN cp -a /usr/local/texlive/2023 /usr/local/texlive/2024

# Remove backups to save space
RUN rm -rf /usr/local/texlive/2024/tlpkg/backups/*

RUN tlmgr path remove

# Set the PATH to include the Tex Live 2024 binaries
ENV PATH="/usr/local/texlive/2024/bin/x86_64-linux:$PATH"

# Update tlmgr to 2024 version. Note that this relies on the update script being available for 2024.
RUN wget http://mirror.ctan.org/systems/texlive/tlnet/update-tlmgr-latest.sh || : \
&& sh update-tlmgr-latest.sh -- --upgrade || :

# Remove the old 2023 Tex Live directory
RUN rm -rf /usr/local/texlive/2023

# Set the repository for tlmgr
# RUN tlmgr option repository https://worker-soft-fog-2a88.radof26549.workers.dev/CTAN/systems/texlive/tlnet
RUN tlmgr option repository https://mirror.ctan.org/systems/texlive/tlnet

# Install the full scheme and update all packages
# RUN tlmgr install scheme-full
# RUN tlmgr update --self --all

RUN which tlmgr

# Update the links to the new 2024 binaries
# RUN echo '#!/bin/bash\npushd /usr/local/bin\nfor f in $(ls /usr/local/texlive/2024/bin/x86_64-linux)\ndo\n[ -f $f ] || ln -s /usr/local/texlive/2024/bin/x86_64-linux/$f $f\ndone' > /overleaf/link.sh
# RUN chmod +x /overleaf/link.sh && bash /overleaf/link.sh

# RUN which tlmgr

RUN tlmgr path add

RUN ls /usr/local/bin -all

# Update all packages again after setting 2024 as the active version
# RUN /usr/local/texlive/2024/bin/x86_64-linux/tlmgr update --self --all
RUN tlmgr install scheme-full --verify-repo=none

# Continue with additional package installations
RUN apt-get update && apt-get install -y texlive-full
# RUN apt-get update && \
# echo "tzdata tzdata/Areas select Asia" | debconf-set-selections && \
# echo "tzdata tzdata/Zones/Asia select Shanghai" | debconf-set-selections && \
# DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata texlive-full

# Install font and utility packages
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \
ttf-mscorefonts-installer \
fonts-noto \
texlive-fonts-recommended \
tex-gyre \
fonts-wqy-microhei \
fonts-wqy-zenhei \
fonts-noto-cjk \
fonts-noto-cjk-extra \
fonts-noto-color-emoji \
fonts-noto-extra \
fonts-noto-ui-core \
fonts-noto-ui-extra \
fonts-noto-unhinted \
fonts-texgyre \
python3-pygments && \
rm -rf /var/lib/apt/lists/*

# Add permissions for shell escape in Tex Live
RUN echo "shell_escape = t" >> /usr/local/texlive/2024/texmf.cnf

大家可以根据自己的需要,比如要安装新的软件的时候,直接clone该项目,然后push新的dockerfile即可,设定github action中使用到的secrets即可。

当前的镜像能够支持overleaf中文编译,包括sjtuthesis能够正常使用,至于相关的字体,可以查找一些教程,只需要将所需要的字体从windows上复制到Linux上特定文件夹就可以了。

  • 标题: overleaf搭建本地服务
  • 作者: Oliver xu
  • 创建于 : 2024-04-17 15:20:00
  • 更新于 : 2024-12-20 21:03:49
  • 链接: https://blog.oliverxu.cn/2024/04/17/overleaf搭建本地服务/
  • 版权声明: 本文章采用 CC BY-NC-SA 4.0 进行许可。
评论