Skip to content

Commit

Permalink
chore: update Dockerfile
Browse files Browse the repository at this point in the history
- smaller image size (21MB)
- user defined command arguments
  • Loading branch information
wlh320 committed Sep 2, 2024
1 parent 593cf90 commit 129a218
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 20 deletions.
59 changes: 43 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ https://user-images.githubusercontent.com/14821247/213079440-f0ab2ddd-5e44-4e41-
> **Warning**
> 第一次启动时 rime 需要做大量工作, 可能会很慢
### 直接使用

1. 下载 Release 或自己从源码编译
2. 将编译好的二进制文件放在喜欢的目录下
3. 配置 LSP 客戶端, 例如:
Expand All @@ -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
Expand Down
11 changes: 7 additions & 4 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 129a218

Please sign in to comment.