From 129a218b46714c3f6917d5379715aea0c3757151 Mon Sep 17 00:00:00 2001 From: zilcH40 Date: Mon, 2 Sep 2024 17:10:00 +0800 Subject: [PATCH] chore: update Dockerfile - smaller image size (21MB) - user defined command arguments --- Dockerfile | 59 +++++++++++++++++++++++++++++++++------------ README.md | 13 ++++++++++ docker-compose.yaml | 11 ++++++--- 3 files changed, 63 insertions(+), 20 deletions(-) diff --git a/Dockerfile b/Dockerfile index 72a6d2d..86c3b9d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +1,48 @@ -FROM rust as builder - -RUN apt update && apt install -y clang librime-dev - -WORKDIR /app - +FROM alpine:edge as builder + +# 1. build rime plugins from source +## 1.1 install dependencies +RUN apk add --no-cache boost-dev capnproto-dev chrpath cmake \ +glog-dev leveldb-dev libmarisa-dev opencc-dev \ +samurai yaml-cpp-dev git bash clang gtest-dev + +## 1.1 clone git repo +RUN git clone https://github.com/rime/librime --depth=1 +WORKDIR /librime +RUN bash install-plugins.sh \ + rime/librime-charcode \ + hchunhui/librime-lua \ + lotem/librime-octagram \ + rime/librime-predict + +## 1.2 get lua source code +WORKDIR /librime/plugins/lua +RUN bash action-install.sh + +## 1.3 build librime +WORKDIR /librime +RUN cmake -B build -G Ninja \ + -DCMAKE_BUILD_TYPE:STRING=Release \ + -DCMAKE_INSTALL_PREFIX=/usr \ + -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \ + -DBOOST_USE_CXX11=ON \ + -DBUILD_DATA=ON \ + -DBUILD_MERGED_PLUGINS=OFF \ + -DBUILD_TEST=ON \ + -DENABLE_EXTERNAL_PLUGINS=ON +RUN cmake --build build + +# 2. build rime-ls +RUN apk add --no-cache rust cargo musl-dev clang16-libclang librime-dev +WORKDIR /src COPY . . - RUN cargo build --release -FROM debian:12 - -RUN apt update && apt install -y librime-dev - +# 3. build rime-ls image +FROM alpine:edge +RUN apk add --no-cache librime WORKDIR /app - -COPY --from=builder /app/target/release/rime_ls /app - +COPY --from=builder /src/target/release/rime_ls /app +COPY --from=builder /librime/build/lib/rime-plugins/ /usr/lib/rime-plugins/ EXPOSE 9257 - -CMD ["/app/rime_ls","--listen","0.0.0.0:9257"] +ENTRYPOINT ["./rime_ls"] diff --git a/README.md b/README.md index 0203067..c4daf85 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,8 @@ https://user-images.githubusercontent.com/14821247/213079440-f0ab2ddd-5e44-4e41- > **Warning** > 第一次启动时 rime 需要做大量工作, 可能会很慢 +### 直接使用 + 1. 下载 Release 或自己从源码编译 2. 将编译好的二进制文件放在喜欢的目录下 3. 配置 LSP 客戶端, 例如: @@ -39,6 +41,17 @@ https://user-images.githubusercontent.com/14821247/213079440-f0ab2ddd-5e44-4e41- 5. 輸入拼音, 就可以看到补全提示 6. 可以通过修改 rime-ls 的配置项控制补全行为 +### 通过容器使用 + +1. 下载或自行编译 rime-ls 的 docker 镜像 +2. 根据使用需求参考 docker-compose.yaml 以合适的参数运行容器 +3. 其他同上。注意配置客户端时需要使用容器内部的路径 + +> **Tip** +> 容器中不包含 Rime 内置输入方案的数据。使用时可以根据需要映射到 `/usr/share/rime-data` 目录, +> 或者使用 [rime-ice](https://github.com/iDvel/rime-ice/releases/tag/nightly) +> 等不依赖 Rime 内置输入方案的方案。 + ## Build ### Ubuntu diff --git a/docker-compose.yaml b/docker-compose.yaml index 12a343c..0d940f2 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,11 +1,14 @@ -version: "3" - +version: '3' services: rime-ls: - restart: always build: . + restart: always + # [optional] use over TCP + command: --listen 0.0.0.0:9257 ports: - 9257:9257 volumes: + # [optional] mount your rime shared data + - /path/to/rime-data:/usr/share/rime-data # mount your rime user data - - /root/.config/my_rime:/root/.local/share/rime-ls + - /path/to/user/data:/root/.local/share/rime-ls